Ejemplo n.º 1
0
        public string Render(AbstractNode node, object model)
        {
            var modelValueProviderFactory = _host.DependencyResolver.Resolve<IModelValueProviderFactory>();

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var stringNode = node as StringLiteral;
            if (stringNode == null)
            {
                throw new InvalidCastException("node");
            }

            string result = "";
            foreach (var value in stringNode.Values)
            {
                result += GetModelValue(modelValueProviderFactory, model, value.Type, value.Data);
            }

            //return RendererHelpers.GetModelValue(model, stringNode.Parrot.Infrastructure.ValueType, stringNode)

            return result;
            //return stringNode.GetValue() as string;
        }
Ejemplo n.º 2
0
 public void AppendChildNode(AbstractNode node)
 {
     if (node == null)
     {
         return;
     }
     m_array.Add(node);
 }
Ejemplo n.º 3
0
        public string Render(AbstractNode node, object model)
        {
            dynamic localModel = model;

            Document document = new Document(_host)
            {
                Children = localModel.Children
            };

            return _host.DependencyResolver.Resolve<DocumentRenderer>().Render(document, localModel.Model);
        }
Ejemplo n.º 4
0
        public string Render(AbstractNode node, object documentHost)
        {
            if (documentHost != null)
            {
                var modelValueProviderFactory = _host.DependencyResolver.Resolve<IModelValueProviderFactory>();

                var value = modelValueProviderFactory.Get(documentHost.GetType()).GetValue(documentHost, Parrot.Infrastructure.ValueType.Property, (node as Statement).Name);

                return value.ToString();
            }
            return (node as Statement).Name;
        }
Ejemplo n.º 5
0
        public string Render(AbstractNode node, object model)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var stringNode = node as StringLiteralNode;
            if (stringNode == null)
            {
                throw new InvalidCastException("node");
            }

            return stringNode.GetValue() as string;
        }
Ejemplo n.º 6
0
        public string Render(AbstractNode node, object model)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var outputNode = node as OutputNode;
            if (outputNode == null)
            {
                throw new ArgumentNullException("node");
            }

            node.SetModel(model);
            return node.ToString();
        }
Ejemplo n.º 7
0
        public override string Render(AbstractNode node, object model)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var blockNode = node as BlockNode;
            if (blockNode == null)
            {
                throw new ArgumentException("node");
            }

            var tag = CreateTag(model, blockNode);

            return tag.ToString(TagRenderMode.SelfClosing);
        }
Ejemplo n.º 8
0
        public virtual string Render(AbstractNode node, object model)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var blockNode = node as Statement;
            if (blockNode == null)
            {
                throw new ArgumentException("node");
            }

            var tag = CreateTag(model, blockNode);

            return tag.ToString();
        }
Ejemplo n.º 9
0
        public string Render(AbstractNode node, object model)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var blockNode = node as BlockNode;

            //this tag can't have any children
            if (blockNode.Children.Any())
            {
                throw new Exception("Block can't have any children");
            }

            var localModel = model;

            TagBuilder tag = new TagBuilder("input");
            foreach (var attribute in blockNode.Attributes.Cast<AttributeNode>())
            {
                attribute.SetModel(localModel);

                if (attribute.Key == "class")
                {
                    tag.AddCssClass(attribute.GetValue());
                }
                else
                {
                    tag.MergeAttribute(attribute.Key, attribute.GetValue(), true);
                }
            }

            //check and see if there's a parameter and assign it to value
            if (blockNode.Parameters != null && blockNode.Parameters.Count == 1)
            {
                //grab only the first
                var parameter = blockNode.Parameters[0];
                string value = parameter.Value;
                tag.MergeAttribute("value", value, true);
            }

            return tag.ToString(TagRenderMode.SelfClosing);
        }
Ejemplo n.º 10
0
        public string Render(AbstractNode node, object model)
        {
            var modelValueProviderFactory = _host.DependencyResolver.Resolve<IModelValueProviderFactory>();

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var outputNode = node as RawOutput;
            if (outputNode == null)
            {
                throw new ArgumentNullException("node");
            }

            var value = modelValueProviderFactory.Get(model.GetType()).GetValue(model, Parrot.Infrastructure.ValueType.Property, outputNode.VariableName);

            return value.ToString();
        }
Ejemplo n.º 11
0
        public string Render(AbstractNode node, object documentHost)
        {
            var modelValueProviderFactory = _host.DependencyResolver.Resolve<IModelValueProviderFactory>();

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var outputNode = node as EncodedOutput;
            if (outputNode == null)
            {
                throw new ArgumentNullException("node");
            }

            var value = modelValueProviderFactory.Get(documentHost.GetType()).GetValue(documentHost, Parrot.Infrastructure.ValueType.Property, outputNode.VariableName);

            //html encode this!
            return System.Net.WebUtility.HtmlEncode(value.ToString());
        }
Ejemplo n.º 12
0
        public string Render(AbstractNode node, object model)
        {
            //assert we have a blocknode
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var docTypeNode = node as BlockNode;
            if (docTypeNode == null || !docTypeNode.BlockName.Equals("doctype", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidCastException("node was not a docType element");
            }

            var value = "html"; //default value of "html"

            var parameter = docTypeNode.Parameters != null ? docTypeNode.Parameters.FirstOrDefault() : null;
            if (parameter != null)
            {
                value = parameter.Value;
            }

            return string.Format("<!DOCTYPE {0}>", value);
        }
Ejemplo n.º 13
0
        public string Render(AbstractNode node, object model)
        {
            var modelValueProviderFactory = _host.DependencyResolver.Resolve<IModelValueProviderFactory>();

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var blockNode = node as Statement;

            //this tag can't have any children
            if (blockNode.Children.Any())
            {
                throw new Exception("Block can't have any children");
            }

            var localModel = model;

            TagBuilder tag = new TagBuilder("input");
            foreach (var attribute in blockNode.Attributes)
            {
                object attributeValue = model;
                if (attributeValue != null)
                {
                    attributeValue = modelValueProviderFactory.Get(model.GetType()).GetValue(model, attribute.ValueType, attribute.Value);
                }
                else
                {
                    attributeValue = modelValueProviderFactory.Get(typeof(object)).GetValue(model, attribute.ValueType, attribute.Value);
                }

                if (attribute.Key == "class")
                {
                    tag.AddCssClass((string)attributeValue);
                }
                else
                {

                    Func<object, Parrot.Infrastructure.ValueType, bool> noOutput = (a, v) =>
                    {
                        if (a is bool && !(bool) attributeValue)
                        {
                            return true;
                        }

                        if (attributeValue == null && v == Parrot.Infrastructure.ValueType.Keyword)
                        {
                            return true;
                        }

                        return false;
                    };

                    if (attributeValue is bool && (bool)attributeValue)
                    {
                        tag.MergeAttribute(attribute.Key, attribute.Key, true);
                    }
                    else if (noOutput(attributeValue, attribute.ValueType))
                    {
                        //checked=false should not output the checked attribute
                        //checked=null should not output the checked attribute
                    }
                    else
                    {
                        tag.MergeAttribute(attribute.Key, (string)attributeValue, true);
                    }
                }
            }

            //check and see if there's a parameter and assign it to value
            if (blockNode.Parameters != null && blockNode.Parameters.Count == 1)
            {
                //grab only the first
                var parameter = blockNode.Parameters[0];
                string value = parameter.Value;
                tag.MergeAttribute("value", value, true);
            }

            return tag.ToString(TagRenderMode.SelfClosing);
        }
Ejemplo n.º 14
0
 public virtual string Render(AbstractNode node)
 {
     return Render(node, null);
 }
Ejemplo n.º 15
0
 public string Render(AbstractNode node, object model)
 {
     return _renderer(null, model);
 }
Ejemplo n.º 16
0
 public string Render(AbstractNode node)
 {
     return "null"; //throw a null reference exception here?
 }
Ejemplo n.º 17
0
 public string Render(AbstractNode node, object documentHost)
 {
     return documentHost.ToString();
 }
Ejemplo n.º 18
0
 public string Render(AbstractNode node)
 {
     throw new InvalidOperationException();
 }