TODO: Update summary.
Esempio n. 1
0
        public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model)
        {
            var localModel = GetLocalModel(documentHost, statement, model);

            //Assert that we're looping over something
            IEnumerable loop = localModel as IEnumerable;
            if (loop == null)
            {
                throw new InvalidCastException("model is not IEnumerable");
            }

            //create a local copy
            IList<object> items = ToList(loop);

            //create locals object to handle local values to the method
            Locals locals = new Locals(documentHost);

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];

                foreach (var child in statement.Children)
                {
                    var renderer = rendererFactory.GetRenderer(child.Name);
                    locals.Push(IteratorItem(i, items));

                    renderer.Render(writer, rendererFactory, child, documentHost, item);

                    locals.Pop();
                }
            }
        }
Esempio n. 2
0
        public override void RenderChildren(IParrotWriter writer, Nodes.Statement statement, IRendererFactory rendererFactory, IDictionary<string, object> documentHost, object model, string defaultTag = null)
        {
            if (string.IsNullOrEmpty(defaultTag))
            {
                defaultTag = DefaultChildTag;
            }

            //get model from parameter
            //required - do not remove
            if (statement.Parameters != null && statement.Parameters.Count == 1)
            {
                var localModel = GetLocalModel(documentHost, statement, model);

                if (localModel is IEnumerable)
                {
                    //create locals object to handle local values to the method
                    Locals locals = new Locals(documentHost);

                    IList<object> items = ToList(model as IEnumerable);
                    for (int i = 0; i < items.Count; i++)
                    {
                        var localItem = items[i];
                        locals.Push(IteratorItem(i, items));

                        base.RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, localItem);

                        locals.Pop();
                    }
                }
            }
            else
            {
                base.RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, model);
            }
        }