From cca0f47fef53d0ca4bbefdd056158cd1415085d7 Mon Sep 17 00:00:00 2001 From: Alexander Selishchev Date: Wed, 17 Apr 2024 00:28:27 +0300 Subject: [PATCH] Update to PR #141 --- Pack.ps1 | 2 +- .../RazorEngineCore.Tests.csproj | 2 +- RazorEngineCore.Tests/TestCompileAndRun.cs | 15 +++++++++------ .../IRazorEngineCompilationOptionsBuilder.cs | 7 +++++++ RazorEngineCore/RazorEngine.cs | 2 +- RazorEngineCore/RazorEngineCompilationOptions.cs | 2 +- .../RazorEngineCompilationOptionsBuilder.cs | 9 +++++++++ RazorEngineCore/RazorEngineCore.csproj | 10 +++++----- 8 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Pack.ps1 b/Pack.ps1 index f2acf97..13dc543 100644 --- a/Pack.ps1 +++ b/Pack.ps1 @@ -1,4 +1,4 @@ dotnet build -c Release dotnet test dotnet pack -c Release -o artifacts RazorEngineCore\RazorEngineCore.csproj -p:symbolPackageFormat=snupkg --include-symbols -dotnet nuget push artifacts\RazorEngineCore.2023.11.2.nupkg --source https://www.nuget.org/api/v2/package -k KEY +dotnet nuget push artifacts\RazorEngineCore.2024.4.1.nupkg --source https://www.nuget.org/api/v2/package -k KEY diff --git a/RazorEngineCore.Tests/RazorEngineCore.Tests.csproj b/RazorEngineCore.Tests/RazorEngineCore.Tests.csproj index f194a4c..6a28b1e 100644 --- a/RazorEngineCore.Tests/RazorEngineCore.Tests.csproj +++ b/RazorEngineCore.Tests/RazorEngineCore.Tests.csproj @@ -1,7 +1,7 @@  - net472;net6.0 + net472;net6.0;net7.0;net8.0 false diff --git a/RazorEngineCore.Tests/TestCompileAndRun.cs b/RazorEngineCore.Tests/TestCompileAndRun.cs index f269369..a772a49 100644 --- a/RazorEngineCore.Tests/TestCompileAndRun.cs +++ b/RazorEngineCore.Tests/TestCompileAndRun.cs @@ -241,7 +241,7 @@ public void TestCompileAndRun_NullablePropertyWithValue() string actual = template.Run(instance => instance.Model = new TestModel() { - DateTime = dateTime + DateTime = dateTime }); Assert.AreEqual("DateTime: " + dateTime, actual); @@ -258,7 +258,7 @@ public void TestCompileAndRun_NullablePropertyWithoutValue() string actual = template.Run(instance => instance.Model = new TestModel() { - DateTime = dateTime + DateTime = dateTime }); Assert.AreEqual("DateTime: " + dateTime, actual); @@ -538,7 +538,7 @@ Hello @Model.Decorator(Model.C) { instance.Model = new TestModel { - C = "Alex" + C = "Alex" }; }); @@ -635,7 +635,7 @@ public void TestCompileAndRun_DynamicModelLinq() "; string actual = template.Run(new { - Numbers = new List() {2, 1, 3} + Numbers = new List() { 2, 1, 3 } }); Assert.AreEqual(expected, actual); @@ -911,12 +911,15 @@ public void TestCompileAndRun_IncludeDebuggingForTypedAnonymous_EnabledDebugging [TestMethod] public void TestCompileAndRun_ProjectEngineBuilderAction_IsInvoked() { - var builderActionIsInvoked = false; + var builderActionIsInvoked = false; RazorEngine razorEngine = new RazorEngine(); IRazorEngineCompiledTemplate template = razorEngine.Compile("

Hello @Model.Name

", builder => { builder.IncludeDebuggingInfo(); - builder.Options.ProjectEngineBuilderAction = (x) => builderActionIsInvoked = true; + builder.ConfigureRazorEngineProject(engineBuilder => + { + builderActionIsInvoked = true; + }); }); template.EnableDebugging(); diff --git a/RazorEngineCore/IRazorEngineCompilationOptionsBuilder.cs b/RazorEngineCore/IRazorEngineCompilationOptionsBuilder.cs index 5d6e2e2..9ef174a 100644 --- a/RazorEngineCore/IRazorEngineCompilationOptionsBuilder.cs +++ b/RazorEngineCore/IRazorEngineCompilationOptionsBuilder.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis; namespace RazorEngineCore @@ -56,5 +57,11 @@ public interface IRazorEngineCompilationOptionsBuilder /// Enables debug info /// void IncludeDebuggingInfo(); + + /// + /// Access RazorProjectEngineBuilder to register new Features etc + /// + /// + void ConfigureRazorEngineProject(Action configure); } } \ No newline at end of file diff --git a/RazorEngineCore/RazorEngine.cs b/RazorEngineCore/RazorEngine.cs index 0bfe950..672d41b 100644 --- a/RazorEngineCore/RazorEngine.cs +++ b/RazorEngineCore/RazorEngine.cs @@ -67,7 +67,7 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin (builder) => { builder.SetNamespace(options.TemplateNamespace); - options.ProjectEngineBuilderAction?.Invoke(builder); + options.ProjectEngineBuilder?.Invoke(builder); }); RazorSourceDocument document = RazorSourceDocument.Create(templateSource, fileName); diff --git a/RazorEngineCore/RazorEngineCompilationOptions.cs b/RazorEngineCore/RazorEngineCompilationOptions.cs index 4d2282f..2ff6a75 100644 --- a/RazorEngineCore/RazorEngineCompilationOptions.cs +++ b/RazorEngineCore/RazorEngineCompilationOptions.cs @@ -23,7 +23,7 @@ public class RazorEngineCompilationOptions "System.Collections", "System.Collections.Generic" }; - public Action ProjectEngineBuilderAction { get; set; } + public Action ProjectEngineBuilder { get; set; } public RazorEngineCompilationOptions() { diff --git a/RazorEngineCore/RazorEngineCompilationOptionsBuilder.cs b/RazorEngineCore/RazorEngineCompilationOptionsBuilder.cs index 16ba347..997c6ef 100644 --- a/RazorEngineCore/RazorEngineCompilationOptionsBuilder.cs +++ b/RazorEngineCore/RazorEngineCompilationOptionsBuilder.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis; namespace RazorEngineCore @@ -134,5 +135,13 @@ public void IncludeDebuggingInfo() this.Options.IncludeDebuggingInfo = true; } + /// + /// Enables debug info + /// + public void ConfigureRazorEngineProject(Action configure) + { + this.Options.ProjectEngineBuilder = configure; + } + } } diff --git a/RazorEngineCore/RazorEngineCore.csproj b/RazorEngineCore/RazorEngineCore.csproj index f4e4a23..90fa169 100644 --- a/RazorEngineCore/RazorEngineCore.csproj +++ b/RazorEngineCore/RazorEngineCore.csproj @@ -1,13 +1,13 @@  - net6.0;net5.0;netstandard2.0 + net8.0;net7.0;net6.0;net5.0;netstandard2.0 true - 2023.11.2 - Alexander Selishchev, Simon Mourier, William David Cossey, Benjamin Smith, Dag H. Baardsen, krmr, jddj007-hydra, shehrozeee, TheAtomicOption + 2024.4.1 + Alexander Selishchev, Simon Mourier, William David Cossey, Benjamin Smith, Dag H. Baardsen, krmr, jddj007-hydra, shehrozeee, TheAtomicOption, ItWorksOnMyMachine https://github.com/adoconnection/RazorEngineCore NET6 Razor Template Engine - 2023.11.2 - 2023.11.2 + 2024.4.1 + 2024.4.1 Alexander Selishchev true