Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RendererSettings"/> class.
 /// </summary>
 /// <param name="valueGetters">The value getters</param>
 /// <param name="truthyChecks">The truthy checks</param>
 /// <param name="templateLoader">The template loader</param>
 /// <param name="partialLoader">The partial loader</param>
 /// <param name="maxRecursionDepth">The max recursion depth</param>
 /// <param name="renderSettings">The render settings</param>
 /// <param name="enumerationConverters">The enumeration converters</param>
 /// <param name="ignoreCaseOnLookup">Should case be ignored on lookup</param>
 /// <param name="parser">The mustache parser to use</param>
 /// <param name="rendererPipeline">The renderer pipeline to use</param>
 /// <param name="defaultTags">The default tags to use during parsing</param>
 /// <param name="parserPipeline">The parser pipeline to use during parsing</param>
 public RendererSettings(
     Dictionary <Type, ValueGetterDelegate> valueGetters,
     Dictionary <Type, List <Func <object, bool> > > truthyChecks,
     IStubbleLoader templateLoader,
     IStubbleLoader partialLoader,
     uint maxRecursionDepth,
     RenderSettings renderSettings,
     Dictionary <Type, Func <object, IEnumerable> > enumerationConverters,
     bool ignoreCaseOnLookup,
     IMustacheParser parser,
     TokenRendererPipeline <Context> rendererPipeline,
     Classes.Tags defaultTags,
     ParserPipeline parserPipeline)
     : base(
         templateLoader,
         partialLoader,
         maxRecursionDepth,
         ignoreCaseOnLookup,
         parser,
         defaultTags,
         parserPipeline)
 {
     ValueGetters          = valueGetters.ToImmutableDictionary();
     TruthyChecks          = truthyChecks.ToImmutableDictionary(k => k.Key, v => v.Value.ToImmutableArray());
     RenderSettings        = renderSettings;
     EnumerationConverters = enumerationConverters.ToImmutableDictionary();
     RendererPipeline      = rendererPipeline;
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RendererSettings"/> class.
 /// </summary>
 /// <param name="valueGetters">The value getters</param>
 /// <param name="truthyChecks">The truthy checks</param>
 /// <param name="templateLoader">The template loader</param>
 /// <param name="partialLoader">The partial loader</param>
 /// <param name="maxRecursionDepth">The max recursion depth</param>
 /// <param name="renderSettings">The render settings</param>
 /// <param name="enumerationConverters">The enumeration converters</param>
 /// <param name="ignoreCaseOnLookup">Should case be ignored on lookup</param>
 /// <param name="parser">The mustache parser to use</param>
 /// <param name="rendererPipeline">The renderer pipeline to use</param>
 /// <param name="defaultTags">The default tags to use during parsing</param>
 /// <param name="parserPipeline">The parser pipeline to use during parsing</param>
 public RendererSettings(
     Dictionary <Type, Func <object, string, object> > valueGetters,
     IEnumerable <Func <object, bool?> > truthyChecks,
     IStubbleLoader templateLoader,
     IStubbleLoader partialLoader,
     uint maxRecursionDepth,
     RenderSettings renderSettings,
     Dictionary <Type, Func <object, IEnumerable> > enumerationConverters,
     bool ignoreCaseOnLookup,
     IMustacheParser parser,
     TokenRendererPipeline rendererPipeline,
     Classes.Tags defaultTags,
     ParserPipeline parserPipeline)
 {
     ValueGetters          = valueGetters.ToImmutableDictionary();
     TruthyChecks          = truthyChecks.ToImmutableArray();
     TemplateLoader        = templateLoader;
     PartialTemplateLoader = partialLoader;
     MaxRecursionDepth     = maxRecursionDepth;
     RenderSettings        = renderSettings;
     EnumerationConverters = enumerationConverters.ToImmutableDictionary();
     IgnoreCaseOnKeyLookup = ignoreCaseOnLookup;
     Parser           = parser;
     RendererPipeline = rendererPipeline;
     DefaultTags      = defaultTags;
     ParserPipeline   = parserPipeline;
 }
Пример #3
0
        /// <summary>
        /// Parse a template and return a <see cref="MustacheTemplate"/>
        /// </summary>
        /// <param name="text">The text to be parsed</param>
        /// <param name="startingTags">The starting tag description</param>
        /// <param name="lineIndent">The default line indent for the template</param>
        /// <param name="pipeline">The pipeline to use for parsing</param>
        /// <returns>The string converted to Tags</returns>
        public static MustacheTemplate Parse(string text, Classes.Tags startingTags = null, int lineIndent = 0, ParserPipeline pipeline = null)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            startingTags = startingTags ?? new Classes.Tags("{{", "}}");
            pipeline     = pipeline ?? new ParserPipelineBuilder().Build();

            var mustacheParser = new MustacheParser(text, startingTags, lineIndent, pipeline);

            return(mustacheParser.Parse());
        }
Пример #4
0
        private MustacheParser(string text, Classes.Tags startingTags, int lineIndent, ParserPipeline pipeline)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            content = new StringSlice(text);

            processor = new Processor(pipeline.InlineParsers, pipeline.BlockParsers)
            {
                CurrentTags            = startingTags,
                LineIndent             = lineIndent,
                DefaultLineIndent      = lineIndent,
                DefaultLineIndentSlice = lineIndent > 0 ? new StringSlice(new string(' ', lineIndent)) : StringSlice.Empty
            };
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseSettings"/> class.
 /// </summary>
 /// <param name="templateLoader">The template loader</param>
 /// <param name="partialLoader">The partial loader</param>
 /// <param name="maxRecursionDepth">The max recursion depth</param>
 /// <param name="ignoreCaseOnLookup">Should case be ignored on lookup</param>
 /// <param name="parser">The mustache parser to use</param>
 /// <param name="defaultTags">The default tags to use during parsing</param>
 /// <param name="parserPipeline">The parser pipeline to use during parsing</param>
 public BaseSettings(
     IStubbleLoader templateLoader,
     IStubbleLoader partialLoader,
     uint maxRecursionDepth,
     bool ignoreCaseOnLookup,
     IMustacheParser parser,
     Classes.Tags defaultTags,
     ParserPipeline parserPipeline)
 {
     TemplateLoader        = templateLoader;
     PartialTemplateLoader = partialLoader;
     MaxRecursionDepth     = maxRecursionDepth;
     IgnoreCaseOnKeyLookup = ignoreCaseOnLookup;
     Parser         = parser;
     DefaultTags    = defaultTags;
     ParserPipeline = parserPipeline;
 }
Пример #6
0
        private Func <string, Task <string> > RenderInContextAsync(Context context, Classes.Tags tags)
        {
            return(async(str) =>
            {
                if (!str.Contains(tags.StartTag))
                {
                    return str;
                }

                using var writer = new StringWriter();
                var blockRenderer = new StringRender(writer, context.RendererSettings.RendererPipeline);
                var parsed = context.RendererSettings.Parser.Parse(str, tags);

                await blockRenderer.RenderAsync(parsed, context).ConfigureAwait(false);

                return writer.ToString();
            });
        }
Пример #7
0
        private Func <string, string> RenderInContext(Context context, Classes.Tags tags)
        {
            return((str) =>
            {
                if (!str.Contains(tags.StartTag))
                {
                    return str;
                }

                using var writer = new StringWriter();
                var blockRenderer = new StringRender(writer, context.RendererSettings.RendererPipeline);
                var parsed = context.RendererSettings.Parser.Parse(str, tags);

                blockRenderer.Render(parsed, context);

                return writer.ToString();
            });
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseSettings"/> class.
 /// </summary>
 /// <param name="templateLoader">The template loader</param>
 /// <param name="partialLoader">The partial loader</param>
 /// <param name="maxRecursionDepth">The max recursion depth</param>
 /// <param name="ignoreCaseOnLookup">Should case be ignored on lookup</param>
 /// <param name="parser">The mustache parser to use</param>
 /// <param name="defaultTags">The default tags to use during parsing</param>
 /// <param name="parserPipeline">The parser pipeline to use during parsing</param>
 /// <param name="sectionBlacklistTypes">The blacklisted section types</param>
 public BaseSettings(
     IStubbleLoader templateLoader,
     IStubbleLoader partialLoader,
     uint maxRecursionDepth,
     bool ignoreCaseOnLookup,
     IMustacheParser parser,
     Classes.Tags defaultTags,
     ParserPipeline parserPipeline,
     HashSet <Type> sectionBlacklistTypes)
 {
     TemplateLoader        = templateLoader;
     PartialTemplateLoader = partialLoader;
     MaxRecursionDepth     = maxRecursionDepth;
     IgnoreCaseOnKeyLookup = ignoreCaseOnLookup;
     Parser                = parser;
     DefaultTags           = defaultTags;
     ParserPipeline        = parserPipeline;
     SectionBlacklistTypes = sectionBlacklistTypes.ToImmutableHashSet();
 }
Пример #9
0
 /// <summary>
 /// Sets the default tags to be used during parsing
 /// </summary>
 /// <param name="tags">The tags</param>
 /// <returns>The IRendererSettingsBuilder for chaining</returns>
 public TBuilder SetDefaultTags(Classes.Tags tags)
 {
     DefaultTags = tags;
     return((TBuilder)this);
 }
Пример #10
0
 /// <inheritdoc/>
 public MustacheTemplate Parse(string text, Classes.Tags startingTags = null, int lineIndent = 0, ParserPipeline pipeline = null)
 {
     return(MustacheParser.Parse(text, startingTags, lineIndent, pipeline));
 }
Пример #11
0
 /// <inheritdoc/>
 public RendererSettingsBuilder SetDefaultTags(Classes.Tags tags)
 {
     DefaultTags = tags;
     return(this);
 }