#![feature(try_from)] #![feature(proc_macro_hygiene)] extern crate stdweb; extern crate typed_html; extern crate typed_html_macros; use stdweb::web::{self, Element, IElement, INode}; use typed_html::for_events; use typed_html::dom::{Node, VNode}; use typed_html::events::{EFn, Events}; use typed_html_macros::html; fn install_handlers(target: &Element, handlers: &mut Events) { for_events!(handler in handlers => { handler.attach(target); }); } fn build( document: &web::Document, vnode: VNode, ) -> Result { match vnode { VNode::Text(text) => Ok(document.create_text_node(&text).into()), VNode::Element(element) => { let mut node = document.create_element(element.name)?; for (key, value) in element.attributes { node.set_attribute(&key, &value)?; } install_handlers(&node, element.events); for child in element.children { let child_node = build(document, child)?; node.append_child(&child_node); } Ok(node.into()) } } } fn main() { let mut doc = html!(

"Hello Kitty"

"She is not a ""cat" ". She is a ""human girl""."

); let vdom = doc.vnode(); let document = web::document(); let body = document.body().expect("no body element in doc"); let tree = build(&document, vdom).unwrap(); body.append_child(&tree); }