Esempio n. 1
0
        /// <summary>
        /// Render takes a hash with local variables.
        ///
        /// if you use the same filters over and over again consider registering them globally
        /// with <tt>Template.register_filter</tt>
        ///
        /// Following options can be passed:
        ///
        /// * <tt>filters</tt> : array with local filters
        /// * <tt>registers</tt> : hash with register variables. Those can be accessed from
        /// filters and tags and might be useful to integrate liquid more with its host application
        /// </summary>
        private void RenderInternal(TextWriter result, RenderParameters parameters)
        {
            if (Root == null)
            {
                return;
            }

            Context            context;
            Hash               registers;
            IEnumerable <Type> filters;

            parameters.Evaluate(this, out context, out registers, out filters);

            if (registers != null)
            {
                Registers.Merge(registers);
            }

            if (filters != null)
            {
                context.AddFilters(filters);
            }

            try
            {
                // Render the nodelist.
                Root.Render(context, result);
            }
            finally
            {
                _errors = context.Errors;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Renders the template using the specified parameters and returns a string containing the result.
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public string Render(RenderParameters parameters)
 {
     using (TextWriter writer = new StringWriter())
     {
         Render(writer, parameters);
         return(writer.ToString());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Renders the template into the specified Stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="parameters"></param>
        public void Render(Stream stream, RenderParameters parameters)
        {
            // Can't dispose this new StreamWriter, because it would close the
            // passed-in stream, which isn't up to us.
            StreamWriter streamWriter = new StreamWriter(stream);

            RenderInternal(streamWriter, parameters);
            streamWriter.Flush();
        }
Esempio n. 4
0
 /// <summary>
 /// Renders the template into the specified StreamWriter.
 /// </summary>
 /// <param name="result"></param>
 /// <param name="parameters"></param>
 public void Render(TextWriter result, RenderParameters parameters)
 {
     RenderInternal(result, parameters);
 }