public BlockNode(string blockName, AttributeNodeList attributes, ParameterNodeList parameterNodes, BlockNode childNode) : this(blockName, attributes, parameterNodes) { Children.Add(childNode); }
protected TagBuilder CreateTag(object model, BlockNode blockNode) { object localModel = model; if (blockNode.Parameters != null && blockNode.Parameters.Any()) { blockNode.Parameters.First().SetModel(model); localModel = (blockNode.Parameters.First() as ParameterNode).GetPropertyValue(); } TagBuilder builder = new TagBuilder(blockNode.BlockName); foreach (var attribute in blockNode.Attributes.Cast<AttributeNode>()) { attribute.SetModel(model); if (attribute.Key == "class") { builder.AddCssClass(attribute.GetValue()); } else { builder.MergeAttribute(attribute.Key, attribute.GetValue(), true); } } if (blockNode.Children.Any()) { if (localModel is IEnumerable && blockNode.Parameters != null && blockNode.Parameters.Any()) { StringBuilder sb = new StringBuilder(); foreach (object item in localModel as IEnumerable) { var localItem = item; foreach (var child in blockNode.Children) { var renderer = Parrot.Infrastructure.Host.DependencyResolver.Get<IRendererFactory>().GetRenderer(child.BlockName); sb.AppendLine(renderer.Render(child, localItem)); } } builder.InnerHtml += sb.ToString(); } else { StringBuilder sb = new StringBuilder(); foreach (var child in blockNode.Children) { if (child != null) { var renderer = Parrot.Infrastructure.Host.DependencyResolver.Get<IRendererFactory>().GetRenderer(child.BlockName); sb.Append(renderer.Render(child, localModel)); } } builder.InnerHtml = sb.ToString(); } } else { if (blockNode.Parameters != null && blockNode.Parameters.Any()) { builder.InnerHtml = localModel != null ? localModel.ToString() : ""; } } return builder; }