Skip to content

Commit

Permalink
Create impl_attr_methods! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jan 20, 2024
1 parent e88d579 commit 20bc84f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion crates/concoct-web/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ pub struct Html<C> {
child: Child<C>,
}

macro_rules! impl_attr_methods {
($($fn_name: tt: $name: tt),*) => {
$(
pub fn $fn_name(self, value: impl Into<Cow<'static, str>>,) -> Self {
self.attr($name, value)
}
)*
};
}

macro_rules! impl_handler_methods {
($($fn_name: tt: $name: tt),*) => {
$(
Expand Down Expand Up @@ -86,7 +96,16 @@ impl<C> Html<C> {
self
}

impl_handler_methods!(on_click: "click", on_input: "input", on_submit: "submit");
impl_attr_methods!(
class: "class",
kind: "type"
);

impl_handler_methods!(
on_click: "click",
on_input: "input",
on_submit: "submit"
);
}

impl<C: Body> View for Html<C> {
Expand Down

0 comments on commit 20bc84f

Please sign in to comment.