mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-18 08:17:43 +01:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System;
|
|
using HandlebarsDotNet;
|
|
using JetBrains.Annotations;
|
|
using WireMock.Handlers;
|
|
|
|
namespace WireMock.Transformers.Handlebars
|
|
{
|
|
internal class HandlebarsContextFactory : ITransformerContextFactory
|
|
{
|
|
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();
|
|
|
|
WireMockHandlebarsHelpers.Register(handlebars, _fileSystemHandler);
|
|
|
|
_action?.Invoke(handlebars, _fileSystemHandler);
|
|
|
|
return new HandlebarsContext
|
|
{
|
|
Handlebars = handlebars,
|
|
FileSystemHandler = _fileSystemHandler
|
|
};
|
|
}
|
|
}
|
|
} |