Exemplo n.º 1
1
        public override void Render(RenderContext context)
        {
            object value = context.GetValue(_name);

            if (value != null)
            {
                context.Write(value.ToString());
            }
        }
Exemplo n.º 2
0
 public override void Render(RenderContext context)
 {
     foreach (var part in _parts)
     {
         part.Render(context);
     }
 }
Exemplo n.º 3
0
 public static void EachHelper(RenderContext context, IList<object> arguments, IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
 {
     foreach (var item in (IEnumerable) arguments[0])
     {
         fn(item);
     }
 }
Exemplo n.º 4
0
 public void RenderParts(RenderContext context)
 {
     foreach (var part in _parts)
     {
         part.Render(context);
     }
 }
Exemplo n.º 5
0
 public override void Render(RenderContext context)
 {
     if (context.GetValues(Name).Count() > 0)
     {
         base.Render(context);
     }
 }
 /// <summary>
 /// if_eq this compare=that
 /// </summary>
 internal static void IfEqHelper(RenderContext ctx, IList<object> args, IDictionary<string, object> options,
                                 RenderBlock fn, RenderBlock inverse)
 {
     if (Object.Equals(args[0], options["compare"]))
         fn(args[0]);
     else
         inverse(args[0]);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Renders the template.
        /// </summary>
        /// <param name="data">The data to use to render the template.</param>
        /// <param name="writer">The object to write the output to.</param>
        /// <param name="templateLocator">The delegate to use to locate templates for inclusion.</param>
        /// <remarks>
        /// The <paramref name="writer" /> is flushed, but not closed or disposed.
        /// </remarks>
        public void Render(object data, TextWriter writer, TemplateLocator templateLocator)
        {
            var context = new RenderContext(this, data, writer, templateLocator);

            Render(context);

            writer.Flush();
        }
Exemplo n.º 8
0
        public CompileContext(Section section, Type targetType, Expression dataParam, TemplateLocator templateLocator)
        {
            this.targetType = targetType;
            this.renderContext = new RenderContext(section, null, null, templateLocator);
            this.templateLocator = templateLocator;

            _targetObjectStack.Push(dataParam);
            _sectionStack.Push(section);
        }
Exemplo n.º 9
0
        public void Render(object data, TextWriter writer, TemplateLocator templateLocator,
            IValueProviderCollection valueProviders)
        {
            var context = new RenderContext(this, data, writer, templateLocator, valueProviders);

            Render(context);

            writer.Flush();
        }
Exemplo n.º 10
0
        public void Render(object data, TextWriter writer, TemplateLocator templateLocator, RenderContextBehaviour renderContextBehaviour)
        {
            var context = new RenderContext(this, data, writer, templateLocator, renderContextBehaviour);
            context.ActiveStartDelimiter = StartDelimiter;
            context.ActiveEndDelimiter = EndDelimiter;

            Render(context);

            writer.Flush();
        }
Exemplo n.º 11
0
 public RenderContext(RenderContext baseContext, TextWriter writer)
 {
     _sectionStack = baseContext._sectionStack;
     _dataStack = baseContext._dataStack;
     _writer = writer;
     _templateLocator = baseContext._templateLocator;
     _renderContextBehaviour = baseContext._renderContextBehaviour;
     _includeLevel = baseContext._includeLevel;
     _indent = baseContext._indent;
     _lineEnded = baseContext._lineEnded;
 }
Exemplo n.º 12
0
        public override void Render(RenderContext context)
        {
            object value = context.GetValue(_path);

            if (value != null)
            {
                context.Write(_escaped
                    ? Encoders.HtmlEncode(value.ToString())
                    : value.ToString());
            }
        }
Exemplo n.º 13
0
        public override void Render(RenderContext context)
        {
            object value = context.GetValue(_name);

            if (value != null)
            {
                context.Write(_escaped
                  ? HttpUtility.HtmlEncode( value.ToString())
                  : value.ToString());
            }
        }
Exemplo n.º 14
0
        public static void IfHelper(RenderContext context, IList<object> arguments, IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
        {
            var value = arguments[0];

            if (context.IsTruthy(value))
            {
                fn(null);
            }
            else
            {
                inverse(null);
            }
        }
Exemplo n.º 15
0
        public static void Parse(RenderContext ctx, string path, out string name, out IList<object> arguments, out IDictionary<string, object> options)
        {
            name = path;
            arguments = null;
            options = null;

            if (path.Contains(" "))
            {
                var splits = path.Split();
                name = splits[0];
                ParseArguments(ctx, splits, out arguments);
                ParseOptions(ctx, splits, out options);
            }
        }
Exemplo n.º 16
0
 public static void ReplaceHelper(
     RenderContext ctx,
     IList<object> args,
     IDictionary<string, object> options,
     RenderBlock fn,
     RenderBlock inverse)
 {
     try
     {
         ctx.Write(ReplaceValues(args));
     }
     catch (Exception exception)
     {
         ctx.Write(exception.ToString());
     }
 }
Exemplo n.º 17
0
 public static void FormatHelper(
     RenderContext ctx,
     IList<object> args,
     IDictionary<string, object> options,
     RenderBlock fn,
     RenderBlock inverse)
 {
     try
     {
         ctx.Write(FormatValue(args.FirstArg(), args.SecondStringArg()));
     }
     catch (Exception exception)
     {
         ctx.Write(exception.ToString());
     }
 }
Exemplo n.º 18
0
        public override void Render(RenderContext context)
        {
            object value = context.GetValue(_path);

            if (value != null)
            {
                context.Write(_escaped
                    ? Encoders.HtmlEncode(value.ToString())
                    : ReplaceLineBreaksAndEncode(value.ToString()));
                return;
            }

            if (context.CurrentOptions.PreserveUndefinedVariables && !context.PathExists(_path))
            {
                context.Write(Source());
            }
        }
Exemplo n.º 19
0
        public override void Render(RenderContext context)
        {
            var value = context.GetValue(_path);

            var helper = value as HelperProxy;

            if (helper != null)
            {
                helper(data => { }, data => { });
            }
            else if (value != null)
            {
                context.Write(_escaped
                    ? Encoders.HtmlEncode(value.ToString())
                    : value.ToString());
            }
        }
        /// <summary>
        /// if_eq_zero this
        /// </summary>
        internal static void IfEqZeroHelper(RenderContext ctx, IList<object> args, IDictionary<string, object> options,
                                 RenderBlock fn, RenderBlock inverse)
        {
            bool isZero = false;
            double decArg = 0;
            if (args[0] != null && Double.TryParse(args[0].ToString(), out decArg))
            {
                isZero = decArg.Equals(0D);
            }

            if (isZero)
            {
                fn(args[0]);
            }
            else
            {
                inverse(args[0]);
            }
        }
Exemplo n.º 21
0
        public override void Render(RenderContext context)
        {
            var value = context.GetValue(_path);

            var lambda = CheckValueIsDelegateOrLambda(value);
            if(lambda != null)
            {
                var lambdaResult = lambda().ToString();

                lambdaResult = _escaped
                    ? context.HtmlEncoder(lambdaResult.ToString())
                    : lambdaResult.ToString();

                using (System.IO.TextReader sr = new System.IO.StringReader(lambdaResult))
                {
                    Template template = new Template();
                    template.StartDelimiter = "{{";
                    template.EndDelimiter = "}}";

                    template.Load(sr);
                    context.Enter(template);
                    template.Render(context);
                    context.Exit();

                    return;
                }
            }

            var helper = value as HelperProxy;

            if (helper != null)
            {
                helper(data => { }, data => { });
            }
            else if (value != null)
            {
                context.Write(_escaped
                    ? context.HtmlEncoder(value.ToString())
                    : value.ToString());
            }
        }
Exemplo n.º 22
0
 public override void Render(RenderContext context)
 {
     RenderParts(context);
 }
Exemplo n.º 23
0
 public override object GetValue(RenderContext renderContext)
 {
     return _target[_key];
 }
Exemplo n.º 24
0
 public override object GetValue(RenderContext renderContext)
 {
     return _fieldInfo.GetValue(_target);
 }
Exemplo n.º 25
0
 public override void Render(RenderContext context)
 {
     context.Include(_name, _indent);
 }
Exemplo n.º 26
0
 public abstract void Render(RenderContext context);
Exemplo n.º 27
0
        public override void Render(RenderContext context)
        {
            var value = context.GetValue(Name);

            var lambda = CheckValueIsDelegateOrLambda(value);

            if (lambda != null)
            {
                var lambdaResult = lambda(InnerSource()).ToString();
                using(TextReader sr = new StringReader(lambdaResult))
                {
                    var template = new Template();
                    template.StartDelimiter = context.ActiveStartDelimiter;
                    template.EndDelimiter = context.ActiveEndDelimiter;

                    template.Load(sr);
                    context.Enter(template);
                    template.Render(context);
                    context.Exit();
                }

                return;
            }

            var helper = value as HelperProxy;

            if (helper != null)
            {
                helper(data =>
                {
                    context.Enter(this);
                    context.Push(data);

                    RenderParts(context);

                    context.Pop();
                    context.Exit();
                }, data =>
                {
                    if (Inverse != null)
                    {
                        context.Enter(Inverse);
                        context.Push(data);

                        Inverse.RenderParts(context);

                        context.Pop();
                        context.Exit();
                    }
                });

                return;
            }

            foreach (var item in context.GetValues(Name))
            {
                context.Enter(this);
                context.Push(item);

                base.Render(context);

                context.Pop();
                context.Exit();
            }
        }
Exemplo n.º 28
0
 public static void UnlessHelper(RenderContext context, IList <object> arguments, IDictionary <string, object> options, RenderBlock fn, RenderBlock inverse)
 {
     IfHelper(context, arguments, options, inverse, fn);
 }
Exemplo n.º 29
0
 public static void WithHelper(RenderContext context, IList <object> arguments, IDictionary <string, object> options, RenderBlock fn, RenderBlock inverse)
 {
     fn(arguments[0]);
 }
Exemplo n.º 30
0
 public override void Render(RenderContext context)
 {
     context.Write(_text);
 }
 /// <summary>
 /// unless_lt this compare=that
 /// </summary>
 internal static void UnlessLtHelper(RenderContext ctx, IList<object> args, IDictionary<string, object> options,
                                     RenderBlock fn, RenderBlock inverse)
 {
     if (Compare(args[0], options["compare"]) < 0)
         inverse(args[0]);
     else
         fn(args[0]);
 }
Exemplo n.º 32
0
 public override void Render(RenderContext context)
 {
 }
Exemplo n.º 33
0
 public abstract void Render(RenderContext context);