Beispiel #1
0
        /// <summary>
        /// Finds the matching template from the data context, evaluates the data expression, then renders
        /// the template against the data.  The rendered document is inserted into the parent document.
        /// </summary>
        /// <param name="context">The data context used to find the named template and to evaluate the data expression</param>
        /// <returns>The rendered child document to be inserted into the parent document</returns>
        public ConsoleString Evaluate(DocumentRendererContext context)
        {
            DocumentTemplateInfo target = context.DocumentRenderer.GetTemplate(this.IdToken);
            var eval = context.EvaluateExpression(this.EvalToken.Value);

            return(context.DocumentRenderer.Render(target.Value, eval, target.SourceLocation));
        }
        /// <summary>
        /// Register a named tamplate that can be accessed by other templates
        /// </summary>
        /// <param name="name">The unique name of the template</param>
        /// <param name="info">The template info</param>
        public void RegisterTemplate(string name, DocumentTemplateInfo info)
        {
            if (namedTemplates.ContainsKey(name))
            {
                throw new ArgumentException("There is already a template named '" + name + "'");
            }

            namedTemplates.Add(name, info);
        }
        /// <summary>
        /// Register a named tamplate that can be accessed by other templates
        /// </summary>
        /// <param name="name">The unique name of the template</param>
        /// <param name="info">The template info</param>
        public void RegisterTemplate(string name, DocumentTemplateInfo info)
        {
            if(namedTemplates.ContainsKey(name))
            {
                throw new ArgumentException("There is already a template named '" + name + "'");
            }

            namedTemplates.Add(name, info);
        }
 /// <summary>
 /// Renders a document from a template, using a plain old .NET object as a data source.
 /// </summary>
 /// <param name="template">The template to use</param>
 /// <param name="data">The data source to use for template replacements</param>
 /// <returns></returns>
 public ConsoleString Render(DocumentTemplateInfo template, object data)
 {
     return Render(template.Value, data, template.SourceLocation);
 }
 /// <summary>
 /// Renders a document from a template, using a plain old .NET object as a data source.
 /// </summary>
 /// <param name="template">The template to use</param>
 /// <param name="data">The data source to use for template replacements</param>
 /// <returns></returns>
 public ConsoleString Render(DocumentTemplateInfo template, object data)
 {
     return(Render(template.Value, data, template.SourceLocation));
 }