diff --git a/.github/workflows/BuildFromDevelop.yml b/.github/workflows/BuildFromDevelop.yml index 33b060f..a9fd741 100644 --- a/.github/workflows/BuildFromDevelop.yml +++ b/.github/workflows/BuildFromDevelop.yml @@ -20,10 +20,11 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - cache: true + # Disable package cache to avoid lock file requirement + cache: false - name: Restore - run: dotnet restore + run: dotnet restore MbSoftLab.TemplateEngine.Core.sln - name: Build - run: dotnet build --configuration Release --no-restore + run: dotnet build MbSoftLab.TemplateEngine.Core.sln --configuration Release --no-restore - name: Test - run: dotnet test --no-restore --verbosity normal + run: dotnet test MbSoftLab.TemplateEngine.Core.sln --no-restore --verbosity normal diff --git a/.github/workflows/BuildFromMaster.yml b/.github/workflows/BuildFromMaster.yml index 44af805..e7300a8 100644 --- a/.github/workflows/BuildFromMaster.yml +++ b/.github/workflows/BuildFromMaster.yml @@ -20,10 +20,10 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - cache: true + cache: false - name: Restore - run: dotnet restore + run: dotnet restore MbSoftLab.TemplateEngine.Core.sln - name: Build - run: dotnet build --configuration Release --no-restore + run: dotnet build MbSoftLab.TemplateEngine.Core.sln --configuration Release --no-restore - name: Test - run: dotnet test --no-restore --verbosity normal + run: dotnet test MbSoftLab.TemplateEngine.Core.sln --no-restore --verbosity normal diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index ac522ea..59d6f05 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -14,11 +14,11 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - cache: true + cache: false - name: Restore - run: dotnet restore + run: dotnet restore MbSoftLab.TemplateEngine.Core.sln - name: Build - run: dotnet build --configuration Release --no-restore + run: dotnet build MbSoftLab.TemplateEngine.Core.sln --configuration Release --no-restore - name: Pack run: dotnet pack MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj --configuration Release --no-restore -o ./artifacts - name: Push to NuGet diff --git a/MbSoftLab.TemplateEngine.Core.Razor/Documentation.xml b/MbSoftLab.TemplateEngine.Core.Razor/Documentation.xml new file mode 100644 index 0000000..a5c2363 --- /dev/null +++ b/MbSoftLab.TemplateEngine.Core.Razor/Documentation.xml @@ -0,0 +1,8 @@ + + + + MbSoftLab.TemplateEngine.Core.Razor + + + + diff --git a/MbSoftLab.TemplateEngine.Core.Razor/MbSoftLab.TemplateEngine.Core.Razor.csproj b/MbSoftLab.TemplateEngine.Core.Razor/MbSoftLab.TemplateEngine.Core.Razor.csproj new file mode 100644 index 0000000..4d9a9e0 --- /dev/null +++ b/MbSoftLab.TemplateEngine.Core.Razor/MbSoftLab.TemplateEngine.Core.Razor.csproj @@ -0,0 +1,37 @@ + + + + net8.0 + 1.1.0.0 + 1.1.0.0 + 1.1.0 + 1.1.0-preview + Razor-enabled extension for MbSoftLab.TemplateEngine.Core providing RazorTemplateEngine. + true + true + Template Engine Razor RazorEngineCore Html + MbSoftLab.TemplateEngine.Core.Razor + MbSoftLab + MbSoftLab + MIT + © 2021 - 2025 MbSoftLab + MbSoftLabLogo.png + https://github.com/mbsoftlab/MbSoftLab.TemplateEngine.Core + https://github.com/mbsoftlab/MbSoftLab.TemplateEngine.Core + Git + Documentation.xml + + + + + + + + + + True + + + + + diff --git a/MbSoftLab.TemplateEngine.Core.Razor/README.md b/MbSoftLab.TemplateEngine.Core.Razor/README.md new file mode 100644 index 0000000..0c8c0aa --- /dev/null +++ b/MbSoftLab.TemplateEngine.Core.Razor/README.md @@ -0,0 +1,32 @@ +# MbSoftLab.TemplateEngine.Core.Razor + +Optionales Erweiterungspaket für MbSoftLab.TemplateEngine.Core, das die `RazorTemplateEngine` bereitstellt. + +## Installation + +```bash +# .NET CLI +dotnet add package MbSoftLab.TemplateEngine.Core.Razor + +# Oder Projekt-Referenz (Monorepo) +dotnet add .csproj reference MbSoftLab.TemplateEngine.Core.Razor/MbSoftLab.TemplateEngine.Core.Razor.csproj +``` + +## Verwendung + +```csharp +using MbSoftLab.TemplateEngine.Core; + +public class Person : TemplateDataModel +{ + public string FirstName { get; set; } +} + +var person = new Person { FirstName = "Anna" }; + +var engine = new RazorTemplateEngine(); +engine.TemplateString = "

@Model.FirstName

"; +string html = engine.CreateStringFromTemplate(person); +``` + +Hinweis: `TemplateDataModel` ist nun eine einfache Klasse im Core (ohne Razor-Basis). Die Razor-Engine erhält intern `Model` als Datenmodell (`template.Run(TemplateDataModel?.Model)`). diff --git a/MbSoftLab.TemplateEngine.Core/RazorTemplateEngine.cs b/MbSoftLab.TemplateEngine.Core.Razor/RazorTemplateEngine.cs similarity index 99% rename from MbSoftLab.TemplateEngine.Core/RazorTemplateEngine.cs rename to MbSoftLab.TemplateEngine.Core.Razor/RazorTemplateEngine.cs index dcc6fee..b802f0b 100644 --- a/MbSoftLab.TemplateEngine.Core/RazorTemplateEngine.cs +++ b/MbSoftLab.TemplateEngine.Core.Razor/RazorTemplateEngine.cs @@ -1,4 +1,4 @@ -using RazorEngineCore; +using RazorEngineCore; using System; using System.ComponentModel; using System.Globalization; @@ -86,4 +86,4 @@ public string CreateStringFromTemplate(T templateDataModel, string csHtmlTemplat TemplateString = csHtmlTemplate; return CreateStringFromTemplate(); } -} \ No newline at end of file +} diff --git a/MbSoftLab.TemplateEngine.Core.Tests/MbSoftLab.TemplateEngine.Core.Tests.csproj b/MbSoftLab.TemplateEngine.Core.Tests/MbSoftLab.TemplateEngine.Core.Tests.csproj index 7dfaf19..d184bec 100644 --- a/MbSoftLab.TemplateEngine.Core.Tests/MbSoftLab.TemplateEngine.Core.Tests.csproj +++ b/MbSoftLab.TemplateEngine.Core.Tests/MbSoftLab.TemplateEngine.Core.Tests.csproj @@ -14,6 +14,7 @@ + diff --git a/MbSoftLab.TemplateEngine.Core.sln b/MbSoftLab.TemplateEngine.Core.sln index aa7f849..3377ad7 100644 --- a/MbSoftLab.TemplateEngine.Core.sln +++ b/MbSoftLab.TemplateEngine.Core.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MbSoftLab.TemplateEngine.Co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MbSoftLab.TemplateEngine.Core", "MbSoftLab.TemplateEngine.Core\MbSoftLab.TemplateEngine.Core.csproj", "{CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MbSoftLab.TemplateEngine.Core.Razor", "MbSoftLab.TemplateEngine.Core.Razor\MbSoftLab.TemplateEngine.Core.Razor.csproj", "{A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MbSoftlab.TemplateEngine.Core.Demo", "MbSoftlab.TemplateEngine.Core.Demo\MbSoftlab.TemplateEngine.Core.Demo.csproj", "{159ED0CF-FB05-4F88-A442-90890814E6A8}" EndProject Global @@ -63,6 +65,26 @@ Global {CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}.Release|x64.Build.0 = Release|Any CPU {CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}.Release|x86.ActiveCfg = Release|Any CPU {CA5BFFAC-ADA4-478B-8B13-B3AF81FE4A05}.Release|x86.Build.0 = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM.ActiveCfg = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM.Build.0 = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|ARM64.Build.0 = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x64.ActiveCfg = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x64.Build.0 = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x86.ActiveCfg = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Debug|x86.Build.0 = Debug|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|Any CPU.Build.0 = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM.ActiveCfg = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM.Build.0 = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM64.ActiveCfg = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|ARM64.Build.0 = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x64.ActiveCfg = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x64.Build.0 = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x86.ActiveCfg = Release|Any CPU + {A9E18D5A-4B79-4C49-BB3A-1E8D0B0D7F1E}.Release|x86.Build.0 = Release|Any CPU {159ED0CF-FB05-4F88-A442-90890814E6A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {159ED0CF-FB05-4F88-A442-90890814E6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU {159ED0CF-FB05-4F88-A442-90890814E6A8}.Debug|ARM.ActiveCfg = Debug|Any CPU diff --git a/MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj b/MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj index 4601007..ea37988 100644 --- a/MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj +++ b/MbSoftLab.TemplateEngine.Core/MbSoftLab.TemplateEngine.Core.csproj @@ -31,7 +31,6 @@ - diff --git a/MbSoftLab.TemplateEngine.Core/TemplateDataModel.cs b/MbSoftLab.TemplateEngine.Core/TemplateDataModel.cs index a61384a..158156a 100644 --- a/MbSoftLab.TemplateEngine.Core/TemplateDataModel.cs +++ b/MbSoftLab.TemplateEngine.Core/TemplateDataModel.cs @@ -1,12 +1,11 @@ -using RazorEngineCore; -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace MbSoftLab.TemplateEngine.Core; -public class TemplateDataModel : RazorEngineTemplateBase +public class TemplateDataModel { [JsonIgnore] - public new T Model { get; set; } + public T Model { get; set; } public string GetNullstringValue() { diff --git a/MbSoftlab.TemplateEngine.Core.Demo/MbSoftlab.TemplateEngine.Core.Demo.csproj b/MbSoftlab.TemplateEngine.Core.Demo/MbSoftlab.TemplateEngine.Core.Demo.csproj index d7f13de..0a879a5 100644 --- a/MbSoftlab.TemplateEngine.Core.Demo/MbSoftlab.TemplateEngine.Core.Demo.csproj +++ b/MbSoftlab.TemplateEngine.Core.Demo/MbSoftlab.TemplateEngine.Core.Demo.csproj @@ -11,6 +11,7 @@ + diff --git a/README.md b/README.md index 7224d65..6478641 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,13 @@ string result = engine.CreateStringFromTemplate(); // Output: "Hallo Max Mustermann!" ``` -### Razor-Template-Beispiel +### Razor-Template-Beispiel (optional) + +Installieren Sie zusätzlich das optionale Paket: + +```bash +dotnet add package MbSoftLab.TemplateEngine.Core.Razor +``` ```csharp public class Person : TemplateDataModel @@ -44,6 +50,7 @@ var person = new Person { Tags = new List { "Developer", "Designer" } }; +// Razor steht erst nach Installation von MbSoftLab.TemplateEngine.Core.Razor zur Verfügung var engine = new RazorTemplateEngine(); engine.TemplateString = @"

@Model.FirstName

diff --git a/docs/README.md b/docs/README.md index ed1cd88..7cbf665 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,8 +11,8 @@ Willkommen zur offiziellen Dokumentation der **MbSoftLab.TemplateEngine.Core** Bibliothek - einer leistungsstarken und flexiblen Template-Engine für .NET 8.0. Diese Bibliothek bietet zwei verschiedene Ansätze zur Template-Verarbeitung: -- **TemplateEngine** - Schnell und einfach für String-basierte Templates -- **RazorTemplateEngine** - Mächtig und flexibel für komplexe HTML-Templates mit Razor-Syntax +- **TemplateEngine** – Schnell und einfach für String-basierte Templates +- **RazorTemplateEngine** – Mächtig und flexibel für komplexe HTML-Templates mit Razor-Syntax (optional, verfügbar nach Installation von `MbSoftLab.TemplateEngine.Core.Razor`) --- @@ -74,6 +74,12 @@ Install-Package MbSoftLab.TemplateEngine.Core dotnet add package MbSoftLab.TemplateEngine.Core ``` +Optional: Razor-Unterstützung installieren + +```bash +dotnet add package MbSoftLab.TemplateEngine.Core.Razor +``` + ### Erstes Beispiel ```csharp @@ -121,10 +127,11 @@ var engine = new TemplateEngine(customer, "Hallo ${Name}!"); → Siehe [Einfache Beispiele](/docs/examples/#einfache-beispiele) -### 2. Komplexe HTML-Templates +### 2. Komplexe HTML-Templates (optional) Für dynamische HTML-Generierung mit Schleifen, Bedingungen und verschachtelten Objekten. ```csharp +// Razor steht erst nach Installation von MbSoftLab.TemplateEngine.Core.Razor zur Verfügung var engine = new RazorTemplateEngine(); engine.TemplateString = "@foreach(var item in Model.Items) {
  • @item
  • }"; ``` diff --git a/docs/architecture.md b/docs/architecture.md index 7103f46..119d486 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -20,7 +20,7 @@ MbSoftLab.TemplateEngine.Core ist eine .NET 8.0 Bibliothek, die zwei verschiedene Template-Engine-Implementierungen bereitstellt: 1. **TemplateEngine** - Einfacher, schneller String-basierter Template-Engine -2. **RazorTemplateEngine** - Komplexer Razor-basierter Template-Engine für HTML +2. **RazorTemplateEngine** - Komplexer Razor-basierter Template-Engine für HTML (bereitgestellt durch das optionale Paket `MbSoftLab.TemplateEngine.Core.Razor`) Beide implementieren das gemeinsame `ITemplateEngine` Interface. @@ -39,7 +39,7 @@ graph TB subgraph "MbSoftLab.TemplateEngine.Core" B[ITemplateEngine<T>] C[TemplateEngine<T>] - D[RazorTemplateEngine<T>] + D[[RazorTemplateEngine<T>]] E[TemplateDataModelProcessor] F[PlaceholderValueReplacer] G[ReplacementActionCollection] @@ -48,7 +48,8 @@ graph TB J[TemplateEngineExtensions] end - subgraph "External Dependencies" + subgraph "MbSoftLab.TemplateEngine.Core.Razor (optional)" + D K[RazorEngineCore] end @@ -125,7 +126,7 @@ classDiagram ITemplateEngine~T~ <|.. TemplateEngine~T~ ITemplateEngine~T~ <|.. RazorTemplateEngine~T~ ITemplateEngineConfig~T~ <|.. TemplateEngineConfig~T~ - RazorEngineTemplateBase <|-- TemplateDataModel~T~ + %% Core ist von Razor entkoppelt; kein RazorEngineTemplateBase TemplateEngine~T~ --> ITemplateEngineConfig~T~ RazorTemplateEngine~T~ --> ITemplateEngineConfig~T~ RazorTemplateEngine~T~ --> TemplateDataModel~T~ diff --git a/docs/development.md b/docs/development.md index 529f41c..50bb091 100644 --- a/docs/development.md +++ b/docs/development.md @@ -66,11 +66,10 @@ MbSoftLab.TemplateEngine.Core/ │ ├── BuildFromDevelop.yml │ ├── BuildFromMaster.yml │ └── Release.yml -├── MbSoftLab.TemplateEngine.Core/ # Haupt-Bibliothek +├── MbSoftLab.TemplateEngine.Core/ # Haupt-Bibliothek (ohne Razor-Abhängigkeit) │ ├── ITemplateEngine.cs # Interface für Template-Engines │ ├── TemplateEngine.cs # Simple Template-Engine -│ ├── RazorTemplateEngine.cs # Razor-basierte Engine -│ ├── TemplateDataModel.cs # Basis-Klasse für Razor-Models +│ ├── TemplateDataModel.cs # Datenmodell (ohne Razor-Basisklasse) │ ├── TemplateDataModelProcessor.cs # Property/Methoden-Verarbeitung │ ├── PlaceholderValueRaplacer.cs # Platzhalter-Ersetzung │ ├── ReplacementActionCollection.cs # Typ-spezifische Actions @@ -78,12 +77,12 @@ MbSoftLab.TemplateEngine.Core/ │ ├── TemplateEngineConfig.cs # Konfigurations-Implementierung │ ├── TemplateEngineExtensions.cs # Erweiterungsmethoden │ └── MbSoftLab.TemplateEngine.Core.csproj # Projekt-Datei -├── MbSoftLab.TemplateEngine.Core.Tests/ # Unit-Tests +├── MbSoftLab.TemplateEngine.Core.Tests/ # Unit-Tests (referenzieren bei Bedarf Razor-Projekt) │ ├── TemplateEngineUnitTest.cs │ ├── RazorTemplateEngineUnitTest.cs │ ├── TemplateDataModelDummy.cs # Test-Fixtures │ └── *.cs # Weitere Test-Dateien -├── MbSoftlab.TemplateEngine.Core.Demo/ # Demo-Anwendung +├── MbSoftlab.TemplateEngine.Core.Demo/ # Demo-Anwendung (Razor-Demo referenziert Razor-Projekt) │ ├── Program.cs │ ├── Person.cs │ ├── Address.cs @@ -97,7 +96,10 @@ MbSoftLab.TemplateEngine.Core/ ├── CHANGELOG.md # Versions-Historie ├── RELEASENOTES.md # Release-Informationen ├── README.md # Haupt-Dokumentation -└── MbSoftLab.TemplateEngine.Core.sln # Solution-Datei +├── MbSoftLab.TemplateEngine.Core.Razor/ # Optionales Razor-Erweiterungsprojekt +│ ├── RazorTemplateEngine.cs # Razor-basierte Engine +│ └── MbSoftLab.TemplateEngine.Core.Razor.csproj +└── MbSoftLab.TemplateEngine.Core.sln # Solution-Datei (enthält beide Projekte) ``` --- @@ -119,6 +121,20 @@ dotnet pack --configuration Release **Output:** Das NuGet-Package wird in `bin/Release/` erstellt. +### Razor-Erweiterung (optional) + +Das Razor-Feature ist als separates Paket/Projekt verfügbar. + +```bash +# Razor-Erweiterung lokal referenzieren +dotnet add .csproj reference MbSoftLab.TemplateEngine.Core.Razor/MbSoftLab.TemplateEngine.Core.Razor.csproj + +# Oder als NuGet installieren +dotnet add package MbSoftLab.TemplateEngine.Core.Razor +``` + +Die Projekte, die `RazorTemplateEngine` verwenden, müssen die Razor-Erweiterung referenzieren oder das NuGet einsetzen. + ### Tests ausführen ```bash diff --git a/docs/examples.md b/docs/examples.md index 61389dd..4f6fa63 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -28,6 +28,12 @@ Install-Package MbSoftLab.TemplateEngine.Core dotnet add package MbSoftLab.TemplateEngine.Core ``` +Optional: Razor-Unterstützung + +```bash +dotnet add package MbSoftLab.TemplateEngine.Core.Razor +``` + ### Erstes Beispiel (30 Sekunden) ```csharp @@ -342,12 +348,13 @@ string result = engine.CreateStringFromTemplate(); --- -## Razor-Templates +## Razor-Templates (optional) ### Beispiel 12: Einfaches Razor-Template ```csharp using MbSoftLab.TemplateEngine.Core; +// Hinweis: Stellen Sie sicher, dass das Paket MbSoftLab.TemplateEngine.Core.Razor installiert ist. public class Person : TemplateDataModel { @@ -363,6 +370,7 @@ var person = new Person Age = 35 }; +// Razor steht erst nach Installation von MbSoftLab.TemplateEngine.Core.Razor zur Verfügung var engine = new RazorTemplateEngine(); string razorTemplate = @"