Пример #1
0
 public static IteratorExpression Iterator(
     Expression sequence,
     BlockParamsExpression blockParams,
     Expression template)
 {
     return(new IteratorExpression(sequence, blockParams, template, Empty()));
 }
Пример #2
0
 public IteratorExpression(Expression sequence, BlockParamsExpression blockParams, Expression template, Expression ifEmpty)
     : base("each", Enumerable.Empty <Expression>(), blockParams, template, ifEmpty, false)
 {
     Sequence = sequence;
     Template = template;
     IfEmpty  = ifEmpty;
 }
Пример #3
0
 public static IteratorExpression Iterator(
     string helperName,
     Expression sequence,
     BlockParamsExpression blockParams,
     Expression template)
 {
     return(new IteratorExpression(helperName, sequence, blockParams, template, Empty()));
 }
 public BlockHelperExpression(
     string helperName,
     IEnumerable <Expression> arguments,
     Expression body,
     Expression inversion,
     bool isRaw = false)
     : this(helperName, arguments, BlockParamsExpression.Empty(), body, inversion, isRaw)
 {
 }
Пример #5
0
 public static BlockHelperExpression BlockHelper(
     string helperName,
     IEnumerable <Expression> arguments,
     BlockParamsExpression blockParams,
     Expression body,
     Expression inversion,
     bool isRaw = false)
 {
     return(new BlockHelperExpression(helperName, arguments, blockParams, body, inversion, isRaw));
 }
 public BlockHelperExpression(
     string helperName,
     IEnumerable <Expression> arguments,
     BlockParamsExpression blockParams,
     Expression body,
     Expression inversion,
     bool isRaw = false)
     : base(helperName, true, arguments, isRaw)
 {
     Body        = body;
     Inversion   = inversion;
     BlockParams = blockParams;
     IsBlock     = true;
 }
Пример #7
0
        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);
        }
Пример #8
0
 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);
     }
 }
Пример #9
0
 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 IteratorExpression(Expression sequence, Expression template, Expression ifEmpty)
     : this(sequence, BlockParamsExpression.Empty(), template, ifEmpty)
 {
 }