示例#1
0
        private static Option<IExpressionConstant> FindParentLoop(SymbolTableStack stack)
        {
            var parentLoop = stack.Reference("forloop", skiplevels:1 );

            if (parentLoop.IsError || !parentLoop.SuccessResult.HasValue)
            {
                return new None<IExpressionConstant>();
            }
            return parentLoop.SuccessValue<DictionaryValue>();
                
        }
        public static DictionaryValue CreateForLoopDescriptor(String name, int iter, int length, int col, int maxcol, int row, SymbolTableStack stack)
        {
            return new DictionaryValue(new Dictionary<String, Option<IExpressionConstant>>
            {               
                {"first", new BooleanValue(iter == 0)},
                {"index", NumericValue.Create(iter + 1)},
                {"col" , NumericValue.Create(col + 1)},
                {"row" , NumericValue.Create(row + 1)},
                {"row0" , NumericValue.Create(row)},
                {"col0" , NumericValue.Create(col)},
                {"col_first" , new BooleanValue(col == 0)},
                {"col_last" , new BooleanValue(col == maxcol)},
                {"index0", NumericValue.Create(iter)},
                {"rindex", NumericValue.Create(length - iter)},
                {"rindex0", NumericValue.Create(length - iter - 1)},
                {"last", new BooleanValue(length - iter - 1 == 0)},
                {"length", NumericValue.Create(length) },
                {"name", new StringValue(name) }
            });

        }
示例#3
0
        public static DictionaryValue CreateForLoopDescriptor(String name, int iter, int length, SymbolTableStack stack)
        {
            return new DictionaryValue(new Dictionary<String, Option<IExpressionConstant>>
            {               
                {"parentloop", FindParentLoop(stack)}, // see: https://github.com/Shopify/liquid/pull/520
                {"first", new BooleanValue(iter == 0)},
                {"index", NumericValue.Create(iter + 1)},
                {"index0", NumericValue.Create(iter)},
                {"rindex", NumericValue.Create(length - iter)},
                {"rindex0", NumericValue.Create(length - iter - 1)},
                {"last", new BooleanValue(length - iter - 1 == 0)},
                {"length", NumericValue.Create(length) },
                {"name", new StringValue(name) }
            });

        }