| | | 1 | | using Elsa.Expressions.Contracts; |
| | | 2 | | using Elsa.Expressions.Helpers; |
| | | 3 | | using Elsa.Expressions.Models; |
| | | 4 | | using Elsa.Expressions.Liquid.Contracts; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Expressions.Liquid.Expressions; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Evaluates a Liquid expression. |
| | | 10 | | /// </summary> |
| | | 11 | | public class LiquidExpressionHandler : IExpressionHandler |
| | | 12 | | { |
| | | 13 | | private readonly ILiquidTemplateManager _liquidTemplateManager; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="LiquidExpressionHandler"/> class. |
| | | 17 | | /// </summary> |
| | 0 | 18 | | public LiquidExpressionHandler(ILiquidTemplateManager liquidTemplateManager) |
| | | 19 | | { |
| | 0 | 20 | | _liquidTemplateManager = liquidTemplateManager; |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public async ValueTask<object?> EvaluateAsync(Expression expression, Type returnType, ExpressionExecutionContext con |
| | | 25 | | { |
| | 0 | 26 | | var liquidExpression = expression.Value.ConvertTo<string>() ?? ""; |
| | 0 | 27 | | var renderedString = await _liquidTemplateManager.RenderAsync(liquidExpression, context); |
| | 0 | 28 | | return renderedString.ConvertTo(returnType); |
| | 0 | 29 | | } |
| | | 30 | | } |