mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-10 18:56:50 +02:00
Create WireMock.Net.MimePart project (#1300)
* Create WireMock.Net.MimePart project * . * REFACTOR * ILRepack * -- * ... * x * x * . * fix * public class MimePartMatcher * shared * min * . * <!--<DelaySign>true</DelaySign>--> * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using HandlebarsDotNet;
|
||||
using HandlebarsDotNet.Helpers.Extensions;
|
||||
using Stef.Validation;
|
||||
using WireMock.Handlers;
|
||||
|
||||
namespace WireMock.Transformers.Handlebars;
|
||||
|
||||
internal class HandlebarsContext : IHandlebarsContext
|
||||
{
|
||||
public IHandlebars Handlebars { get; }
|
||||
|
||||
public IFileSystemHandler FileSystemHandler { get; }
|
||||
|
||||
public HandlebarsContext(IHandlebars handlebars, IFileSystemHandler fileSystemHandler)
|
||||
{
|
||||
Handlebars = Guard.NotNull(handlebars);
|
||||
FileSystemHandler = Guard.NotNull(fileSystemHandler);
|
||||
}
|
||||
|
||||
public string ParseAndRender(string text, object model)
|
||||
{
|
||||
var template = Handlebars.Compile(text);
|
||||
return template(model);
|
||||
}
|
||||
|
||||
public object? ParseAndEvaluate(string text, object model)
|
||||
{
|
||||
if (text.StartsWith("{{") && text.EndsWith("}}") &&
|
||||
Handlebars.TryEvaluate(text, model, out var result) &&
|
||||
result is not UndefinedBindingResult)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return ParseAndRender(text, model);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user