1 module uim.html.elements.html; 2 3 import uim.html; 4 5 /** 6 * DH5Html - Wrapper for the html-Element 7 * Das html-Element, auch root(-Element) oder Wurzelelement enthält den vollständigen Inhalt einer Internetseite. 8 * Date: January 09, 2015 9 */ 10 class DH5Html : DH5Obj { 11 mixin(H5This!"html"); 12 13 override public void _init() { 14 super._init; 15 _head = H5Head; 16 _body_ = H5Body; 17 } 18 19 void Add(T...)(T values) { _body.Add(values); } 20 21 O Add(this O, T...)(T values) { 22 switch (values.length) { 23 case 0: break; 24 case 1: 25 static if (is(typeof(values[0]) == DH5Head)) _head = values[0]; 26 else if (is(typeof(values[0]) == DH5Body)) _body = values[0]; 27 else _body.add(values[0]); break; 28 default: 29 static if ((is(typeof(values[0]) == string)) && ((is(typeof(values[1]) == string[])) || (is(typeof(values[1]) == string[string])))) { 30 _id = values[0]; foreach(v; values[1..$]) { 31 static if (is(typeof(v) == DH5Head)) { _head = v; continue; } 32 static if (is(typeof(v) == DH5Body)) { _body = v; continue; } 33 _body.add(v); } 34 } 35 else { foreach(v; values) { 36 static if (is(typeof(v) == DH5Head)) { _head = v; continue; } 37 static if (is(typeof(v) == DH5Body)) { _body = v; continue; } 38 _body.add(v); } 39 } 40 break; 41 } 42 return cast(O)this; 43 } 44 45 alias add = typeof(super).add; 46 47 mixin(OProperty!("DH5Head","head")); 48 auto head(this O)(string[] classes) { _head(classes); return cast(O)this;} 49 auto head(this O)(string[string] attributes) { _head(attributes); return cast(O)this;} 50 //auto head(this O)(string[] classes, string[string] attributes) { _html[0](classes, attributes); return cast(O)this;} 51 auto head(this O)(string addContent) { _head(addContent); return cast(O)this;} 52 53 mixin(OProperty!("DH5Body","body_")); 54 auto body_(this O)(string[] classes) { _body_(classes); return cast(O)this;} 55 auto body_(this O)(string[string] attributes) { _body_(attributes); return cast(O)this;} 56 auto body_(this O)(string[] classes, string[string] attributes) { _body_(classes, attributes); return cast(O)this;} 57 auto body_(this O)(string addContent) { _body_(addContent); return cast(O)this;} 58 auto body_(this O)(DH5Obj[] addContent...) { _body_(addContent); return cast(O)this;} 59 auto body_(this O)(DH5Obj[] addContent) { _body_(addContent); return cast(O)this;} 60 61 void opBinary(string op, T...)(T values) { static if ((op == "+") || (op == "~")) Add(values); } 62 63 /* O scripts(this O)(string[] links) { _body.scripts(links); return cast(O)this; } 64 O script(this O, T...)(T values) { _body.script(values); return cast(O)this; } 65 */ 66 override string toString() { 67 return h5Doctype~H5Obj(_id, _classes, _attributes, _head, _body_).tag("html").toString; } 68 } 69 mixin(H5Short!"Html"); 70 71 unittest { 72 writeln(H5Html); 73 assert(Assert(H5Html,"<!doctype html><html><head></head><body></body></html>")); 74 assert(Assert(H5Html(["lang":"en"]),"<!doctype html><html lang=\"en\"><head></head><body></body></html>")); 75 }