#![allow(clippy::useless_vec)] use hypertext::{Attribute, AttributeNamespace, GlobalAttributes}; #[test] fn readme() { use hypertext::{html_elements, GlobalAttributes, RenderIterator, Renderable}; let shopping_list = vec!["milk", "eggs", "bread"]; let shopping_list_maud = hypertext::maud! { div { h1 { "Shopping List" } ul { @for (&item, i) in shopping_list.iter().zip(1..) { li.item { input #{ "item-" (i) } type="checkbox"; label for={ "item-" (i) } { (item) } } } } } } .render(); // or, alternatively: let shopping_list_rsx = hypertext::rsx! {

Shopping List

} .render(); assert_eq!(shopping_list_maud, shopping_list_rsx); } #[allow(non_upper_case_globals)] #[allow(dead_code)] trait HtmxAttributes: GlobalAttributes { const hx_post: Attribute = Attribute; const hx_on: AttributeNamespace = AttributeNamespace; } impl HtmxAttributes for T {} #[test] fn htmx() { use hypertext::{html_elements, Renderable}; let htmx_maud = hypertext::maud! { div { form hx-post="/login" hx-on::after-request="this.reset()" { input type="text" name="username"; input type="password" name="password"; input type="submit" value="Login"; } } } .render(); assert_eq!( htmx_maud, r#"
"# ); } #[test] fn elements_macro() { use hypertext::Renderable; mod html_elements { use hypertext::elements; pub use hypertext::html_elements::*; elements! { /// This is a test element my_element { /// This is a test attribute my_attribute } } } let custom_maud = hypertext::maud! { div { my_element my_attribute="test" { "Hello, world!" } } } .render(); assert_eq!( custom_maud, r#"
Hello, world!
"# ); }