Skip to content

Commit

Permalink
Feature/apiview improvements (#958)
Browse files Browse the repository at this point in the history
* Changes to show documentation and deprecated methods
  • Loading branch information
praveenkuttappan authored Sep 8, 2020
1 parent b7ced0a commit 6a313e2
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 18 deletions.
12 changes: 11 additions & 1 deletion src/dotnet/APIView/APIView/CodeFileHtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected CodeFileHtmlRenderer(bool readOnly)
public static CodeFileHtmlRenderer Normal { get; } = new CodeFileHtmlRenderer(false);
public static CodeFileHtmlRenderer ReadOnly { get; } = new CodeFileHtmlRenderer(true);

protected override void RenderToken(CodeFileToken token, StringBuilder stringBuilder)
protected override void RenderToken(CodeFileToken token, StringBuilder stringBuilder, bool isDeprecatedToken, bool isDocumentation)
{
if (token.Value == null)
{
Expand Down Expand Up @@ -47,6 +47,16 @@ protected override void RenderToken(CodeFileToken token, StringBuilder stringBui
break;
}

if (isDeprecatedToken)
{
elementClass += " deprecated";
}

if (isDocumentation)
{
elementClass += " documentation";
}

string href = null;

if (token.DefinitionId != null && !_readOnly)
Expand Down
48 changes: 34 additions & 14 deletions src/dotnet/APIView/APIView/CodeFileRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,47 @@ private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node)
{
var stringBuilder = new StringBuilder();
string currentId = null;
bool isDocumentation = false;
bool isDeprecatedToken = false;

foreach (var token in node)
{
if (token.Kind == CodeFileTokenKind.Newline)
{
list.Add(new CodeLine(stringBuilder.ToString(), currentId));
currentId = null;
stringBuilder.Clear();
}
else
switch(token.Kind)
{
if (token.DefinitionId != null)
{
currentId = token.DefinitionId;
}
case CodeFileTokenKind.Newline:
list.Add(new CodeLine(stringBuilder.ToString(), currentId));
currentId = null;
stringBuilder.Clear();
break;

case CodeFileTokenKind.DocumentRangeStart:
isDocumentation = true;
break;

case CodeFileTokenKind.DocumentRangeEnd:
isDocumentation = false;
break;

case CodeFileTokenKind.DeprecatedRangeStart:
isDeprecatedToken = true;
break;

case CodeFileTokenKind.DeprecatedRangeEnd:
isDeprecatedToken = false;
break;

RenderToken(token, stringBuilder);
}
default:
if (token.DefinitionId != null)
{
currentId = token.DefinitionId;
}
RenderToken(token, stringBuilder, isDeprecatedToken, isDocumentation);
break;
}
}
}

protected virtual void RenderToken(CodeFileToken token, StringBuilder stringBuilder)
protected virtual void RenderToken(CodeFileToken token, StringBuilder stringBuilder, bool isDeprecatedToken, bool isDocumentation)
{
if (token.Value != null)
{
Expand Down
1 change: 0 additions & 1 deletion src/dotnet/APIView/APIView/CodeLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public readonly struct CodeLine
{
public string DisplayString { get; }
public string ElementId { get; }

public CodeLine(string html, string id)
{
this.DisplayString = html;
Expand Down
6 changes: 5 additions & 1 deletion src/dotnet/APIView/APIView/Model/CodeFileTokenKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public enum CodeFileTokenKind
MemberName = 7,
StringLiteral = 8,
Literal = 9,
Comment = 10
Comment = 10,
DocumentRangeStart = 11,
DocumentRangeEnd = 12,
DeprecatedRangeStart = 13,
DeprecatedRangeEnd = 14
}
}
1 change: 0 additions & 1 deletion src/dotnet/APIView/APIViewWeb/APIViewWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@
<ProjectReference Include="..\APIView\APIView.csproj" />
</ItemGroup>


</Project>
8 changes: 8 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Client/css/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,12 @@ code-inner {
}
.code-removed {
background-color: #ffeef0;
}

.deprecated {
text-decoration: line-through;
}

.documentation {
display: none;
}
36 changes: 36 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Client/src/documentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$(() => {
const SEL_DOC_CLASS = ".documentation";
const SHOW_DOC_CHECKBOX = "#show-documentation-checkbox";
const SHOW_DOC_CHECK_COMPONENT = "#show-documentation-component";
const SEL_CODE_INNER_CLASS = ".code-inner";
const SEL_CODE_LINE = ".code-line";

hideCheckboxIfNoDocs();
toggleEmptyLineVisibility(false);

$(document).on("click", SHOW_DOC_CHECKBOX, e => {
toggleAllDocumentationVisibility(e.target.checked);
});

function hideCheckboxIfNoDocs() {
if ($(SEL_DOC_CLASS).length == 0) {
$(SHOW_DOC_CHECK_COMPONENT).hide();
}
}

function toggleEmptyLineVisibility(showDocuments: boolean) {
//If code line only has documentation then toggle that line
$(SEL_CODE_LINE).each(function () {
var tokenElements = $(this).find(SEL_CODE_INNER_CLASS).children();
//Checking atleast one doc node is present to avoid hiding explicit empty lines
if (tokenElements.filter(SEL_DOC_CLASS).length > 0 && tokenElements.not(SEL_DOC_CLASS).length == 0) {
$(this).toggle(showDocuments);
}
});
}

function toggleAllDocumentationVisibility(showDocuments: boolean) {
$(SEL_DOC_CLASS).toggle(showDocuments);
toggleEmptyLineVisibility(showDocuments);
}
});
1 change: 1 addition & 0 deletions src/dotnet/APIView/APIViewWeb/Client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import "./comments.ts";
import "./revisions.ts";
import "./file-input.ts";
import "./navbar.ts";
import "./documentation.ts";
6 changes: 6 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
Show comments
</label>
</span>
<span class="dropdown-item checkbox" id="show-documentation-component">
<label>
<input type="checkbox" id="show-documentation-checkbox">
Show documentation
</label>
</span>
</div>
</div>
</div>
Expand Down

0 comments on commit 6a313e2

Please sign in to comment.