mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-01 22:53:02 +02:00
Handlebars Extension (#286)
* wip * HandlebarsRegistrationCallback * HandlebarsContextFactoryTests * 1.0.21.0 * fix sonar * LocalFileSystemHandler * readme * Fix System.IO.IOException
This commit is contained in:
34
src/WireMock.Net/Transformers/HandlebarsContextFactory.cs
Normal file
34
src/WireMock.Net/Transformers/HandlebarsContextFactory.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using HandlebarsDotNet;
|
||||
using System;
|
||||
using WireMock.Handlers;
|
||||
|
||||
namespace WireMock.Transformers
|
||||
{
|
||||
internal class HandlebarsContextFactory : IHandlebarsContextFactory
|
||||
{
|
||||
private static readonly HandlebarsConfiguration HandlebarsConfiguration = new HandlebarsConfiguration
|
||||
{
|
||||
UnresolvedBindingFormatter = "{0}"
|
||||
};
|
||||
|
||||
private readonly IFileSystemHandler _fileSystemHandler;
|
||||
private readonly Action<IHandlebars, IFileSystemHandler> _action;
|
||||
|
||||
public HandlebarsContextFactory(IFileSystemHandler fileSystemHandler, Action<IHandlebars, IFileSystemHandler> action)
|
||||
{
|
||||
_fileSystemHandler = fileSystemHandler;
|
||||
_action = action;
|
||||
}
|
||||
|
||||
public IHandlebars Create()
|
||||
{
|
||||
var handlebarsContext = Handlebars.Create(HandlebarsConfiguration);
|
||||
|
||||
HandlebarsHelpers.Register(handlebarsContext, _fileSystemHandler);
|
||||
|
||||
_action?.Invoke(handlebarsContext, _fileSystemHandler);
|
||||
|
||||
return handlebarsContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user