New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require braces around the body of an element #137

Merged
merged 6 commits into from Jun 20, 2018

Conversation

Projects
None yet
3 participants
@lfairy
Owner

lfairy commented Jun 16, 2018

Summary

Maud now requires braces around the body of an HTML element. For example, this code

html! {
    h1 a href="/" "Pinkie Pie's awesome website"
    div#main (contents)
}

must now be written as

html! {
    h1 {
        a href="/" { "Pinkie Pie's awesome website" }
    }
    div#main { (contents) }
}

This change was made to address usability issues, as well as improve visual harmony with surrounding Rust code.

Rationale

Omitting the braces around an element body can reduce clutter. The feature is also easy to implement, and does not introduce ambiguity in the formal grammar.

However, over the last few months I have found many arguments for removing the feature:

  • In #117, a user questioned why label "Email" for="email" didn't work. If we had required braces around the body, then it would be clear why label { "Email" } for="email" wouldn't parse.

  • A void element (e.g. input type="text";) is always terminated by a semicolon. But an element with a single node in its body (e.g. p "hello") does not require a semicolon. This is inconsistent with Rust syntax in general, which requires semicolons on statements unless they have return values or end with a braced block.

  • The shorthand syntax also hides errors. If the user omits the trailing semicolon on a void element, then Maud will emit an extra end tag. For example, this code:

    html! {
        input name="cuteness" type="number"  // note missing `;`
        button "Update!"
    }

    results in the following HTML:

    <input name="cuteness" type="number">
        <button>Update!</button>
    </input>

    It's possible for the library to detect and warn about these cases, but we should aim to avoid this situation in the first place.

FAQ

Do we need a deprecation period for this change?

I don't think so. Template engines tend to be direct dependencies, not transitive ones (like Serde), so it should be easy to pin an older version if you're not ready to deal with the breakage yet.

I have another question. Should I ask it here?

Go for it! 馃槃

@lfairy lfairy changed the title from [WIP] Require braces around the body of an element to Require braces around the body of an element Jun 17, 2018

@anxiousmodernman

This comment has been minimized.

Contributor

anxiousmodernman commented Jun 17, 2018

Seems sensible. The unit tests read nicer, in my opinion.

@lfairy lfairy merged commit 1f68ef0 into master Jun 20, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@lfairy lfairy deleted the snaggletooth branch Jun 20, 2018

lfairy added a commit to lfairy/maud-book that referenced this pull request Jul 15, 2018

@Korvox

This comment has been minimized.

Korvox commented Aug 2, 2018

This one bites. Went back to an older site to update it and got 150 errors of this, and fixing them all bloated one of my templates from 560 chars (without whitespace / control chars) to 644 chars, a 13% bloat.

I'm not sure how feasible it is, but I would love for it to be an option to disable redudnant braces. Its probably the Pythonista talking, and you are right that it is Rust and this isn't really the domain of terse beautiful syntax, but it did feel like magic to go from:

<button class="btn">Thing</button>

to

button.btn "Thing"

Like sanity in a space where so little has existed for twenty years.

button.btn { "Thing" }

Isn't worse than the original, but its for sure a lot less magical.

In some ways it is even more redundant than regular html, since you have the braces and the quotations demarking the text body whereas with html you delineate the tags only, which kind of sucks.

Not really any point here, just going to miss how beautiful Maud was. It felt as close to no boilerplate markup as you could get. I'd definitely love some tunable to make the extra braces a warning or something. For now I'm just going to keep a local copy and revert the braces requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment