diff --git a/rocket/src/main.rs b/rocket/src/main.rs index 0de5d49..6855384 100644 --- a/rocket/src/main.rs +++ b/rocket/src/main.rs @@ -9,10 +9,9 @@ use rocket::response::{Responder, Result}; use rocket::{get, routes, Request, Response}; use std::io::Cursor; use typed_html::types::LinkType; -use typed_html::{dom::Node, text}; -use typed_html_macros::html; +use typed_html::{dom::DOMTree, html, text}; -struct Html(Box>); +struct Html(DOMTree); impl<'r> Responder<'r> for Html { fn respond_to(self, _request: &Request) -> Result<'r> { diff --git a/typed-html/Cargo.toml b/typed-html/Cargo.toml index ccee029..088d49f 100644 --- a/typed-html/Cargo.toml +++ b/typed-html/Cargo.toml @@ -9,7 +9,6 @@ strum = "0.11.0" strum_macros = "0.11.0" mime = "0.3.12" language-tags = "0.2.2" -enumset = "0.3.12" http = "0.1.13" htmlescape = "0.3.1" stdweb = "0.4.10" diff --git a/typed-html/src/bin/main.rs b/typed-html/src/bin/main.rs index 2a9523c..3142630 100644 --- a/typed-html/src/bin/main.rs +++ b/typed-html/src/bin/main.rs @@ -3,11 +3,10 @@ #[macro_use] extern crate typed_html; -extern crate typed_html_macros; use typed_html::dom::TextNode; +use typed_html::html; use typed_html::types::*; -use typed_html_macros::html; struct Foo { foo: &'static str, diff --git a/typed-html/src/dom.rs b/typed-html/src/dom.rs index 8214367..8bf74ec 100644 --- a/typed-html/src/dom.rs +++ b/typed-html/src/dom.rs @@ -8,6 +8,26 @@ use elements::{FlowContent, PhrasingContent}; use events::Events; use htmlescape::encode_minimal; +/// A boxed DOM tree, as returned from the `html!` macro. +/// +/// # Examples +/// +/// ``` +/// # #![feature(proc_macro_hygiene)] +/// # extern crate typed_html; +/// # use typed_html::html; +/// # use typed_html::dom::DOMTree; +/// # fn main() { +/// let tree: DOMTree = html!( +///
+///

"Hello Joe!"

+///
+/// ); +/// let rendered_tree: String = tree.to_string(); +/// # } +/// ``` +pub type DOMTree = Box>; + /// An untyped representation of an HTML node. /// /// This structure is designed to be easily walked in order to render a DOM tree @@ -52,7 +72,7 @@ pub trait Node: Display { /// Render the node into a [`VNode`][VNode] tree. /// /// [VNode]: enum.VNode.html - fn vnode<'a>(&'a mut self) -> VNode<'a, T>; + fn vnode(&mut self) -> VNode; } /// Trait for querying a typed HTML element. diff --git a/typed-html/src/events.rs b/typed-html/src/events.rs index c8a8400..d11bfed 100644 --- a/typed-html/src/events.rs +++ b/typed-html/src/events.rs @@ -25,6 +25,26 @@ macro_rules! declare_events { } } + /// Iterate over the defined events on a DOM object. + /// + /// # Examples + /// + /// ``` + /// # #![feature(proc_macro_hygiene)] + /// # extern crate typed_html; + /// # use typed_html::{html, for_events}; + /// # use typed_html::dom::{DOMTree, VNode}; + /// # fn main() { + /// let mut doc: DOMTree = html!( + ///