public BlockHelperExpression( string helperName, IEnumerable <Expression> arguments, Expression body, Expression inversion, bool isRaw = false) : this(helperName, arguments, BlockParamsExpression.Empty(), body, inversion, isRaw) { }
public override Expression GetAccumulatedBlock() { if (_accumulatedBody == null) { _accumulatedBody = GetBlockBody(); _accumulatedInversion = Expression.Block(Expression.Empty()); } else if (_accumulatedInversion == null) { _accumulatedInversion = GetBlockBody(); } var resultExpr = HandlebarsExpression.BlockHelper( _startingNode.HelperName, _startingNode.Arguments.Where(o => o.NodeType != (ExpressionType)HandlebarsExpressionType.BlockParamsExpression), _startingNode.Arguments.OfType <BlockParamsExpression>().SingleOrDefault() ?? BlockParamsExpression.Empty(), _accumulatedBody, _accumulatedInversion, _startingNode.IsRaw); if (_startingNode.IsRaw) { return(HandlebarsExpression.Statement( resultExpr, false, _trimBefore, _trimAfter)); } return(resultExpr); }
public override void HandleElement(Expression item) { if (IsElseBlock(item)) { _accumulatedExpression = HandlebarsExpression.Iterator( _startingNode.Arguments.Single(o => o.NodeType != (ExpressionType)HandlebarsExpressionType.BlockParamsExpression), _startingNode.Arguments.OfType <BlockParamsExpression>().SingleOrDefault() ?? BlockParamsExpression.Empty(), Expression.Block(_body)); _body = new List <Expression>(); } else { _body.Add((Expression)item); } }
public override bool IsClosingElement(Expression item) { if (IsClosingNode(item)) { // If the template has no content within the block, e.g. `{{#each ...}}{{/each}`, then the block body is a no-op. var bodyStatements = _body.Count != 0 ? _body : new List <Expression> { Expression.Empty() }; if (_accumulatedExpression == null) { _accumulatedExpression = HandlebarsExpression.Iterator( _startingNode.Arguments.Single(o => o.NodeType != (ExpressionType)HandlebarsExpressionType.BlockParamsExpression), _startingNode.Arguments.OfType <BlockParamsExpression>().SingleOrDefault() ?? BlockParamsExpression.Empty(), Expression.Block(bodyStatements)); } else { _accumulatedExpression = HandlebarsExpression.Iterator( ((IteratorExpression)_accumulatedExpression).Sequence, ((IteratorExpression)_accumulatedExpression).BlockParams, ((IteratorExpression)_accumulatedExpression).Template, Expression.Block(bodyStatements)); } return(true); } else { return(false); } }
public IteratorExpression(Expression sequence, Expression template, Expression ifEmpty) : this(sequence, BlockParamsExpression.Empty(), template, ifEmpty) { }