Enter() public method

public Enter ( Nustache.Core.Section section ) : void
section Nustache.Core.Section
return void
コード例 #1
0
ファイル: VariableReference.cs プロジェクト: unarist/Nustache
        public override void Render(RenderContext context)
        {
            var value = context.GetValue(_path);

            var lambda = CheckValueIsDelegateOrLambda(value);

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

                lambdaResult = _escaped
                    ? Encoders.HtmlEncode(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
                    ? Encoders.HtmlEncode(value.ToString())
                    : value.ToString());
            }
        }
コード例 #2
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
                    ? Encoders.HtmlEncode(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
                    ? Encoders.HtmlEncode(value.ToString())
                    : value.ToString());
            }
        }
コード例 #3
0
ファイル: Block.cs プロジェクト: reicheltp/Nustache
        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();
            }
        }
コード例 #4
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();
            }
        }