simple/
simple.rs

1// examples/hello.rs
2
3use html_types::attributes::Value;
4use html_types::node::Element;
5use html_types::node::Node;
6use html_types::tag::Tag;
7use html_types::text::Text;
8
9fn main() {
10    // Create a link
11    let link = {
12        let label = Text::create("Click Me");
13        let url = Value::create("http://google.com").unwrap();
14        // Anchor is a helper for the typical case
15        Element::anchor(url, label)
16    };
17    // Create the body. Sugar function takes a list of child nodes
18    let body = Element::body(vec![link]);
19
20    // Create a header manually. There isn't a sugar function here
21    let header = {
22        let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23        let text = Text::create("Hello world");
24        let title = Element::title(text);
25        el.push(title);
26        el
27    };
28    let html = Element::html(Value::EN, header, body);
29
30    // Convert an element into a node
31    let node: Node = html.into();
32
33    // Nodes can be turned into HTML formatted strings
34    let string: String = node.into();
35
36    println!("{}", string);
37}