Skip to content

Commit

Permalink
docs: API generator could resolve obsolete parameter and render to AP…
Browse files Browse the repository at this point in the history
…I table (#1493)

* 📝 docs(api): Support for Obsolete attribute

* 📝 docs: use no transition click  example and api

* 📝 docs: TOC i18n error
  • Loading branch information
capdiem authored Aug 18, 2023
1 parent bb90b54 commit fdff0e6
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 32 deletions.
22 changes: 12 additions & 10 deletions docs/Masa.Blazor.Docs/Components/Api/ApiDatatable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<AppSheet Class="mb-9">
<MSimpleTable Class="api-table">
<thead>
<tr>
@foreach (var header in Headers)
{
<th style="@GetHeaderStyle(header)">
<div class="subtitle">@I18n.T(header)</div>
</th>
}
</tr>
<tr>
@foreach (var header in Headers)
{
<th style="@GetHeaderStyle(header)">
<div class="subtitle">@I18n.T(header)</div>
</th>
}
</tr>
</thead>
<tbody>
@foreach (var item in Items)
Expand All @@ -24,7 +24,9 @@
@if (header == "name")
{
<span class="subtitle">
<MBadge Value="@(item.Required)" Color="transparent" Class="text-mono" OffsetY="10">
<MBadge Value="@(item.Required)" Color="transparent"
Class="@(item.IsObsolete ? "text-mono text-decoration-line-through" : "text-mono")"
OffsetY="10">
<BadgeContent>
<MIcon Size="9" Color="red lighten-2">mdi-asterisk</MIcon>
</BadgeContent>
Expand Down Expand Up @@ -125,7 +127,7 @@
"name" => "width:144px",
"type" => "width:264px;",
_ => ""
};
};
}

}
20 changes: 10 additions & 10 deletions docs/Masa.Blazor.Docs/Pages/Components.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@
}
else
{
<FadeTransition LeaveAbsolute>
<ShowTransitionElement Tag="div" Value="@IsApiTab">
<Apis @bind-Value="@CurrentApi"
Data="@_apiData"
GithubUri="@ApiGithubUri">
</Apis>
</ShowTransitionElement>
<ShowTransitionElement Tag="div" Value="@(!IsApiTab)">
<MTabsItems Value="IsApiTab.ToString()">
<MTabItem Value="@("False")" Transition="" Eager>
<DocumentMarkdownIt Source="@_md"
OnTocParsed="@OnTocParsed"
OnFrontMatterParsed="@OnFrontMatterParsed" />
Expand All @@ -49,8 +43,14 @@
{
<BackMatter Related="@_frontMatterMeta.Related"></BackMatter>
}
</ShowTransitionElement>
</FadeTransition>
</MTabItem>
<MTabItem Value="@("True")" Transition="">
<Apis @bind-Value="@CurrentApi"
Data="@_apiData"
GithubUri="@ApiGithubUri">
</Apis>
</MTabItem>
</MTabsItems>
}

<Contribute GithubUri="@(IsApiTab ? ApiGithubUri : ComponentGithubUri)" />
Expand Down
5 changes: 3 additions & 2 deletions docs/Masa.Docs.Core/Components/OutlineCard.razor.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.m-outline-card {
position: relative;
padding: 16px;
border-radius: 4px;
margin-top: 12px;
padding: 16px;
position: relative;
}

.m-outline-card__title {
Expand Down
2 changes: 1 addition & 1 deletion docs/Masa.Docs.Shared/Shared/Toc.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<ChildContent>
@if (_toc.Any())
{
<div class="toc-content mb-2 ml-6">@I18n.T("Contents")</div>
<div class="toc-content mb-2 ml-6">@I18n.T("Toc")</div>
}
<ul class="mb-6">
@foreach (var item in _toc)
Expand Down
1 change: 0 additions & 1 deletion docs/Masa.Docs.Shared/wwwroot/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ a.text-dec-none {
}

.overview .project-content__title {
margin-bottom: 8px;
font-weight: 700;
line-height: 24px;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/Masa.Docs.Shared/wwwroot/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"InvertExampleColors": "Invert example colors",
"ViewOnGithub": "View on github",
"ViewSource": "View source",
"Contents": "Contents",
"Toc": "Contents",
"SeniorSponsor": "Senior sponsor",
"ComponentPages": "Component Pages",
"NextPage": "Next Page",
Expand Down
2 changes: 1 addition & 1 deletion docs/Masa.Docs.Shared/wwwroot/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"InvertExampleColors": "反转示例颜色",
"ViewOnGithub": "在 Github 上查看",
"ViewSource": "查看源代码",
"Contents": "目录",
"Toc": "目录",
"SeniorSponsor": "高级赞助商",
"Sponsor": "赞助商",
"Required": "必填",
Expand Down
6 changes: 5 additions & 1 deletion src/Masa.Blazor.Docs.ApiGenerator/ApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class ParameterInfo
public string? Description {{ get; set; }}
public bool Required {{ get; set; }}
public bool IsObsolete {{ get; set; }}
}}
}}");

Expand Down Expand Up @@ -202,7 +204,9 @@ private static void AnalyzeParameters(INamedTypeSymbol classSymbol, List<Paramet
}
}

var parameterInfo = new ParameterInfo(parameterSymbol.Name, typeText, typeDesc, defaultValue);
var isObsolete = attrs.FirstOrDefault(attr => attr.AttributeClass?.Name == "ObsoleteAttribute") is not null;

var parameterInfo = new ParameterInfo(parameterSymbol.Name, typeText, typeDesc, defaultValue, isObsolete);

if (type.Name.StartsWith("RenderFragment"))
{
Expand Down
3 changes: 2 additions & 1 deletion src/Masa.Blazor.Docs.ApiGenerator/GenComponentMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static partial class ApiGenerator
Type = ""{item.Type}"",
TypeDesc = @""{item.TypeDesc}"",
DefaultValue = ""{item.DefaultValue}"",
Required = {item.Required.ToString().ToLower()}
Required = {item.Required.ToString().ToLower()},
IsObsolete = {item.IsObsolete.ToString().ToLower()},
}});");
}

Expand Down
11 changes: 7 additions & 4 deletions src/Masa.Blazor.Docs.ApiGenerator/ParameterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

internal class ParameterInfo
{
public ParameterInfo(string name, string type, string? typeDesc = null, string? defaultValue = null)
public ParameterInfo(string name, string type, string? typeDesc = null, string? defaultValue = null, bool isObsolete = false)
{
Name = name;
Type = type;
TypeDesc = typeDesc;
DefaultValue = defaultValue;
IsObsolete = isObsolete;
}

public string Name { get; set; } = null!;

public string Type { get; set; } = null!;

public string? TypeDesc { get; set; }

public string? DefaultValue { get; set; }

public string? Description { get; set; }

public bool Required { get; set; }
}

public bool IsObsolete { get; set; }
}

0 comments on commit fdff0e6

Please sign in to comment.