Example #1
0
        private void RenderFromLiquidHash(IncludeTag includeTag, ITemplateContext templateContext, String virtualFileName,
                                          LiquidAST snippetAst)
        {
            Action <SymbolTable> action = localBlockScope => localBlockScope.DefineLocalVariable(
                virtualFileName, LiquidExpressionEvaluator.Eval(includeTag.ForExpression, templateContext).SuccessResult);

            RenderBlock(includeTag, templateContext, snippetAst, action);
        }
Example #2
0
        private void RenderIncludeBlock(IncludeTag includeTag, ITemplateContext templateContext, String virtualFileName,
                                        LiquidAST snippetAst)
        {
            Action <SymbolTable> action = localBlockScope =>
            {
                if (includeTag.WithExpression != null)
                {
                    var withExpression = LiquidExpressionEvaluator.Eval(includeTag.WithExpression, templateContext);
                    localBlockScope.DefineLocalVariable(virtualFileName, withExpression.SuccessResult);
                }
            };

            RenderBlock(includeTag, templateContext, snippetAst, action);
        }
Example #3
0
        private void RenderBlock(
            IncludeTag includeTag,
            ITemplateContext templateContext,
            LiquidAST snippetAst,
            Action <SymbolTable> renderAction)
        {
            var localBlockScope = new SymbolTable();

            DefineLocalVariables(templateContext, localBlockScope, includeTag.Definitions);

            renderAction(localBlockScope);

            RenderWithLocalScope(templateContext, localBlockScope, snippetAst.RootNode);
        }
        public void It_Should_Parse_An_AST()
        {
            // Arrange
            const string helloWorld = "HELLO WORLD";
            LiquidAST ast = new LiquidAST();
            TemplateContext ctx = new TemplateContext();
            ast.RootNode.AddChild(new TreeNode<IASTNode>(new RawBlockTag(helloWorld)));

            // Act
            String result = Render(ctx, ast);

            // Assert
            Assert.That(result, Is.EqualTo(helloWorld));

        }
Example #5
0
        public void It_Should_Parse_An_AST()
        {
            // Arrange
            const string    helloWorld = "HELLO WORLD";
            LiquidAST       ast        = new LiquidAST();
            TemplateContext ctx        = new TemplateContext();

            ast.RootNode.AddChild(new TreeNode <IASTNode>(new RawBlockTag(helloWorld)));

            // Act
            String result = Render(ctx, ast);

            // Assert
            Assert.Equal(helloWorld, result);
        }
Example #6
0
        private static string Render(ITemplateContext templateContext, LiquidAST liquidAst, Action <LiquidError> onError = null)
        {
            if (onError == null)
            {
                onError = error => { };
            }
            String result           = "";
            var    renderingVisitor = new RenderingVisitor(templateContext);

            renderingVisitor.StartWalking(liquidAst.RootNode, str => result += str);
            if (renderingVisitor.HasErrors)
            {
                foreach (var error in renderingVisitor.RenderingErrors)
                {
                    onError(error);
                }
                //throw new LiquidRendererException(renderingVisitor.RenderingErrors);
            }
            return(result);
        }
 public static IEnumerable <TreeNode <IASTNode> > FindNodesWithType(LiquidAST ast, Type type)
 {
     return(FindWhere(ast.RootNode.Children, type));
 }
Example #8
0
 public String Walk(LiquidAST liquidAST)
 {
     return(Walk(liquidAST.RootNode, 0));
 }
 private static string Render(ITemplateContext templateContext, LiquidAST liquidAst)
 {
     String result = "";
     var renderingVisitor = new RenderingVisitor(templateContext);
     renderingVisitor.StartWalking(liquidAst.RootNode, str => result += str);
     if (renderingVisitor.HasErrors)
     {
         throw new LiquidRendererException(renderingVisitor.Errors);
     }
     return result;
 }
 public static IEnumerable<TreeNode<IASTNode>> FindNodesWithType(LiquidAST ast, Type type)
 {
     return FindWhere(ast.RootNode.Children, type);
 }
Example #11
0
 public String Walk(LiquidAST liquidAST)
 {
     return Walk(liquidAST.RootNode, 0);
 }
Example #12
0
 private void RenderFromLiquidExpression(IncludeTag includeTag, ITemplateContext templateContext, String virtualFileName,
                                         Option <ILiquidValue> forExpressionOption, LiquidAST snippetAst)
 {
     ValueCaster.Cast <ILiquidValue, LiquidCollection>(forExpressionOption.Value)
     .WhenError(AddRenderingErrorToResult)
     .WhenSuccess(result =>
     {
         foreach (Option <ILiquidValue> val in (LiquidCollection)result.Value)
         {
             var val1 = val;
             RenderBlock(includeTag, templateContext, snippetAst, localBlockScope => localBlockScope.DefineLocalVariable(virtualFileName, val1));
         }
     });
 }