macro_rules! define_elements {
{
$(
$(#[$meta:meta])*
$name:ident $(
{
$(
$(#[$attr_meta:meta])*
$attr:ident
)*
}
)?
)*
} => { ... };
}Expand description
Define custom elements.
This macro should be called from within a module named hypertext_elements.
ยงExample
mod hypertext_elements {
use hypertext::define_elements;
// Re-export all standard HTML elements
pub use hypertext::validation::hypertext_elements::*;
define_elements! {
/// A custom web component that greets the user.
simple_greeting {
/// The name of the person to greet.
name
}
/// An element representing a coordinate.
coordinate {
/// The x coordinate.
x
/// The y coordinate.
y
}
}
}
// Now, you can use the custom elements like this:
use hypertext::prelude::*;
assert_eq!(
maud! {
simple-greeting name="Alice" {
coordinate x=1 y=2 {}
}
}
.render()
.as_inner(),
r#"<simple-greeting name="Alice"><coordinate x="1" y="2"></coordinate></simple-greeting>"#,
)