public override void Render(Context context, IndentationTextWriter result) { context.Registers["cycle"] = context.Registers["cycle"] ?? new Hash(0); context.Stack(() => { string key = context[_name].ToString(); int iteration = (int)(((Hash)context.Registers["cycle"])[key] ?? 0); result.Write(context[_variables[iteration]].ToString()); ++iteration; if (iteration >= _variables.Length) { iteration = 0; } ((Hash)context.Registers["cycle"])[key] = iteration; }); }
public override void Render(Context context, IndentationTextWriter result) { context.Stack(() => { string tempString; using (var temp = IndentationTextWriter.Create()) { RenderAll(NodeList, context, temp); tempString = temp.ToString(); } if (tempString != (context.Registers["ifchanged"] as string)) { context.Registers["ifchanged"] = tempString; result.Write(tempString); } }); }
private static void WritePropertyValue(Property property, IndentationTextWriter writer) { object value = property.Value; if (value is IList) { IList elements = (IList)value; if ((property.PropertyDeclaration != null) && (property.PropertyDeclaration.Name == "Resources") && (elements.Count == 1) && (elements[0] is Element)) { Element element = (Element) elements[0]; if ((element.TypeDeclaration.Name == "ResourceDictionary") && (element.TypeDeclaration.Namespace == "System.Windows") && (element.TypeDeclaration.Assembly == "PresentationFramework") && (element.Arguments.Count == 0) && (element.Properties.Count == 1) && (element.Properties[0].PropertyType == PropertyType.Content)) { WritePropertyValue(element.Properties[0], writer); return; } } foreach (object child in elements) { if (child is string) { writer.Write((string)child); } else if (child is Element) { WriteElement((Element)child, writer); } else { throw new NotSupportedException(); } } } else if (value is string) { string text = (string)value; writer.Write(text); } else if (value is Element) { Element element = (Element)value; WriteElement(element, writer); } else { throw new NotSupportedException(); } }
private static void WriteElement(Element element, IndentationTextWriter writer) { writer.Write("<"); WriteTypeDeclaration(element.TypeDeclaration, writer); ArrayList attributes = new ArrayList(); ArrayList properties = new ArrayList(); Property contentProperty = null; foreach (Property property in element.Properties) { switch (property.PropertyType) { case PropertyType.List: case PropertyType.Dictionary: properties.Add(property); break; case PropertyType.Namespace: case PropertyType.Value: case PropertyType.Declaration: attributes.Add(property); break; case PropertyType.Complex: if (IsExtension(property.Value)) { attributes.Add(property); } else { properties.Add(property); } break; case PropertyType.Content: contentProperty = property; break; } } foreach (Property property in attributes) { writer.Write(" "); WritePropertyDeclaration(property.PropertyDeclaration, element.TypeDeclaration, writer); writer.Write("="); writer.Write("\""); switch (property.PropertyType) { case PropertyType.Complex: WriteComplexElement((Element)property.Value, writer); break; case PropertyType.Namespace: case PropertyType.Declaration: case PropertyType.Value: writer.Write(property.Value.ToString()); break; default: throw new NotSupportedException(); } writer.Write("\""); } if ((contentProperty != null) || (properties.Count > 0)) { writer.Write(">"); if ((properties.Count > 0) || (contentProperty.Value is IList)) { writer.WriteLine(); } writer.Indentation++; foreach (Property property in properties) { writer.Write("<"); WriteTypeDeclaration(element.TypeDeclaration, writer); writer.Write("."); WritePropertyDeclaration(property.PropertyDeclaration, element.TypeDeclaration, writer); writer.Write(">"); writer.WriteLine(); writer.Indentation++; WritePropertyValue(property, writer); writer.Indentation--; writer.Write("</"); WriteTypeDeclaration(element.TypeDeclaration, writer); writer.Write("."); WritePropertyDeclaration(property.PropertyDeclaration, element.TypeDeclaration, writer); writer.Write(">"); writer.WriteLine(); } if (contentProperty != null) { WritePropertyValue(contentProperty, writer); } writer.Indentation--; writer.Write("</"); WriteTypeDeclaration(element.TypeDeclaration, writer); writer.Write(">"); } else { writer.Write(" />"); } writer.WriteLine(); }
public override void Render(Context context, IndentationTextWriter result) { object coll = context[_collectionName]; if (!(coll is IEnumerable)) { return; } IEnumerable <object> collection = ((IEnumerable)coll).Cast <object>(); if (_attributes.ContainsKey("offset")) { int offset = Convert.ToInt32(_attributes["offset"]); collection = collection.Skip(offset); } if (_attributes.ContainsKey("limit")) { int limit = Convert.ToInt32(_attributes["limit"]); collection = collection.Take(limit); } collection = collection.ToList(); int length = collection.Count(); int cols = Convert.ToInt32(context[_attributes["cols"]]); int row = 1; int col = 0; result.WriteLine("<tr class=\"row1\">"); context.Stack(() => collection.EachWithIndex((item, index) => { context[_variableName] = item; context["tablerowloop"] = Hash.FromAnonymousObject(new { length = length, index = index + 1, index0 = index, col = col + 1, col0 = col, rindex = length - index, rindex0 = length - index - 1, first = (index == 0), last = (index == length - 1), col_first = (col == 0), col_last = (col == cols - 1) }); ++col; using (var temp = IndentationTextWriter.Create()) { RenderAll(NodeList, context, temp); result.Write("<td class=\"col{0}\">{1}</td>", col, temp.ToString()); } if (col == cols && index != length - 1) { col = 0; ++row; result.WriteLine("</tr>"); result.Write("<tr class=\"row{0}\">", row); } })); result.WriteLine("</tr>"); }
private static void WritePropertyValue(Property property, IndentationTextWriter writer) { object obj2 = property.Value; if (obj2 is IList) { IList list = (IList)obj2; if (((property.PropertyDeclaration != null) && (property.PropertyDeclaration.Name == "Resources")) && ((list.Count == 1) && (list[0] is Element))) { Element element = (Element)list[0]; if ((((element.TypeDeclaration.Name == "ResourceDictionary") && (element.TypeDeclaration.Namespace == "System.Windows")) && ((element.TypeDeclaration.Assembly == "PresentationFramework") && (element.Arguments.Count == 0))) && ((element.Properties.Count == 1) && (element.Properties[0].PropertyType == PropertyType.Content))) { WritePropertyValue(element.Properties[0], writer); return; } } foreach (object obj3 in list) { if (!(obj3 is string)) { if (!(obj3 is Element)) { throw new NotSupportedException(); } WriteElement((Element)obj3, writer); } else { writer.Write((string)obj3); continue; } } } else if (obj2 is string) { string str = (string)obj2; writer.Write(str); } else { if (!(obj2 is Element)) { throw new NotSupportedException(); } Element element2 = (Element)obj2; WriteElement(element2, writer); } }
private static void WriteElement(Element element, IndentationTextWriter writer) { writer.Write("<"); WriteTypeDeclaration(element.TypeDeclaration, writer); ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); Property property = null; foreach (Property property2 in element.Properties) { switch (property2.PropertyType) { case PropertyType.Value: case PropertyType.Declaration: case PropertyType.Namespace: { list.Add(property2); continue; } case PropertyType.Content: { property = property2; continue; } case PropertyType.List: case PropertyType.Dictionary: { list2.Add(property2); continue; } case PropertyType.Complex: { if (!IsExtension(property2.Value)) { break; } list.Add(property2); continue; } default: { continue; } } list2.Add(property2); } foreach (Property property3 in list) { writer.Write(" "); WritePropertyDeclaration(property3.PropertyDeclaration, element.TypeDeclaration, writer); writer.Write("="); writer.Write("\""); switch (property3.PropertyType) { case PropertyType.Value: case PropertyType.Declaration: case PropertyType.Namespace: writer.Write(property3.Value.ToString()); break; case PropertyType.Complex: WriteComplexElement((Element)property3.Value, writer); break; default: throw new NotSupportedException(); } writer.Write("\""); } if ((property != null) || (list2.Count > 0)) { writer.Write(">"); if ((list2.Count > 0) || (property.Value is IList)) { writer.WriteLine(); } writer.Indentation++; foreach (Property property4 in list2) { writer.Write("<"); WriteTypeDeclaration(element.TypeDeclaration, writer); writer.Write("."); WritePropertyDeclaration(property4.PropertyDeclaration, element.TypeDeclaration, writer); writer.Write(">"); writer.WriteLine(); writer.Indentation++; WritePropertyValue(property4, writer); writer.Indentation--; writer.Write("</"); WriteTypeDeclaration(element.TypeDeclaration, writer); writer.Write("."); WritePropertyDeclaration(property4.PropertyDeclaration, element.TypeDeclaration, writer); writer.Write(">"); writer.WriteLine(); } if (property != null) { WritePropertyValue(property, writer); } writer.Indentation--; writer.Write("</"); WriteTypeDeclaration(element.TypeDeclaration, writer); writer.Write(">"); } else { writer.Write(" />"); } writer.WriteLine(); }