elsa-core/src/modules/Elsa.Liquid/Extensions/TemplateContextExtensions.cs

24 lines
801 B
C#
Raw Normal View History

using Elsa.Liquid.Contracts;
using Elsa.Liquid.Options;
2022-01-12 11:37:40 +00:00
using Fluid;
using Fluid.Filters;
2022-01-12 11:37:40 +00:00
using Microsoft.Extensions.DependencyInjection;
// ReSharper disable once CheckNamespace
namespace Elsa.Extensions;
2023-02-15 11:09:45 +00:00
internal static class TemplateContextExtensions
2022-01-12 11:37:40 +00:00
{
internal static void AddFilters(this TemplateContext templateContext, FluidOptions options, IServiceProvider services)
2022-01-12 11:37:40 +00:00
{
foreach (var (key, value) in options.FilterRegistrations)
2022-01-12 11:37:40 +00:00
{
templateContext.Options.Filters.AddFilter(key, (input, arguments, ctx) =>
2022-01-12 11:37:40 +00:00
{
var filter = (ILiquidFilter)services.GetRequiredService(value);
return filter.ProcessAsync(input, arguments, ctx);
});
2022-01-12 11:37:40 +00:00
}
options.FluidFiltersDelegate(templateContext);
2022-01-12 11:37:40 +00:00
}
}