Skip to content

Commit 8248ee3

Browse files
authored
feat: Add Razor support as an optional extension to TemplateEngine.Core (#12)
* Add Razor support as an optional extension to TemplateEngine.Core - Introduced MbSoftLab.TemplateEngine.Core.Razor project with RazorTemplateEngine implementation. - Updated project references in existing projects to include the new Razor extension. - Removed Razor dependencies from core classes and adjusted documentation to reflect optional usage. - Enhanced README and other documentation files to guide users on installing and using the Razor extension. * Disable package cache and specify solution file for restore, build, and test steps in CI workflows
1 parent a33163c commit 8248ee3

File tree

17 files changed

+172
-33
lines changed

17 files changed

+172
-33
lines changed

.github/workflows/BuildFromDevelop.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ jobs:
2020
uses: actions/setup-dotnet@v4
2121
with:
2222
dotnet-version: 8.0.x
23-
cache: true
23+
# Disable package cache to avoid lock file requirement
24+
cache: false
2425
- name: Restore
25-
run: dotnet restore
26+
run: dotnet restore MbSoftLab.TemplateEngine.Core.sln
2627
- name: Build
27-
run: dotnet build --configuration Release --no-restore
28+
run: dotnet build MbSoftLab.TemplateEngine.Core.sln --configuration Release --no-restore
2829
- name: Test
29-
run: dotnet test --no-restore --verbosity normal
30+
run: dotnet test MbSoftLab.TemplateEngine.Core.sln --no-restore --verbosity normal

.github/workflows/BuildFromMaster.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
uses: actions/setup-dotnet@v4
2121
with:
2222
dotnet-version: 8.0.x
23-
cache: true
23+
cache: false
2424
- name: Restore
25-
run: dotnet restore
25+
run: dotnet restore MbSoftLab.TemplateEngine.Core.sln
2626
- name: Build
27-
run: dotnet build --configuration Release --no-restore
27+
run: dotnet build MbSoftLab.TemplateEngine.Core.sln --configuration Release --no-restore
2828
- name: Test
29-
run: dotnet test --no-restore --verbosity normal
29+
run: dotnet test MbSoftLab.TemplateEngine.Core.sln --no-restore --verbosity normal

.github/workflows/Release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
uses: actions/setup-dotnet@v4
1515
with:
1616
dotnet-version: 8.0.x
17-
cache: true
17+
cache: false
1818
- name: Restore
19-
run: dotnet restore
19+
run: dotnet restore MbSoftLab.TemplateEngine.Core.sln
2020
- name: Build
21-
run: dotnet build --configuration Release --no-restore
21+
run: dotnet build MbSoftLab.TemplateEngine.Core.sln --configuration Release --no-restore
2222
- name: Pack
2323
run: dotnet pack MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj --configuration Release --no-restore -o ./artifacts
2424
- name: Push to NuGet

MbSoftLab.TemplateEngine.Core.Razor/Documentation.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<AssemblyVersion>1.1.0.0</AssemblyVersion>
6+
<FileVersion>1.1.0.0</FileVersion>
7+
<Version>1.1.0</Version>
8+
<PackageVersion>1.1.0-preview</PackageVersion>
9+
<Description>Razor-enabled extension for MbSoftLab.TemplateEngine.Core providing RazorTemplateEngine.</Description>
10+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
11+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
12+
<PackageTags>Template Engine Razor RazorEngineCore Html</PackageTags>
13+
<PackageId>MbSoftLab.TemplateEngine.Core.Razor</PackageId>
14+
<Company>MbSoftLab</Company>
15+
<Authors>MbSoftLab</Authors>
16+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
17+
<Copyright>© 2021 - 2025 MbSoftLab</Copyright>
18+
<PackageIcon>MbSoftLabLogo.png</PackageIcon>
19+
<PackageProjectUrl>https://github.com/mbsoftlab/MbSoftLab.TemplateEngine.Core</PackageProjectUrl>
20+
<RepositoryUrl>https://github.com/mbsoftlab/MbSoftLab.TemplateEngine.Core</RepositoryUrl>
21+
<RepositoryType>Git</RepositoryType>
22+
<DocumentationFile>Documentation.xml</DocumentationFile>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<PackageReference Include="RazorEngineCore" Version="2020.10.1" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="../MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj" />
31+
<None Include="../MbSoftLab.TemplateEngine.Core/MbSoftLabLogo.png">
32+
<Pack>True</Pack>
33+
<PackagePath></PackagePath>
34+
</None>
35+
</ItemGroup>
36+
37+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# MbSoftLab.TemplateEngine.Core.Razor
2+
3+
Optionales Erweiterungspaket für MbSoftLab.TemplateEngine.Core, das die `RazorTemplateEngine<T>` bereitstellt.
4+
5+
## Installation
6+
7+
```bash
8+
# .NET CLI
9+
dotnet add package MbSoftLab.TemplateEngine.Core.Razor
10+
11+
# Oder Projekt-Referenz (Monorepo)
12+
dotnet add <IhrProjekt>.csproj reference MbSoftLab.TemplateEngine.Core.Razor/MbSoftLab.TemplateEngine.Core.Razor.csproj
13+
```
14+
15+
## Verwendung
16+
17+
```csharp
18+
using MbSoftLab.TemplateEngine.Core;
19+
20+
public class Person : TemplateDataModel<Person>
21+
{
22+
public string FirstName { get; set; }
23+
}
24+
25+
var person = new Person { FirstName = "Anna" };
26+
27+
var engine = new RazorTemplateEngine<Person>();
28+
engine.TemplateString = "<h1>@Model.FirstName</h1>";
29+
string html = engine.CreateStringFromTemplate(person);
30+
```
31+
32+
Hinweis: `TemplateDataModel<T>` ist nun eine einfache Klasse im Core (ohne Razor-Basis). Die Razor-Engine erhält intern `Model` als Datenmodell (`template.Run(TemplateDataModel?.Model)`).

MbSoftLab.TemplateEngine.Core/RazorTemplateEngine.cs renamed to MbSoftLab.TemplateEngine.Core.Razor/RazorTemplateEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using RazorEngineCore;
1+
using RazorEngineCore;
22
using System;
33
using System.ComponentModel;
44
using System.Globalization;
@@ -86,4 +86,4 @@ public string CreateStringFromTemplate(T templateDataModel, string csHtmlTemplat
8686
TemplateString = csHtmlTemplate;
8787
return CreateStringFromTemplate();
8888
}
89-
}
89+
}

MbSoftLab.TemplateEngine.Core.Tests/MbSoftLab.TemplateEngine.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<ItemGroup>
1616
<ProjectReference Include="..\MbSoftLab.TemplateEngine.Core\MbSoftLab.TemplateEngine.Core.csproj" />
17+
<ProjectReference Include="..\MbSoftLab.TemplateEngine.Core.Razor\MbSoftLab.TemplateEngine.Core.Razor.csproj" />
1718
</ItemGroup>
1819

1920
<ItemGroup>

MbSoftLab.TemplateEngine.Core.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MbSoftLab.TemplateEngine.Co
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MbSoftLab.TemplateEngine.Core", "MbSoftLab.TemplateEngine.Core\MbSoftLab.TemplateEngine.Core.csproj", "{CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}"
99
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MbSoftLab.TemplateEngine.Core.Razor", "MbSoftLab.TemplateEngine.Core.Razor\MbSoftLab.TemplateEngine.Core.Razor.csproj", "{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}"
11+
EndProject
1012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MbSoftlab.TemplateEngine.Core.Demo", "MbSoftlab.TemplateEngine.Core.Demo\MbSoftlab.TemplateEngine.Core.Demo.csproj", "{159ED0CF-FB05-4F88-A442-90890814E6A8}"
1113
EndProject
1214
Global
@@ -63,6 +65,26 @@ Global
6365
{CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}.Release|x64.Build.0 = Release|Any CPU
6466
{CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}.Release|x86.ActiveCfg = Release|Any CPU
6567
{CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}.Release|x86.Build.0 = Release|Any CPU
68+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM.ActiveCfg = Debug|Any CPU
71+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM.Build.0 = Debug|Any CPU
72+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM64.ActiveCfg = Debug|Any CPU
73+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM64.Build.0 = Debug|Any CPU
74+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x64.ActiveCfg = Debug|Any CPU
75+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x64.Build.0 = Debug|Any CPU
76+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x86.ActiveCfg = Debug|Any CPU
77+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x86.Build.0 = Debug|Any CPU
78+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
79+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|Any CPU.Build.0 = Release|Any CPU
80+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM.ActiveCfg = Release|Any CPU
81+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM.Build.0 = Release|Any CPU
82+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM64.ActiveCfg = Release|Any CPU
83+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM64.Build.0 = Release|Any CPU
84+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x64.ActiveCfg = Release|Any CPU
85+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x64.Build.0 = Release|Any CPU
86+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x86.ActiveCfg = Release|Any CPU
87+
{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x86.Build.0 = Release|Any CPU
6688
{159ED0CF-FB05-4F88-A442-90890814E6A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6789
{159ED0CF-FB05-4F88-A442-90890814E6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
6890
{159ED0CF-FB05-4F88-A442-90890814E6A8}.Debug|ARM.ActiveCfg = Debug|Any CPU

MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34-
<PackageReference Include="RazorEngineCore" Version="2020.10.1" />
3534
</ItemGroup>
3635

3736
</Project>

0 commit comments

Comments
 (0)