dhtags.attrs

Modules

attribute
module dhtags.attrs.attribute
define
module dhtags.attrs.define

Examples

Attribute should be rendered as strings between quotes

1 import dhtags.attrs.attribute : HtmlAttribute;
2 
3 /** Defining custom attributes with allowed types should be possible */
4 mixin DefineAttr!("danger-level", int);
5 assert(
6    HtmlAttribute.create(dangerLevel=5).toString == 
7    `danger-level="5"`
8 );
9 
10 /** Define custom boolean attributes should be possible */
11 mixin DefineBooleanAttr!("finagles");
12 assert(
13    HtmlAttribute.create(finagles).toString ==
14    `finagles="finagles"`
15 );
16 
17 /** Defining custom attributes with an 'attr' function should be possible */
18 assert(
19    HtmlAttribute.create("my-attr".attr="Hello").toString
20    == `my-attr="Hello"`
21 );

Defining custom attributes with an 'attr' function should be possible

1 import dhtags.attrs.attribute : HtmlAttribute;
2 
3 /** Boolean attribute's value should match the attribute's name */
4 assert(
5    HtmlAttribute.create(async).toString
6    == `async="async"`
7 );
8 
9 /** True/false attributes should allow boolean values */
10 assert(
11    HtmlAttribute.create(contenteditable=true).toString
12    == `contenteditable="true"`
13 );
14 
15 /** Integer values should be rendered as strings */
16 assert(
17    HtmlAttribute.create(height=50).toString
18    == `height="50"`
19 );
20 
21 /** Double values should be rendered as strings without trailing zeros */
22 assert(
23    HtmlAttribute.create(height=50.5).toString
24    == `height="50.5"`
25 );
26 
27 /** Arrays should be space separated */
28 assert(
29    HtmlAttribute.create(className=["class1", "class2", "class3"]).toString
30    == `class="class1 class2 class3"`
31 );

Arrays should be space separated

1 import dhtags.attrs.attribute : HtmlAttribute;
2 
3 /** Lower camelcase data attributes should be converted to lowercase hyphen-separated string */
4 assert(
5    HtmlAttribute.create(data.ABSomeTESTWordCD=10).toString
6    == `data-ab-some-test-word-cd="10"`
7 );
8 
9 /** Uppercase acronyms in data attributes should be split as expected */
10 assert(
11    HtmlAttribute.create(data.customHTMLAttr=false).toString
12    == `data-custom-html-attr="false"`
13 );
14 
15 /** Alternative data syntax should be allowed */
16 assert(
17    HtmlAttribute.create(data("some-value")=10).toString
18    == `data-some-value="10"`
19 );

Meta