lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
2.14k stars 143 forks source link

Empty class when all optional classes are omitted #424

Open SenojLuap opened 9 months ago

SenojLuap commented 9 months ago

This may be a 'working as intended' situation, but I thought I'd raise the issue in case it's not:

Currently, if you're applying a class to an element optionally, but the condition is falsey, maud still generates a 'class' attribute, but with an empty class list.

Ex.

use maud::{html, Render};
fn main() {
    let demo_output = html! {
      p .someClass[false] {
        "Lorem Ipsum"
      }
    }
    .render();
    println!("Generated html: {}", demo_output.0);
}

Output: Generated html: <p class="">Lorem Ipsum</p>

Note that a 'class' attribute is generated, even though it isn't needed.

Definitely not a huge deal, but it would be nice to keep the HTML trim where possible.

SenojLuap commented 9 months ago

Also: I'm not opposed to putting in PR for this. I just wasn't sure whether this was an intentional 'feature' or not.