private static HtmlControl CreateElementWithAttributes(string part, string name) { using (HtmlControl element = HtmlElementFactory.Create(name)) { List <string> subParts = GetSubParts(part, _attr); foreach (string subPart in subParts) { // Class if (subPart[0] == '.') { AddClass(element, subPart); } // ID else if (subPart[0] == '#') { AddId(element, subPart); } else if (subPart[0] == '[') { AddAttributes(element, subPart); } else if (subPart[0] == '{') { AddInnerText(element, subPart); } } return(element); } }
public static HtmlControl Parse(string zenSyntax) { string[] args = zenSyntax.TrimStart('+', '>', '^').Split(':'); if (args.Length != 2) { return(null); } using (HtmlControl element = HtmlElementFactory.Create(args[0])) { AddAttributes(element, args[1]); return(element); } }
public static HtmlControl CloneElement(this HtmlControl element, int count) { if (element == null) { return(null); } using (HtmlControl control = HtmlElementFactory.Create(element.TagName.Increment(count), element.GetType(), true)) { foreach (var attribute in element.Attributes.Keys) { string attr = (string)attribute; control.Attributes[attr] = element.Attributes[attr].Increment(count); if (attr == "class") { control.Attributes[attr] = control.Attributes[attr].Increment(count); } } if (!string.IsNullOrEmpty(element.ID)) { control.ID = element.ID.Increment(count); } var lorem = element as LoremControl; if (lorem != null) { (control as LoremControl).InnerText = lorem.Generate(count); } else if (element.Controls.Count == 1) { LiteralControl literal = element.Controls[0] as LiteralControl; if (literal != null) { control.Controls.Add(new LiteralControl(literal.Text.Increment(count))); } } return(control); } }
public static Control CreateDoctypes(string part, ref IEnumerable <Control> current) { if (part == null) { return(null); } using (ContentPlaceHolder root = new ContentPlaceHolder()) { string second = part.Substring(part.IndexOf(':') + 1); root.Controls.Add(new LiteralControl(GetDoctype(second))); using (HtmlControl html = HtmlElementFactory.Create("html")) { if (!second.StartsWith("x", StringComparison.Ordinal)) { html.Attributes["lang"] = "en"; } else { html.Attributes["xmlns"] = "http://www.w3.org/1999/xhtml"; html.Attributes["xml:lang"] = "en"; } root.Controls.Add(html); using (HtmlControl head = HtmlElementFactory.Create("head")) using (HtmlControl title = HtmlElementFactory.Create("title")) using (HtmlControl meta = ShortcutHelper.Parse("meta:utf")) { head.Controls.Add(title); head.Controls.Add(meta); html.Controls.Add(head); } using (HtmlControl body = HtmlElementFactory.Create("body")) { html.Controls.Add(body); current = new Control[] { body }; } return(root); } } }