diff --git a/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj b/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj index b2b06e3..9f8060a 100644 --- a/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj +++ b/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj @@ -12,7 +12,7 @@ The library is a modified version of Volo.Abp.TextTemplating 3.3.1 © 2013 - 2020 Volosoft. Open source license with LGPLv3.0 - 0.8.0 + 0.8.1 axuno gGmbH LGPL-3.0-only text templating netstandard c# diff --git a/Src/Axuno.TextTemplating/ITemplateRenderer.cs b/Src/Axuno.TextTemplating/ITemplateRenderer.cs index d5b9cb4..205c4d2 100644 --- a/Src/Axuno.TextTemplating/ITemplateRenderer.cs +++ b/Src/Axuno.TextTemplating/ITemplateRenderer.cs @@ -13,7 +13,7 @@ public interface ITemplateRenderer /// An optional model object that is used in the template. /// Culture name. Uses the if not specified /// A dictionary which can be used to import global objects to the template - /// + /// Returns the rendered text template. Task RenderAsync(string templateName, object? model = null, string? cultureName = null, diff --git a/Src/Axuno.TextTemplating/TemplateRenderer.cs b/Src/Axuno.TextTemplating/TemplateRenderer.cs index b17b64f..436d4f1 100644 --- a/Src/Axuno.TextTemplating/TemplateRenderer.cs +++ b/Src/Axuno.TextTemplating/TemplateRenderer.cs @@ -17,25 +17,48 @@ namespace Axuno.TextTemplating /// public class TemplateRenderer : ITemplateRenderer { - protected readonly ITemplateContentProvider _templateContentProvider; - protected readonly ITemplateDefinitionManager _templateDefinitionManager; - protected readonly IStringLocalizerFactory _stringLocalizerFactory; - + /// + /// Gets the . + /// + protected readonly ITemplateContentProvider TemplateContentProvider; + /// + /// Gets the . + /// + protected readonly ITemplateDefinitionManager TemplateDefinitionManager; + /// + /// Gets the . + /// + protected readonly IStringLocalizerFactory StringLocalizerFactory; + + /// + /// Creates a new instance of a class. + /// + /// + /// + /// public TemplateRenderer( ITemplateContentProvider templateContentProvider, ITemplateDefinitionManager templateDefinitionManager, IStringLocalizerFactory stringLocalizerFactory) { - _templateContentProvider = templateContentProvider; - _templateDefinitionManager = templateDefinitionManager; - _stringLocalizerFactory = stringLocalizerFactory; + TemplateContentProvider = templateContentProvider; + TemplateDefinitionManager = templateDefinitionManager; + StringLocalizerFactory = stringLocalizerFactory; } + /// + /// Renders a text template. + /// + /// The template name + /// An optional model object that is used in the template. + /// Culture name. Uses the if not specified + /// A dictionary which can be used to import global objects to the template + /// Returns the rendered text template. public virtual async Task RenderAsync( string templateName, - object? model, - string? cultureName, - Dictionary? globalContext) + object? model = null, + string? cultureName = null, + Dictionary? globalContext = null) { globalContext ??= new Dictionary(); @@ -58,12 +81,19 @@ public virtual async Task RenderAsync( } } + /// + /// Renders a text template. + /// + /// The template name + /// An optional model object that is used in the template. + /// A dictionary which can be used to import global objects to the template + /// Returns the rendered text template. protected virtual async Task RenderInternalAsync( string templateName, Dictionary globalContext, object? model = null) { - var templateDefinition = _templateDefinitionManager.Get(templateName); + var templateDefinition = TemplateDefinitionManager.Get(templateName); if (templateDefinition is null) throw new Exception($"Template name '{templateName}' not found."); var renderedContent = await RenderSingleTemplateAsync( @@ -84,12 +114,19 @@ protected virtual async Task RenderInternalAsync( return renderedContent; } + /// + /// Renders a text template. + /// + /// The template definition + /// A dictionary which can be used to import global objects to the template + /// An optional model object that is used in the template. + /// Returns the rendered text template. protected virtual async Task RenderSingleTemplateAsync( TemplateDefinition templateDefinition, Dictionary globalContext, object? model = null) { - var rawTemplateContent = await _templateContentProvider + var rawTemplateContent = await TemplateContentProvider .GetContentAsync( templateDefinition ); @@ -102,6 +139,14 @@ protected virtual async Task RenderSingleTemplateAsync( ); } + /// + /// Renders a text template with Scriban. + /// + /// The template definition + /// The template content + /// A dictionary which can be used to import global objects to the template + /// An optional model object that is used in the template. + /// Returns the rendered text template. protected virtual async Task RenderTemplateContentWithScribanAsync( TemplateDefinition templateDefinition, string? templateContent, @@ -119,6 +164,13 @@ protected virtual async Task RenderTemplateContentWithScribanAsync( .RenderAsync(context); } + /// + /// Creates a new Scriban . + /// + /// The . + /// The global context. + /// The model to render the template. + /// protected virtual TemplateContext CreateScribanTemplateContext( TemplateDefinition templateDefinition, Dictionary globalContext, @@ -145,7 +197,7 @@ protected virtual TemplateContext CreateScribanTemplateContext( private IStringLocalizer GetLocalizer(TemplateDefinition templateDefinition) { - return _stringLocalizerFactory.Create(templateDefinition.LocalizationResource ?? typeof(object)); + return StringLocalizerFactory.Create(templateDefinition.LocalizationResource ?? typeof(object)); } } }