Skip to content

Commit 8de47f9

Browse files
Copilotj4587698Tony-ST0754peereflitsCopilot
authored
doc(AttributeTable): auto generate AttributeTable content (#7529)
* Initial plan * Add reflection-based attribute retrieval for Circles component Co-authored-by: ArgoZhang <22001478+ArgoZhang@users.noreply.github.com> * Fix security issues in ComponentAttributeCacheService Co-authored-by: ArgoZhang <22001478+ArgoZhang@users.noreply.github.com> * Fix IndexOf edge case in GetFriendlyTypeName Co-authored-by: ArgoZhang <22001478+ArgoZhang@users.noreply.github.com> * refactor: 重构代码 * doc: 重构示例 * refactor: 移除冗余配置 * chore: 增加 xml 拷贝指令 * chore: 调整 Target 顺序 * chore: 增加版本信息 * refactor: 移除默认值列 * refactor: 增加 xmlDoc 复用提高性能 * refactor: 兼容老代码 * refactor: 移除 ValueList 列 * refactor: 增加说明文档 * refactor: 更改数据类型为 List * refactor: 精简代码 * chore: 临时脚本 * refactor: 重构逻辑 * refactor: 调整脚本 * refactor: 更新脚本 * chore: 撤销更改 --------- Co-Authored-By: j4587698 <24642446+j4587698@users.noreply.github.com> Co-Authored-By: Tony-ST0754 <244411587+tony-st0754@users.noreply.github.com> Co-authored-by: Marcel Peereboom <40403094+peereflits@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: ArgoZhang <22001478+ArgoZhang@users.noreply.github.com> Co-authored-by: Argo Zhang <argo@live.ca>
1 parent 91466d0 commit 8de47f9

7 files changed

Lines changed: 267 additions & 87 deletions

File tree

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
<div class="table-attr">
1+
<div class="table-attr">
22
<h4>@Title</h4>
33

4-
<Table TItem="AttributeItem" Items="Items">
4+
<Table TItem="AttributeItem" Items="Items" ShowFooter="@ShowFooter">
55
<TableColumns>
66
<TableColumn @bind-Field="@context.Name" />
77
<TableColumn @bind-Field="@context.Description" TextWrap="true" />
88
<TableColumn @bind-Field="@context.Type" />
9-
<TableColumn @bind-Field="@context.ValueList" TextWrap="true" />
10-
<TableColumn @bind-Field="@context.DefaultValue" />
9+
<TableColumn @bind-Field="@context.Version" />
1110
</TableColumns>
11+
<TableFooter>
12+
<TableFooterCell Text="合计:" colspan="3" Align="Alignment.Left" />
13+
<TableFooterCell Aggregate="AggregateType.Count" Field="@nameof(AttributeItem.Name)" />
14+
</TableFooter>
1215
</Table>
1316
</div>
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55

66
namespace BootstrapBlazor.Server.Components.Components;
77

88
/// <summary>
9-
///
9+
/// 组件参数表格组件
1010
/// </summary>
1111
public sealed partial class AttributeTable
1212
{
@@ -15,24 +15,42 @@ public sealed partial class AttributeTable
1515
private IStringLocalizer<AttributeTable>? Localizer { get; set; }
1616

1717
/// <summary>
18-
///
18+
/// 获得/设置 表格标题
1919
/// </summary>
2020
[Parameter]
2121
[NotNull]
2222
public string? Title { get; set; }
2323

2424
/// <summary>
25-
///
25+
/// 获得/设置 表格数据
2626
/// </summary>
27-
[Parameter] public IEnumerable<AttributeItem>? Items { get; set; }
27+
[Parameter]
28+
public IEnumerable<AttributeItem> Items { get; set; } = [];
29+
30+
/// <summary>
31+
/// 获得/设置 表格关联组件类型
32+
/// </summary>
33+
[Parameter]
34+
public Type? Type { get; set; }
2835

2936
/// <summary>
30-
/// OnInitialized 方法
37+
/// 是否显示合计信息 默认 false
38+
/// </summary>
39+
[Parameter]
40+
public bool ShowFooter { get; set; }
41+
42+
/// <summary>
43+
/// <inheritdoc/>
3144
/// </summary>
3245
protected override void OnInitialized()
3346
{
3447
base.OnInitialized();
3548

3649
Title ??= Localizer[nameof(Title)];
50+
51+
if (Type != null)
52+
{
53+
Items = ComponentAttributeCacheService.GetAttributes(Type);
54+
}
3755
}
3856
}

src/BootstrapBlazor.Server/Components/Samples/Circles.razor

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212

1313
<DemoBlock Title="@Localizer["BasicUsageTitle"]" Introduction="@Localizer["BasicUsageIntro"]" Name="Normal">
1414
<Circle Value="@_circleValue" />
15-
<section ignore class="btn-group mt-3 d-block">
16-
<button class="btn btn-primary" @onclick="e => Add(10)">
17-
<i class="fa-solid fa-plus"></i>
18-
<span>@Localizer["IncreaseSpan"] 10</span>
19-
</button>
20-
<button class="btn btn-info" @onclick="e => Add(-10)">
21-
<i class="fa-solid fa-minus"></i>
22-
<span>@Localizer["DecreaseSpan"] 10</span>
23-
</button>
15+
<section ignore class="mt-3">
16+
<div class="btn-group">
17+
<button class="btn btn-primary" @onclick="e => Add(10)">
18+
<i class="fa-solid fa-plus"></i>
19+
<span>@Localizer["IncreaseSpan"] 10</span>
20+
</button>
21+
<button class="btn btn-info" @onclick="e => Add(-10)">
22+
<i class="fa-solid fa-minus"></i>
23+
<span>@Localizer["DecreaseSpan"] 10</span>
24+
</button>
25+
</div>
2426
</section>
2527
</DemoBlock>
2628

@@ -53,4 +55,4 @@
5355
</Circle>
5456
</DemoBlock>
5557

56-
<AttributeTable Items="@GetAttributes()" />
58+
<AttributeTable Type="@typeof(Circle)" />
Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -17,61 +17,5 @@ private void Add(int interval)
1717
_circleValue += interval;
1818
_circleValue = Math.Min(100, Math.Max(0, _circleValue));
1919
}
20-
21-
/// <summary>
22-
/// GetAttributes
23-
/// </summary>
24-
/// <returns></returns>
25-
private AttributeItem[] GetAttributes() =>
26-
[
27-
new()
28-
{
29-
Name = "Width",
30-
Description = Localizer["Width"],
31-
Type = "int",
32-
ValueList = "",
33-
DefaultValue = "120"
34-
},
35-
new()
36-
{
37-
Name = "StrokeWidth",
38-
Description = Localizer["StrokeWidth"],
39-
Type = "int",
40-
ValueList = "",
41-
DefaultValue = "2"
42-
},
43-
new()
44-
{
45-
Name = "Value",
46-
Description = Localizer["Value"],
47-
Type = "int",
48-
ValueList = "0-100",
49-
DefaultValue = "0"
50-
},
51-
new()
52-
{
53-
Name = "Color",
54-
Description = Localizer["Color"],
55-
Type = "Color",
56-
ValueList = "Primary / Secondary / Success / Danger / Warning / Info / Dark",
57-
DefaultValue = "Primary"
58-
},
59-
new()
60-
{
61-
Name = "ShowProgress",
62-
Description = Localizer["ShowProgress"],
63-
Type = "bool",
64-
ValueList = "true / false",
65-
DefaultValue = "true"
66-
},
67-
new()
68-
{
69-
Name = "ChildContent",
70-
Description = Localizer["ChildContent"],
71-
Type = "RenderFragment",
72-
ValueList = "",
73-
DefaultValue = ""
74-
}
75-
];
7620
}
7721

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55

6-
using System.ComponentModel;
7-
86
namespace BootstrapBlazor.Server.Data;
97

108
/// <summary>
@@ -15,30 +13,30 @@ public class AttributeItem
1513
/// <summary>
1614
/// 获得/设置 参数
1715
/// </summary>
18-
[DisplayName("参数")]
1916
public string Name { get; set; } = "";
2017

2118
/// <summary>
2219
/// 获得/设置 说明
2320
/// </summary>
24-
[DisplayName("说明")]
2521
public string Description { get; set; } = "";
2622

2723
/// <summary>
2824
/// 获得/设置 类型
2925
/// </summary>
30-
[DisplayName("类型")]
3126
public string Type { get; set; } = "";
3227

3328
/// <summary>
3429
/// 获得/设置 可选值
3530
/// </summary>
36-
[DisplayName("可选值")]
3731
public string ValueList { get; set; } = "";
3832

3933
/// <summary>
40-
/// 获得/设置 默认值
34+
/// 获得/设置 版本
35+
/// </summary>
36+
public string Version { get; set; } = "";
37+
38+
/// <summary>
39+
///
4140
/// </summary>
42-
[DisplayName("默认值")]
4341
public string DefaultValue { get; set; } = "";
4442
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
<Project>
22

3-
<Target Name="LLMs" AfterTargets="Publish" Condition="'$(TargetFramework)' == '$(RunTargetFramework)'">
3+
<Target Name="LLMs" AfterTargets="Publish">
44
<Message Text="LLMs documentation generating ..." Importance="high"></Message>
55
<Exec Command="dotnet tool restore"></Exec>
66
<Exec Command="dotnet llms-docs --root=$(MSBuildThisFileDirectory) --output=$(PublishDir)"></Exec>
77
</Target>
88

9+
<Target Name="CopyXmlDocs" AfterTargets="LLMs">
10+
<ItemGroup>
11+
<XmlDocsToCopy Include="%(Reference.RelativeDir)BootstrapBlazor*.xml" />
12+
</ItemGroup>
13+
<Message Text="Copying XML docs to output path: $(PublishDir)" Importance="High" />
14+
<Copy SourceFiles="@(XmlDocsToCopy)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')" />
15+
</Target>
16+
917
</Project>

0 commit comments

Comments
 (0)