Refactor Transformer (add Scriban) (#562)

This commit is contained in:
Stef Heyenrath
2021-01-19 21:11:33 +01:00
committed by GitHub
parent 73e73cebb7
commit c35315e610
43 changed files with 1405 additions and 767 deletions

View File

@@ -0,0 +1,39 @@
using System;
using HandlebarsDotNet;
using JetBrains.Annotations;
using WireMock.Handlers;
namespace WireMock.Transformers.Handlebars
{
internal class HandlebarsContextFactory : ITransformerContextFactory
{
private static readonly HandlebarsConfiguration HandlebarsConfiguration = new HandlebarsConfiguration
{
UnresolvedBindingFormatter = "{0}"
};
private readonly IFileSystemHandler _fileSystemHandler;
private readonly Action<IHandlebars, IFileSystemHandler> _action;
public HandlebarsContextFactory([NotNull] IFileSystemHandler fileSystemHandler, [CanBeNull] Action<IHandlebars, IFileSystemHandler> action)
{
_fileSystemHandler = fileSystemHandler ?? throw new ArgumentNullException(nameof(fileSystemHandler));
_action = action;
}
public ITransformerContext Create()
{
var handlebars = HandlebarsDotNet.Handlebars.Create(HandlebarsConfiguration);
WireMockHandlebarsHelpers.Register(handlebars, _fileSystemHandler);
_action?.Invoke(handlebars, _fileSystemHandler);
return new HandlebarsContext
{
Handlebars = handlebars,
FileSystemHandler = _fileSystemHandler
};
}
}
}