diff --git a/maud_extras/lib.rs b/maud_extras/lib.rs index bbff757..ceaa959 100644 --- a/maud_extras/lib.rs +++ b/maud_extras/lib.rs @@ -30,3 +30,107 @@ impl<T: AsRef<str>> Render for Css<T> { } } } + +/// Links to an external javascript. +/// +/// # Example +/// +/// ```rust +/// # #![feature(plugin)] +/// # #![plugin(maud_macros)] +/// # extern crate maud; +/// # extern crate maud_extras; +/// # use maud_extras::*; +/// # fn main() { +/// let markup = html! { (Js("app.js")) }; +/// assert_eq!(markup.into_string(), +/// r#"<script src="app.js"></script>"#); +/// # } +/// ``` +pub struct Js<T: AsRef<str>>(pub T); + +impl<T: AsRef<str>> Render for Js<T> { + fn render(&self) -> Markup { + html! { + script src=(self.0.as_ref()) {} + } + } +} + +/// Generate <meta> elements. +/// +/// # Example +/// +/// ```rust +/// # #![feature(plugin)] +/// # #![plugin(maud_macros)] +/// # extern crate maud; +/// # extern crate maud_extras; +/// # use maud_extras::*; +/// # fn main() { +/// let m = Meta("description", "test description"); +/// assert_eq!(html!{ (m) }.into_string(), +/// r#"<meta name="description" content="test description">"#); +/// # } +/// ``` +pub struct Meta<T: AsRef<str>, U: AsRef<str>>(pub T, pub U); + +impl<T: AsRef<str>, U: AsRef<str>> Render for Meta<T, U> { + fn render(&self) -> Markup { + html! { + meta name=(self.0.as_ref()) content=(self.1.as_ref()) / + } + } +} + +/// Generate <title> element. +/// +/// # Example +/// +/// ```rust +/// # #![feature(plugin)] +/// # #![plugin(maud_macros)] +/// # extern crate maud; +/// # extern crate maud_extras; +/// # use maud_extras::*; +/// # fn main() { +/// let markup = html! { (Title("Maud")) }; +/// assert_eq!(markup.into_string(), +/// r#"<title>Maud</title>"#); +/// # } +/// ``` +pub struct Title<T: AsRef<str>>(pub T); + +impl<T: AsRef<str>> Render for Title<T> { + fn render(&self) -> Markup { + html! { + title (self.0.as_ref()) + } + } +} + +/// Generate <meta charset=""> element. +/// +/// # Example +/// +/// ```rust +/// # #![feature(plugin)] +/// # #![plugin(maud_macros)] +/// # extern crate maud; +/// # extern crate maud_extras; +/// # use maud_extras::*; +/// # fn main() { +/// let markup = html! { (Charset("utf-8")) }; +/// assert_eq!(markup.into_string(), +/// r#"<meta charset="utf-8">"#); +/// # } +/// ``` +pub struct Charset<T: AsRef<str>>(pub T); + +impl<T: AsRef<str>> Render for Charset<T> { + fn render(&self) -> Markup { + html! { + meta charset=(self.0.as_ref()) / + } + } +}