2023-03-03 21:47:23 +00:00
|
|
|
|
using Elsa.Liquid.Contracts;
|
|
|
|
|
|
using Elsa.Liquid.Options;
|
2022-01-12 11:37:40 +00:00
|
|
|
|
using Fluid;
|
2024-04-26 13:50:05 +00:00
|
|
|
|
using Fluid.Filters;
|
2022-01-12 11:37:40 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
2022-12-31 15:16:43 +00:00
|
|
|
|
// 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
|
|
|
|
{
|
2022-12-31 15:16:43 +00:00
|
|
|
|
internal static void AddFilters(this TemplateContext templateContext, FluidOptions options, IServiceProvider services)
|
2022-01-12 11:37:40 +00:00
|
|
|
|
{
|
2022-12-31 15:16:43 +00:00
|
|
|
|
foreach (var (key, value) in options.FilterRegistrations)
|
2022-01-12 11:37:40 +00:00
|
|
|
|
{
|
2022-12-31 15:16:43 +00:00
|
|
|
|
templateContext.Options.Filters.AddFilter(key, (input, arguments, ctx) =>
|
2022-01-12 11:37:40 +00:00
|
|
|
|
{
|
2022-12-31 15:16:43 +00:00
|
|
|
|
var filter = (ILiquidFilter)services.GetRequiredService(value);
|
|
|
|
|
|
return filter.ProcessAsync(input, arguments, ctx);
|
|
|
|
|
|
});
|
2022-01-12 11:37:40 +00:00
|
|
|
|
}
|
2024-04-26 13:50:05 +00:00
|
|
|
|
options.FluidFiltersDelegate(templateContext);
|
2022-01-12 11:37:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|