string RenderInverted(Token token, MustacheContext ctx) { var value = ctx.Lookup(token.Name); if (value == null && StrictMode) { throw new MustacheException(string.Format("lookup failed name:'{0}' around:\n...{1}...\n", token.Name, token.SurroundingTemplate)); } if (value.ShouldNotRender()) { return(RenderTokens(ctx, token.Children)); } return(string.Empty); }
string RenderName(Token token, MustacheContext ctx, bool escape) { var value = ctx.Lookup(token.Name); if (value == null && StrictMode) { throw new MustacheException(string.Format("lookup failed name:'{0}' around:\n...{1}...\n", token.Name, token.SurroundingTemplate)); } if (value == null) { return(string.Empty); } if (value.IsLambda()) { var template = value.InvokeNameLambda() as string; var tokens = new MustacheParser().Parse(template, Delimiter.Default()); value = RenderTokens(ctx, tokens); // Recheck for null if (value == null) { return(string.Empty); } } var s = value.ToString(); if (s == "{ }") { return(string.Empty); } if (escape) { return(System.Web.HttpUtility.HtmlEncode(s)); } return(s); }
string RenderSection(Token token, MustacheContext ctx) { var value = ctx.Lookup(token.Name); if (value == null && StrictMode) { throw new MustacheException(string.Format("lookup failed name:'{0}' around:\n...{1}...\n", token.Name, token.SurroundingTemplate)); } if (value.ShouldNotRender()) { return(string.Empty); } if (value.IsLambda()) { var template = value.InvokeSectionLambda(token.SectionTemplate) as string; if (!string.IsNullOrEmpty(template)) { if (!Cache.ContainsKey(template)) { // When Lambdas are used as the data value for Section tag, // the returned value MUST be rendered against the current delimiters. Cache[template] = new MustacheParser().Parse(template, token.CurrentDelimiter); } return(RenderTokens(ctx, Cache[template])); } } if (value is ICollection) { var sb = new StringBuilder(); foreach (object item in value as ICollection) { sb.Append(RenderTokens(new MustacheContext(item, ctx), token.Children)); } return(sb.ToString()); } return(RenderTokens(new MustacheContext(value, ctx), token.Children)); }