/// <summary> /// Parses a template with the given tags, looks up the template in the /// template token cache and returns cached version if possible. /// </summary> /// <param name="template">The template to parse</param> /// <param name="tags">The tags to parse the template with</param> /// <returns>A list of tokens parsed from the template</returns> public IList<ParserOutput> Parse(string template, Tags tags) { IList<ParserOutput> tokens; var success = Cache.TryGetValue(template, out tokens); if (!success) { tokens = Cache[template] = Parser.ParseTemplate(template, tags); } return tokens; }
/// <summary> /// Takes a template, context, partials and tags and renders the template /// </summary> /// <param name="template">The template to parse and render</param> /// <param name="context">The context object to use to render</param> /// <param name="partials">The partials available to the template</param> /// <param name="tags">The tags to initalise the parser with</param> /// <returns>The template rendered with the passed context object</returns> public string Render(string template, Context context, IDictionary<string, string> partials, Tags tags) { var tokens = Parse(template, tags); var renderResult = RenderTokens(tokens, context, partials, template); ResetCurrentDepth(); return renderResult; }
/// <summary> /// Parses and caches the given template in the writer and returns the list /// of tokens it contains. Doing this ahead of time avoids the need to parse /// templates on the fly as they are rendered. /// /// If you don't need the result <see cref="CacheTemplate(string,Tags)"/> /// </summary> /// <param name="template">The mustache teplate to parse</param> /// <param name="tags">The set of tags to use for parsing</param> /// <returns>Returns a list of tokens</returns> public static IList<ParserOutput> Parse(string template, Tags tags) { return (List<ParserOutput>)Instance.Parse(template, tags); }
/// <summary> /// Parses a template with given tags and adds the result to the writer cache. /// </summary> /// <param name="template">The mustache teplate to parse</param> /// <param name="tags">The set of tags to use for parsing</param> public static void CacheTemplate(string template, Tags tags) { Instance.CacheTemplate(template, tags); }
/// <summary> /// Parses a template with given tags and adds the result to the writer cache. /// </summary> /// <param name="template">The mustache teplate to parse</param> /// <param name="tags">The set of tags to use for parsing</param> public void CacheTemplate(string template, Tags tags) { Parse(template, tags); }
/// <summary> /// Parses and caches the given template in the writer and returns the list /// of tokens it contains. Doing this ahead of time avoids the need to parse /// templates on the fly as they are rendered. /// /// If you don't need the result <see cref="CacheTemplate(string,Tags)"/> /// </summary> /// <param name="template">The mustache teplate to parse</param> /// <param name="tags">The set of tags to use for parsing</param> /// <returns>Returns a list of tokens</returns> public IList<ParserOutput> Parse(string template, Tags tags) { var loadedTemplate = Registry.TemplateLoader.Load(template); return Writer.Parse(loadedTemplate, tags); }