1 module dhtags;
2 
3 public import dhtags.tags;
4 alias tags = dhtags.tags;
5 
6 public import dhtags.attrs;
7 alias attrs = dhtags.attrs;
8 
9 unittest {
10    import dhtags.utils.html : stripMargin;
11    
12    /** Tags should accept attributes in first parameter list and child tags in second parameter list */
13    assert(
14       htmlWithDoctype(
15          head(
16             script(type="text/javascript")("Script")
17          ),
18          body_(
19             div(id="main", className="content")(
20                p("Some ", b("text"), " goes here")
21             )
22          )
23       ).toString ==
24       "<!DOCTYPE html>
25       <html>
26          <head>
27             <script type=\"text/javascript\">Script</script>
28          </head>
29          <body>
30             <div id=\"main\" class=\"content\">
31                <p>Some <b>text</b> goes here</p>
32             </div>
33          </body>
34       </html>".stripMargin
35    );
36 }
37 
38 unittest {
39    /** Attributes should always be supplied before content */
40    assert(!__traits(compiles, div("Hello")(id="some-div")));
41 
42    /** Supplying multiple content lists should not be possible */
43    assert(!__traits(compiles, div("Hello1")("Hello2")));
44 }
45 
46 unittest {
47    /** Tags should be assignable to static const */
48    static const aTag = iframe(id="some-frame", width=5)("Hello");
49    assert(aTag.toString == `<iframe id="some-frame" width="5">Hello</iframe>`);
50 
51    /** Compile-time generation of html should be possible */
52    enum someHtml = iframe(id="some-frame", width=5)("Hello").toString;
53    assert(someHtml == `<iframe id="some-frame" width="5">Hello</iframe>`);
54 }
55 
56 unittest {
57    /** Tags should allow a range of attributes */
58    import std.container.dlist;
59    auto list = DList!(Attr)([cls="some-class", attrs.style="background-color:grey;"]);
60    assert(
61       div(list, attrs.data.width=5).toString == 
62       `<div class="some-class" style="background-color:grey;" data-width="5"></div>`
63    );
64 
65    /** Tags should allow an array of attributes */
66    Attr[2] array = [cls="some-class", attrs.style="background-color:grey;"];
67    assert(
68       div(array, attrs.data.width=5).toString == 
69       `<div class="some-class" style="background-color:grey;" data-width="5"></div>`
70    );
71 }