/// <summary>
        ///     Pushes the specified template writer helper onto the stack.
        /// </summary>
        /// <param name="bodyWriter">The template writer helper.</param>
        internal void PushBody(TemplateWriter bodyWriter)
        {
            if (bodyWriter == null)
            {
                throw new ArgumentNullException("bodyWriter");
            }

            _bodyWriters.Push(bodyWriter);
        }
        /// <summary>
        ///     Pushes the specified template writer helper onto the stack.
        /// </summary>
        /// <param name="bodyWriter">The template writer helper.</param>
        internal void PushBody(TemplateWriter bodyWriter)
        {
            if (bodyWriter == null)
                throw new ArgumentNullException("bodyWriter");

            _bodyWriters.Push(bodyWriter);
        }
Beispiel #3
0
 /// <summary>
 ///     Writes the specfied template helper result to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="helper">The template writer helper.</param>
 public virtual void WriteTo(TextWriter writer, TemplateWriter helper)
 {
     helper.WriteTo(writer);
 }
        /// <summary>
        ///     Runs the template and returns the result.
        /// </summary>
        /// <param name="context">The current execution context.</param>
        /// <returns>The merged result of the template.</returns>
        string ITemplate.Run(ExecuteContext context)
        {
            _context = context;

            var builder = new StringBuilder();
            using (var writer = new StringWriter(builder))
            {
                _context.CurrentWriter = writer;
                Execute();
                _context.CurrentWriter = null;
            }

            if (Layout != null)
            {
                // Get the layout template.
                var layout = ResolveLayout(Layout);

                // Push the current body instance onto the stack for later execution.
                var body = new TemplateWriter(tw => tw.Write(builder.ToString()));
                context.PushBody(body);

                return layout.Run(context);
            }

            return builder.ToString();
        }
 /// <summary>
 ///     Writes the specfied template helper result to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="helper">The template writer helper.</param>
 public virtual void WriteTo(TextWriter writer, TemplateWriter helper)
 {
     helper.WriteTo(writer);
 }
        /// <summary>
        ///     Writes the specified template helper result.
        /// </summary>
        /// <param name="helper">The template writer helper.</param>
        public virtual void Write(TemplateWriter helper)
        {
            if (helper == null)
                return;

            helper.WriteTo(_context.CurrentWriter);
        }