Tag content should allow a list of tags
1 import dhtags.utils.html : stripMargin; 2 3 /** Defining custom tags should be possible */ 4 5 mixin DefineTag!("ShoppingList"); 6 mixin DefineTag!("Item"); 7 mixin DefineTag!("Name"); 8 mixin DefineTag!("Quantity"); 9 10 assert( 11 ShoppingList( 12 Item( 13 Name("Orange"), 14 Quantity(2) 15 ), 16 Item( 17 Name("Milk"), 18 Quantity(5) 19 ) 20 ).toString == 21 `<ShoppingList> 22 <Item> 23 <Name>Orange</Name> 24 <Quantity>2</Quantity> 25 </Item> 26 <Item> 27 <Name>Milk</Name> 28 <Quantity>5</Quantity> 29 </Item> 30 </ShoppingList> 31 `.stripMargin 32 );
Tag content should allow a range of built-in types
1 import dhtags.utils.html : stripMargin; 2 3 /** Tag content should allow an array of tags */ 4 Tag[2] ps = [p("Hello!"), p("Nice to meet you.")]; 5 assert( 6 div(ps).toString == 7 "<div> 8 <p>Hello!</p> 9 <p>Nice to meet you.</p> 10 </div>".stripMargin 11 ); 12 13 /** Tag content should allow an array of strings */ 14 string[2] content = ["Hello!", " Nice to meet you."]; 15 assert( 16 div(content).toString == 17 "<div>Hello! Nice to meet you.</div>" 18 ); 19 20 /** Tag content should allow an array of built-in types */ 21 int[3] numbers = [1, 2, 3]; 22 assert( 23 div(numbers).toString == 24 "<div>123</div>" 25 );
Unescaped strings should also be possible
1 import dhtags.utils.html : stripMargin; 2 3 /** Void tags should not have a closing tag */ 4 assert( 5 div(base, hr, br, wbr, area, img, track, embed, param, source, col, input, keygen).toString == 6 "<div> 7 <base> 8 <hr> 9 <br> 10 <wbr> 11 <area> 12 <img> 13 <track> 14 <embed> 15 <param> 16 <source> 17 <col> 18 <input> 19 <keygen> 20 </div>".stripMargin 21 );
Void tags should not have a closing tag
1 /** Tag 'html' should not include a DOCTYPE */ 2 assert(html.toString == "<html></html>"); 3 4 /** Tag 'htmlWithDoctype' should include a DOCTYPE */ 5 assert(htmlWithDoctype.toString == "<!DOCTYPE html><html></html>");