RUST crate for generating html (or other DOM) text as String objects.

Example

A simple html page can be created by following codes:

``` use domrenderer::*; let html = htmlbasic!( title: "Page Title", body: endelem!("h1"; "Section"), endelem!("p"; "Text goes here..."), ); assert_eq!("Page Title

Section

Text goes here...

", html.render());

let th = elem!("tr"; endelem!("th"; "Item1"), endelem!("th"; "Item2"), endelem!("th"; "Item3"), ); let tr1 = elem!("tr"; endelem!("td"; "value 11"), endelem!("td"; "value 12"), endelem!("td"; "value 13"), ); let tr2 = elem!("tr"; endelem!("td"; "value 21"), endelem!("td"; "value 22"), endelem!("td"; "value 23"), ); let tbl = elem!("table"; ("border", "1"); th, tr1, tr2); asserteq!("

Item1Item2Item3
value 11value 12value 13
value 21value 22value 23
", tbl.render()); ```

DOM Nodes are represented by enum DomNode, which can be created by macros.

Child nodes can be changed using as_XXX() methods.

``` use dom_renderer::*;

let mut tbl = elem!("table"); let tblelem = tbl.aselemmut().unwrap(); tblelem.attributes.push(("border", String::from("1"))); // header let mut tr = elem!("tr"); let headers = (1..=3) .map(|i| format!("Item{}", i)) .map(|x| endelem!("th"; x)) .collect(); tr.aselemmut().unwrap().childnodes = headers; tblelem.childnodes.push(tr); // data for i in 1..=2 { let mut tr = elem!("tr"); let data = (1..=3) .map(|j| format!("value {}{}", i, j)) .map(|x| endelem!("td"; x)) .collect(); tr.aselemmut().unwrap().childnodes = data; tblelem.childnodes.push(tr); } assert_eq!("

Item1Item2Item3
value 11value 12value 13
value 21value 22value 23
", tbl.render()); ```