Skip to content

Commit

Permalink
feat(TagHelper): add BootstrapBlazor.TagHelper package (#3278)
Browse files Browse the repository at this point in the history
* doc: 增加压缩

* refactor: 代码格式化

* refactor: 更改变量名

* refactor: 优化代码

* chore: 移除版本信息

* refactor: 增加压缩配置

* refactor: 使用原生标签

* refactor: 移除缓存配置

* chore: 移除工具链

* chore: 移除代码内置依赖服务

* doc: 移除 xml 注释

* refactor: 更新缓存策略

* doc: 格式化文档

* Revert "refactor: 使用原生标签"

This reverts commit 00da935.

* doc: 增加字典

* doc: 移除 jQuery 显示引用

* Revert "doc: 移除 jQuery 显示引用"

This reverts commit f81512f.

* feat: 增加文件哈希值逻辑

* chore: 更新路由

* doc: 更新注释

* feat: 增加 HashFile 方法

* doc: 格式化文档

* revert: 移除方法

* refactor: 更改属性标签顺序

* refactor: 使用原生标签

* chore: 更新自动化脚本

* revert: 撤销 WebRootPath 参数

* feat: 增加 TagHelper 工程

* doc: 格式化文档

* test: 更新单元测试
  • Loading branch information
ArgoZhang authored Apr 13, 2024
1 parent 576e4d2 commit 998a878
Show file tree
Hide file tree
Showing 105 changed files with 316 additions and 343 deletions.
7 changes: 7 additions & 0 deletions BootstrapBlazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapBlazor.Maui", "src
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "maui", "maui", "{81615751-490B-4B50-8029-C79846F592BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazor.TagHelper", "src\Extensions\Components\BootstrapBlazor.TagHelper\BootstrapBlazor.TagHelper.csproj", "{65CEB170-D561-4878-80E4-625538590D29}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -292,6 +294,10 @@ Global
{B94D32F4-2E7C-400B-BC34-D6BA31A234CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B94D32F4-2E7C-400B-BC34-D6BA31A234CB}.Release|Any CPU.Build.0 = Release|Any CPU
{B94D32F4-2E7C-400B-BC34-D6BA31A234CB}.Release|Any CPU.Deploy.0 = Release|Any CPU
{65CEB170-D561-4878-80E4-625538590D29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65CEB170-D561-4878-80E4-625538590D29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65CEB170-D561-4878-80E4-625538590D29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65CEB170-D561-4878-80E4-625538590D29}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -343,6 +349,7 @@ Global
{AB19F805-A27F-455F-8E36-8F1ADE295868} = {7C1D79F1-87BC-42C1-BD5A-CDE4044AC1BD}
{B94D32F4-2E7C-400B-BC34-D6BA31A234CB} = {81615751-490B-4B50-8029-C79846F592BB}
{81615751-490B-4B50-8029-C79846F592BB} = {A2182155-43ED-44C1-BF6F-1B70EBD2DFFE}
{65CEB170-D561-4878-80E4-625538590D29} = {CD062AB6-244D-402A-8F33-C37DAC5856CC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0DCB0756-34FA-4FD0-AE1D-D3F08B5B3A6B}
Expand Down
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)src\keys\Longbow.Utility.snk</AssemblyOriginatorKeyFile>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>

<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions exclusion.dic
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ Cascader
Cascaders
maui
gantt
jquery
26 changes: 13 additions & 13 deletions src/BootstrapBlazor.Server/Components/App.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject IHostEnvironment Env
@inject IWebHostEnvironment Env
@inject IStringLocalizer<App> Localizer

<!DOCTYPE html>
Expand All @@ -12,19 +12,19 @@
<meta name="keywords" content="bootstrap,blazor,wasm,webassembly,UI,netcore,web,assembly">
<meta name="description" content="基于 Bootstrap 风格的 Blazor UI 组件库,用于研发企业级中后台产品。">
<meta name="author" content="argo (argo@live.ca)">
<base href="/" />
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" href="favicon.png">
<base href="/" />
<Link Href="_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css" />
<Link Href="_content/BootstrapBlazor.MaterialDesign/css/md.min.css" />
<Link Href="_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css" />
<Link Href="_content/BootstrapBlazor/css/motronic.min.css" />
<Link Href="BootstrapBlazor.Server.styles.css" />
<Link Href="css/site.css" />
<title>@Localizer["Title"]</title>
<link rel="stylesheet" href="_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css" />
<link rel="stylesheet" href="_content/BootstrapBlazor.MaterialDesign/css/md.min.css" />
<link rel="stylesheet" href="_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css" />
<link rel="stylesheet" href="_content/BootstrapBlazor/css/motronic.min.css" />
<link rel="stylesheet" href="BootstrapBlazor.Server.styles.css" />
<link rel="stylesheet" href="css/site.css" />
<script src="lib/theme.js" type="module"></script>
<HeadOutlet @rendermode="new InteractiveServerRenderMode(false)" />
<Script Src="lib/theme.js" type="module"></Script>
<title>@Localizer["Title"]</title>
</head>

<body>
Expand All @@ -36,14 +36,14 @@

<BlazorReconnector @rendermode="new InteractiveServerRenderMode(false)" />

<Script Src="_content/BootstrapBlazor.SummerNote/js/jquery-3.5.1.min.js"></Script>
<script src="_content/BootstrapBlazor.SummerNote/js/jquery-3.5.1.min.js"></script>
@if (Env.IsDevelopment())
{
<Script Src="_content/BootstrapBlazor/js/bootstrap.blazor.bundle.js"></Script>
<script src="_content/BootstrapBlazor/js/bootstrap.blazor.bundle.js"></script>
}
@if (Env.IsProduction())
{
<Script Src="_content/BootstrapBlazor/js/bootstrap.blazor.bundle.min.js"></Script>
<script src="_content/BootstrapBlazor/js/bootstrap.blazor.bundle.min.js"></script>
}
<script src="_framework/blazor.web.js"></script>
@if (Env.IsProduction())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPreferredTheme, setTheme } from "../../_content/BootstrapBlazor/modules/theme.js?v=$version"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js?v=$version"
import { getPreferredTheme, setTheme } from "../../_content/BootstrapBlazor/modules/theme.js"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"

export function init() {
const scrollTop = () => (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor.Server/Components/Components/Pre.razor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { copy, getDescribedElement, addLink, addScript, getHeight } from "../../_content/BootstrapBlazor/modules/utility.js?v=$version"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js?v=$version"
import { copy, getDescribedElement, addLink, addScript, getHeight } from "../../_content/BootstrapBlazor/modules/utility.js"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"

export async function init(id, title) {
const el = document.getElementById(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { insertAfter } from "../../_content/BootstrapBlazor/modules/utility.js?v=$version"
import Data from "../../_content/BootstrapBlazor/modules/data.js?v=$version"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js?v=$version"
import { insertAfter } from "../../_content/BootstrapBlazor/modules/utility.js"
import Data from "../../_content/BootstrapBlazor/modules/data.js"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"

export function init(id) {
const el = document.getElementById(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Data from "../../_content/BootstrapBlazor/modules/data.js?v=$version"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js?v=$version"
import Data from "../../_content/BootstrapBlazor/modules/data.js"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"

export function init(id, version) {
const el = document.getElementById(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ public partial class ComponentLayout : IAsyncDisposable
/// </summary>
private JSModule? Module { get; set; }

/// <summary>
/// 获得 IVersionService 服务实例
/// </summary>
[Inject]
[NotNull]
private IVersionService? JSVersionService { get; set; }

[Inject]
[NotNull]
private IOptions<IconThemeOptions>? IconThemeOptions { get; set; }
Expand Down Expand Up @@ -109,7 +102,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
Module = await JSRuntime.LoadModule("./Components/Layout/ComponentLayout.razor.js", JSVersionService.GetVersion());
Module = await JSRuntime.LoadModule("./Components/Layout/ComponentLayout.razor.js");
}
if (Module != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ public partial class DockLayout : IAsyncDisposable
[NotNull]
private IJSRuntime? JSRuntime { get; set; }

/// <summary>
/// 获得 IVersionService 服务实例
/// </summary>
[Inject]
[NotNull]
private IVersionService? JSVersionService { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand All @@ -39,7 +32,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
Module = await JSRuntime.LoadModule("./Components/Layout/DockLayout.razor.js", JSVersionService.GetVersion());
Module = await JSRuntime.LoadModule("./Components/Layout/DockLayout.razor.js");
await Module.InvokeVoidAsync("init");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/BootstrapBlazor.Server/Components/Layout/NavMenu.razor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Data from "../../_content/BootstrapBlazor/modules/data.js?v=$version"
import Drag from "../../_content/BootstrapBlazor/modules/drag.js?v=$version"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js?v=$version"
import Data from "../../_content/BootstrapBlazor/modules/data.js"
import Drag from "../../_content/BootstrapBlazor/modules/drag.js"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"

export function init(id) {
const navmenu = {
Expand Down
6 changes: 1 addition & 5 deletions src/BootstrapBlazor.Server/Components/Pages/Chats.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public partial class Chats
[NotNull]
private IBrowserFingerService? BrowserFingerService { get; set; }

[Inject]
[NotNull]
private IVersionService? VersionService { get; set; }

private string? Context { get; set; }

private List<AzureOpenAIChatMessage> Messages { get; } = [];
Expand Down Expand Up @@ -129,7 +125,7 @@ private async Task GetCompletionsAsync()
private async Task<string> GetFingerCodeAsync()
{
var code = await BrowserFingerService.GetFingerCodeAsync();
code ??= $"BootstrapBlazor{VersionService.GetVersion()}";
code ??= "BootstrapBlazor";
return code;
}

Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Components/Pages/Chats.razor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js?v=$version"
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"

export function init(id) {
const el = document.getElementById(id)
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Components/Pages/Index.razor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Data from '../../_content/BootstrapBlazor/modules/data.js?v=$version'
import Data from '../../_content/BootstrapBlazor/modules/data.js'

export function init(id, text1, text2, text3) {
const el = document.getElementById(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Data from '../../../_content/BootstrapBlazor/modules/data.js?v=$version'
import EventHandler from "../../../_content/BootstrapBlazor/modules/event-handler.js?v=$version"
import { isMobile } from "../../../_content/BootstrapBlazor/modules/utility.js?v=$version"
import Data from '../../../_content/BootstrapBlazor/modules/data.js'
import EventHandler from "../../../_content/BootstrapBlazor/modules/event-handler.js"
import { isMobile } from "../../../_content/BootstrapBlazor/modules/utility.js"

/**
* 缓存绘图步骤
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>

<Import Project="..\Version.targets" />
<Import Project="..\Version.targets" Condition="'$(TargetFramework)' == 'net1.0'" />

<Target Name="PostPublish" AfterTargets="Publish" Condition="'$(Configuration)' == 'Release'">
<Exec Command="git reset --hard"></Exec>
Expand Down
3 changes: 2 additions & 1 deletion src/BootstrapBlazor.Server/Extensions/ServicesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public static IServiceCollection AddBootstrapBlazorServices(this IServiceCollect
// 增加多语言支持配置信息
services.AddRequestLocalization<IOptionsMonitor<BootstrapBlazorOptions>>((localizerOption, blazorOption) =>
{
blazorOption.OnChange(op => Invoke(op));
blazorOption.OnChange(Invoke);
Invoke(blazorOption.CurrentValue);
return;
void Invoke(BootstrapBlazorOptions option)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
// Website: https://www.blazor.zone or https://argozhang.github.io/

using Microsoft.AspNetCore.StaticFiles;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Net.Http.Headers;

namespace BootstrapBlazor.Server.Extensions;

/// <summary>
///
/// </summary>
internal static class CacheExtensions
internal static class StaticFileResponseContextExtensions
{
public static void ProcessCache(this StaticFileResponseContext context, IConfiguration configuration)
{
Expand All @@ -26,39 +22,28 @@ private static bool CanCache(this StaticFileResponseContext context, IConfigurat
var ret = false;
age = 0;

var files = configuration.GetFiles();
if (files.Any(i => context.CanCache(i)))
var fileTypes = configuration.GetFileTypes();
if (fileTypes.Any(context.CanCache))
{
ret = true;
age = configuration.GetAge();
}
return ret;
}

private static bool CanCache(this StaticFileResponseContext context, string file)
private static bool CanCache(this StaticFileResponseContext context, string fileType)
{
var ext = Path.GetExtension(context.File.PhysicalPath) ?? "";
bool ret = file.Equals(ext, StringComparison.OrdinalIgnoreCase);
if (ret && ext.Equals(".js", StringComparison.OrdinalIgnoreCase))
{
// process javascript file
ret = false;
if (context.Context.Request.QueryString.HasValue)
{
var paras = QueryHelpers.ParseQuery(context.Context.Request.QueryString.Value);
ret = paras.ContainsKey("v");
}
}
return ret;
return fileType.Equals(ext, StringComparison.OrdinalIgnoreCase);
}

private static List<string>? _files;
private static List<string> GetFiles(this IConfiguration configuration)
private static List<string>? _fileTypes;
private static List<string> GetFileTypes(this IConfiguration configuration)
{
_files ??= GetFiles();
return _files;
_fileTypes ??= GetFilesFromConfiguration();
return _fileTypes;

List<string> GetFiles()
List<string> GetFilesFromConfiguration()
{
var cacheSection = configuration.GetSection("Cache-Control");
return cacheSection.GetSection("Files").Get<List<string>>() ?? [];
Expand All @@ -68,13 +53,13 @@ List<string> GetFiles()
private static int? _age;
private static int GetAge(this IConfiguration configuration)
{
_age ??= GetAge();
_age ??= GetAgeFromConfiguration();
return _age.Value;

int GetAge()
int GetAgeFromConfiguration()
{
var cacheSection = configuration.GetSection("Cache-Control");
return cacheSection.GetValue<int>("Max-Age", 1000 * 60 * 10);
return cacheSection.GetValue("Max-Age", 1000 * 60 * 10);
}
}
}
28 changes: 20 additions & 8 deletions src/BootstrapBlazor.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@

builder.Services.AddLogging(logBuilder => logBuilder.AddFileLogger());
builder.Services.AddCors();
builder.Services.AddResponseCompression();

#if DEBUG
#else
builder.Services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
});
#endif

builder.Services.AddControllers();
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
Expand All @@ -48,22 +55,27 @@
{
app.UseExceptionHandler("/Error");
app.UseResponseCompression();
app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => ctx.ProcessCache(app.Configuration) });
}
app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => ctx.ProcessCache(app.Configuration) });

var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".properties"] = "application/octet-stream";
provider.Mappings[".moc"] = "application/x-msdownload";
provider.Mappings[".moc3"] = "application/x-msdownload";
provider.Mappings[".mtn"] = "application/x-msdownload";
var provider = new FileExtensionContentTypeProvider
{
Mappings =
{
[".properties"] = "application/octet-stream",
[".moc"] = "application/x-msdownload",
[".moc3"] = "application/x-msdownload",
[".mtn"] = "application/x-msdownload"
}
};

app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider });
app.UseStaticFiles();

var cors = app.Configuration["AllowOrigins"]?.Split(',', StringSplitOptions.RemoveEmptyEntries);
if (cors?.Length > 0)
{
app.UseCors(builder => builder.WithOrigins()
app.UseCors(options => options.WithOrigins()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials());
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ code {
top: .65rem;
right: 1.5rem;
font-size: 65%;
transition: opacity .3s linear;
transition: opacity .3s linear;
}

.btn-code:not(:hover) {
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/wwwroot/lib/theme.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { getPreferredTheme, setTheme } from "../../_content/BootstrapBlazor/modules/theme.js?v=$version"
import { getPreferredTheme, setTheme } from "../../_content/BootstrapBlazor/modules/theme.js"

setTheme(getPreferredTheme())
Loading

0 comments on commit 998a878

Please sign in to comment.