Esempio n. 1
0
 protected void RenderAll(List <object> list, Context context, IndentationTextWriter result)
 {
     list.ForEach(token =>
     {
         try
         {
             if (token is IRenderable)
             {
                 ((IRenderable)token).Render(context, result);
             }
             else
             {
                 result.Write(token.ToString());
             }
         }
         catch (Exception ex)
         {
             if (ex.InnerException is LiquidException)
             {
                 ex = ex.InnerException;
             }
             result.Write(context.HandleError(ex));
         }
     });
 }
Esempio n. 2
0
        public void Render(Context context, IndentationTextWriter result)
        {
            object output = RenderInternal(context);

            if (output != null)
            {
                var transformer = Template.GetValueTypeTransformer(output.GetType());

                if (transformer != null)
                {
                    output = transformer(output);
                }

                string outputString;
                if (output is IEnumerable)
#if NET35
                { outputString = string.Join(string.Empty, ((IEnumerable)output).Cast <object>().Select(o => o.ToString()).ToArray()); }
#else
                { outputString = string.Join(string.Empty, ((IEnumerable)output).Cast <object>()); }
#endif
                else if (output is bool)
                {
                    outputString = output.ToString().ToLower();
                }
                else
                {
                    outputString = output.ToString();
                }
                result.Write(outputString);
            }
Esempio n. 3
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(IndentationTextWriter 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. 4
0
 /// <summary>
 /// Primarily intended for testing.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 internal string Render(Context context)
 {
     using (var result = IndentationTextWriter.Create())
     {
         Render(context, result);
         return(result.ToString());
     }
 }
Esempio n. 5
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 (var writer = IndentationTextWriter.Create())
     {
         Render(writer, parameters);
         return(writer.ToString());
     }
 }
Esempio n. 6
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.
            var streamWriter = IndentationTextWriter.Create(new StreamWriter(stream));

            RenderInternal(streamWriter, parameters);
            streamWriter.Flush();
        }
        public static IndentationTextWriter Create(TextWriter Writer = null, string IndentTab = null)
        {
            IndentationTextWriter Result = null;

            if (Writer == null)
            {
                Writer = new StringWriter();
            }

            if (IndentTab == null)
            {
                IndentTab = " ".Replicate(AppExec.GetConfiguration <int>("FileGeneration", "IndentSize", 4));
            }

            Result = new IndentationTextWriter(Writer, IndentTab);
            Result.IndentationDepth = DotLiquid.Tags.Inject.RecursionLevel;

            return(Result);
        }
Esempio n. 8
0
 public virtual void Render(Context context, IndentationTextWriter result)
 {
 }
Esempio n. 9
0
 public override void Render(Context context, IndentationTextWriter result)
 {
     RenderAll(NodeList, context, result);
 }
Esempio n. 10
0
 /// <summary>
 /// Renders the template into the specified StreamWriter.
 /// </summary>
 /// <param name="result"></param>
 /// <param name="parameters"></param>
 public void Render(IndentationTextWriter result, RenderParameters parameters)
 {
     RenderInternal(result, parameters);
 }