mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 23:41:19 +02:00
Update Transformer functionality to return value instead of string (#858)
This commit is contained in:
@@ -1,18 +1,35 @@
|
||||
using HandlebarsDotNet;
|
||||
using HandlebarsDotNet.Helpers.Extensions;
|
||||
using Stef.Validation;
|
||||
using WireMock.Handlers;
|
||||
|
||||
namespace WireMock.Transformers.Handlebars
|
||||
namespace WireMock.Transformers.Handlebars;
|
||||
|
||||
internal class HandlebarsContext : IHandlebarsContext
|
||||
{
|
||||
internal class HandlebarsContext : IHandlebarsContext
|
||||
public IHandlebars Handlebars { get; }
|
||||
|
||||
public IFileSystemHandler FileSystemHandler { get; }
|
||||
|
||||
public HandlebarsContext(IHandlebars handlebars, IFileSystemHandler fileSystemHandler)
|
||||
{
|
||||
public IHandlebars Handlebars { get; set; }
|
||||
Handlebars = Guard.NotNull(handlebars);
|
||||
FileSystemHandler = Guard.NotNull(fileSystemHandler);
|
||||
}
|
||||
|
||||
public IFileSystemHandler FileSystemHandler { get; set; }
|
||||
public string ParseAndRender(string text, object model)
|
||||
{
|
||||
var template = Handlebars.Compile(text);
|
||||
return template(model);
|
||||
}
|
||||
|
||||
public string ParseAndRender(string text, object model)
|
||||
public object? ParseAndEvaluate(string text, object model)
|
||||
{
|
||||
if (Handlebars.TryEvaluate(text, model, out var result) && result is not UndefinedBindingResult)
|
||||
{
|
||||
var template = Handlebars.Compile(text);
|
||||
return template(model);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ParseAndRender(text, model);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user