render-rs / render.rs

🔏 A safe and simple template engine with the ergonomics of JSX
https://docs.rs/render
MIT License
238 stars 23 forks source link

How to handle boolean attributes in HTML? #38

Open vpzomtrrfrt opened 4 years ago

vpzomtrrfrt commented 4 years ago

Certain HTML attributes, such as

Schniz commented 4 years ago

We can have an enum type for HTML attributes (playground link), so:

enum HtmlAttribute {
  StringValue(String, String),
  BooleanValue(String, bool)
}

and use From<(String, String)> and From<(String, bool)> to generate HtmlAttribute — so the following syntax will be supported:

html! {
  <button disabled={true} type="button" />
}

# will be almost like

::render::SimpleElement {
  tag_name: "button",
  attributes: [HtmlAttribute::from(("disabled", true), HtmlAttribute::from(("type", "button"))],
  children: None
}

What do you think?

vpzomtrrfrt commented 4 years ago

That seems reasonable