public void Render(IncludeTag includeTag, ITemplateContext templateContext) { if (templateContext.FileSystem == null) { AddRenderingErrorToResult(new LiquidError { Message = " ERROR: FileSystem is not defined" }); return; } String virtualFileName = null; LiquidExpressionEvaluator.Eval(includeTag.VirtualFileExpression, templateContext) .WhenError(AddRenderingErrorToResult) .WhenSuccess(result => { virtualFileName = ValueCaster.RenderAsString(result); }); if (virtualFileName == null) { return; } //virtualFileName = ValueCaster.RenderAsString(virtualFilenameVar.SuccessResult.Value); String snippet = templateContext.FileSystem.Include(templateContext, virtualFileName); templateContext.SymbolTableStack.DefineLocalRegistry(LOCALREGISTRY_FILE_KEY, virtualFileName); RenderSnippet(includeTag, templateContext, snippet, virtualFileName); }
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); }
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); }
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); }
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)); } }); }
/// <summary> /// 分析标签 /// </summary> /// <param name="parser">TemplateParser</param> /// <param name="tc">Token集合</param> /// <returns></returns> public Tag Parse(TemplateParser parser, TokenCollection tc) { if (Common.ParserHelpers.IsEqual(tc.First.Text, Field.KEY_INCLUDE)) { if (tc.Count > 2 && (tc[1].TokenKind == TokenKind.LeftParentheses) && tc.Last.TokenKind == TokenKind.RightParentheses) { IncludeTag tag = new IncludeTag(); tag.Path = parser.Read(new TokenCollection(tc, 2, tc.Count - 2)); return(tag); } } return(null); }
private void RenderSnippet(IncludeTag includeTag, ITemplateContext templateContext, String snippet, String virtualFileName) { var snippetAstTry = CreateAstFromSnippet(templateContext, snippet, virtualFileName); if (snippetAstTry.IsLeft) { foreach (var err in snippetAstTry.Left) { AddParsingErrorToResult(err); } return; } var snippetAst = snippetAstTry.Right; //zzz if (includeTag.ForExpression != null) { LiquidExpressionEvaluator.Eval(includeTag.ForExpression, templateContext) .WhenError(AddRenderingErrorToResult) .WhenSuccess(result => { if (result.Value is LiquidHash) { // it seems to render as a single element if it's a dictionary. RenderFromLiquidHash(includeTag, templateContext, virtualFileName, snippetAst); } else { RenderFromLiquidExpression(includeTag, templateContext, virtualFileName, result, snippetAst); } }); } else { RenderIncludeBlock(includeTag, templateContext, virtualFileName, snippetAst); } }
public void Visit(IncludeTag includeTag) { _result += includeTag.ToString(); }
public void Visit(IncludeTag includeTag) { var includeRenderer = new IncludeRenderer(this); includeRenderer.Render(includeTag, _templateContext); }