Provided when parsing a template and getting information about the embedded variables.
Ejemplo n.º 1
0
        /// <summary>
        /// Parse the template, and capture paths used in the template to determine a suitable structure for the required model.
        /// </summary>
        /// <param name="templateSource">The template content to parse.</param>
        /// <param name="options">Options for configuring/extending the parser.</param>
        /// <returns></returns>
        public static ExtendedParseInformation ParseWithModelInference(string templateSource, ParsingOptions options)
        {
            var tokensQueue   = GetTokensQueue(templateSource, options);
            var inferredModel = new InferredTemplateModel();

            var internalTemplate = Parse(tokensQueue, options, inferredModel);
            Func <IDictionary <String, object>, String> template = (model) =>
            {
                var retval  = new StringBuilder();
                var context = new ContextObject()
                {
                    Value = model,
                    Key   = ""
                };
                internalTemplate(retval, context);
                return(retval.ToString());
            };

            var result = new ExtendedParseInformation()
            {
                InferredModel  = inferredModel,
                ParsedTemplate = template
            };

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse the template, and capture paths used in the template to determine a suitable structure for the required model.
        /// </summary>
        /// <param name="templateSource">The template content to parse.</param>
        /// <param name="disableContentEscaping">In some cases, content should not be escaped (such as when rendering text bodies and subjects in emails).
        /// By default, we use content escaping, but this parameter allows it to be disabled.</param>
        /// <returns></returns>
        public static ExtendedParseInformation ParseWithModelInference(string templateSource, bool disableContentEscaping = false)
        {
            var tokens  = new Queue <TokenPair> (Tokenizer.Tokenize(templateSource));
            var options = new ParsingOptions {
                DisableContentSafety = disableContentEscaping
            };
            var inferredModel = new InferredTemplateModel();

            var internalTemplate = Parse(tokens, options, inferredModel);
            Func <IDictionary <String, object>, String> template = (model) =>
            {
                var retval  = new StringBuilder();
                var context = new ContextObject()
                {
                    Value = model,
                    Key   = ""
                };
                internalTemplate(retval, context);
                return(retval.ToString());
            };

            var result = new ExtendedParseInformation()
            {
                InferredModel  = inferredModel,
                ParsedTemplate = template
            };

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parse the template, and capture paths used in the template to determine a suitable structure for the required model.
        /// </summary>
        /// <param name="templateSource">The template content to parse.</param>
        /// <param name="disableContentEscaping">In some cases, content should not be escaped (such as when rendering text bodies and subjects in emails). 
        /// By default, we use content escaping, but this parameter allows it to be disabled.</param>
        /// <returns></returns>
        public static ExtendedParseInformation ParseWithModelInference(string templateSource, bool disableContentEscaping = false)
        {
            var tokens = new Queue<TokenPair>(Tokenizer.Tokenize(templateSource));
            var options = new ParsingOptions { DisableContentSafety = disableContentEscaping };
            var inferredModel = new InferredTemplateModel();

            var internalTemplate = Parse(tokens, options, inferredModel);
            Func<IDictionary<String, object>, String> template = (model) =>
            {
                var retval = new StringBuilder();
                var context = new ContextObject()
                {
                    Value = model,
                    Key = ""
                };
                internalTemplate(retval, context);
                return retval.ToString();
            };

            var result = new ExtendedParseInformation()
            {
                InferredModel = inferredModel,
                ParsedTemplate = template
            };

            return result;
        }