Kephas.Templating 11.1.0

Prefix Reserved
dotnet add package Kephas.Templating --version 11.1.0                
NuGet\Install-Package Kephas.Templating -Version 11.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kephas.Templating" Version="11.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kephas.Templating --version 11.1.0                
#r "nuget: Kephas.Templating, 11.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kephas.Templating as a Cake Addin
#addin nuget:?package=Kephas.Templating&version=11.1.0

// Install Kephas.Templating as a Cake Tool
#tool nuget:?package=Kephas.Templating&version=11.1.0                

Templating

Introduction

The templating area in Kephas handles the text generation out of various templates. The entry point is the ITemplateProcessor singleton service, which returns a processed result, typically in form of a string, through the ProcessAsync method provided with a template and a model.

Check the following packages for more information:

Usage

// normally you would get the processor injected into the service constructor.
var processor = injector.Resolve<ITemplateProcessor>();

var result = processor.Process(new StringTemplate("hi {name}!", "interpolate"), new { name = "Johnny" }));
Assert.Equals("hi Johnny!", result);

// this is a simpler alternative for interpolation using the Interpolate extension method.
var result = processor.Interpolate("hi {name}!", new { name = "Johnny" }));
Assert.Equals("hi Johnny!", result);

The ITemplateProcessor service

This service is the central piece providing the ProcessAsync method through which a template is processed. Typically, the output is written to the ITemplateProcessingContext.TextWriter, but, if this is not set by the user, it is the duty of the template processor to prepare the TextWriter and to return in the operation result the result returned by the processing engine.

DefaultTemplateProcessor is the default implementation of the ITemplateProcessor. Just like the other default implementations provided by the Kephas framework, it declares a low override priority, so that it can be easily overridden. By default, it delegates the template processing to a specific ITemplatingEngine handling the provided template. It identifies the engine based on the template's kind, which the engine declares using the [TemplateKind(...)] attribute.

Template engines

These services implement the ITemplatingEngine contract and handle specific template kinds. By default, the framework provides the InterpolationTemplatingEngine which handles simple string interpolations using the curly braces pattern: {variable}. All such variables are replaced with the values of the properties' with the same name in the model.

Controlling the template processing

The processing context

Additional to the template and the model, the processing methods receive also a context which can be used to further control the operations. Just like all the other context instances, it is a dynamic expandable object (IExpando) and it aggregates the provided template and the model. Through the Result and Exception properties, the behaviors (see below) can control the processing output.

The processing behaviors

The DefaultTemplateProcessor uses also ITemplateProcessingBehavior services to further control the processing. Just like the ITemplateEngine services, they declare the template kinds they handle, and are invoked before and after the selected engine processes the template. They can cover various purposes: authorization, pre-processing/post-processing, audit, and whatever other functionality may be required.

The templates

A template implements ITemplate, basically providing a Kind (string), a Name (string), and an asynchronous content (GetContentAsync()). By default, the framework supports these templates:

  • StringTemplate: constructed using a string. If the Kind is not provided, 'interpolation' is considered instead.
  • StringBuilderTemplate: constructed using a StringBuilder. If the Kind is not provided, 'interpolation' is considered instead.
  • StreamTemplate: constructed using a Stream. If the Kind is not provided, 'interpolation' is considered instead.
  • FileTemplate: constructed using a file path. If the Kind is not provided, the file extension is considered instead.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Kephas.Templating:

Package Downloads
Kephas.Templating.Razor

Provides the templating implementation for Razor. Typically used areas and classes/interfaces/services: - Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
11.1.0 607 4/13/2022
11.1.0-dev.4 135 4/6/2022
11.1.0-dev.3 125 3/30/2022
11.1.0-dev.2 131 3/23/2022
11.1.0-dev.1 123 3/23/2022
11.0.0 554 3/11/2022
11.0.0-dev.7 127 3/7/2022
11.0.0-dev.6 131 2/28/2022
11.0.0-dev.5 125 2/26/2022
11.0.0-dev.4 133 2/24/2022
11.0.0-dev.3 131 2/23/2022
11.0.0-dev.2 123 2/18/2022

Please check https://github.com/kephas-software/kephas/releases for the change log.
           Also check the documentation and the samples from https://github.com/kephas-software/kephas/wiki and https://github.com/kephas-software/kephas/tree/master/Samples.