Represents a set of tags used to identify tokens
コード例 #1
0
ファイル: Writer.cs プロジェクト: StubbleOrg/Stubble
        /// <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;
        }
コード例 #2
0
ファイル: Writer.cs プロジェクト: StubbleOrg/Stubble
 /// <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;
 }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
ファイル: StubbleRenderer.cs プロジェクト: StubbleOrg/Stubble
 /// <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);
 }
コード例 #6
0
ファイル: StubbleRenderer.cs プロジェクト: StubbleOrg/Stubble
 /// <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);
 }