2022-05-26 10:47:31 +00:00
|
|
|
|
using Elsa.Liquid.Options;
|
|
|
|
|
|
using Elsa.Liquid.Services;
|
2022-01-12 11:37:40 +00:00
|
|
|
|
using Fluid;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
|
namespace Elsa.Liquid.Extensions
|
2022-01-12 11:37:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
public static class TemplateContextExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
internal static void AddFilters(this TemplateContext templateContext, FluidOptions options, IServiceProvider services)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var (key, value) in options.FilterRegistrations)
|
|
|
|
|
|
{
|
|
|
|
|
|
templateContext.Options.Filters.AddFilter(key, (input, arguments, ctx) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var filter = (ILiquidFilter)services.GetRequiredService(value);
|
|
|
|
|
|
return filter.ProcessAsync(input, arguments, ctx);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|