Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed tags #378

Closed
imbolc opened this issue Apr 16, 2023 · 3 comments
Closed

Typed tags #378

imbolc opened this issue Apr 16, 2023 · 3 comments

Comments

@imbolc
Copy link
Contributor

imbolc commented Apr 16, 2023

It would be great to check tags attributes on compile time. Maybe something like HtmlTag trait one could derive to describe types:

#[derive(HtmlTag)]
struct Form {
    action: Option<String>,
    method: Option<Method>,
}

#[derive(FromStr)]
enum Method {
    Get,
    Post,
}

and then use it like

@Form
   method="PUT"  <-- bad value use one of [GET, POST]
@lambda-fairy
Copy link
Owner

Have you seen this?

https://github.com/yoshuawuyts/html

In general I'm against validation (except the bare minimum needed for security – see #181). Because it's a lot of work, and also I don't think Maud can do it better than the html crate.

@imbolc
Copy link
Contributor Author

imbolc commented Apr 16, 2023

I'm not suggesting that Maud should implement the entire HTML specification. I don't even think it would be enough, considering enhancements like Htmx. However, I would like Maud to provide support for typed tags (e.g., through a derivable trait). Typically, projects use a small subset of tags and their attributes, which isn't so hard to type. This approach also enables people to share typing efforts by creating specialized crates, e.g. maud-htmx.

@lambda-fairy
Copy link
Owner

Typically, projects use a small subset of tags and their attributes, which isn't so hard to type.

Then we're offloading the validation effort to library users. That doesn't seem like an improvement over yoshuawuyts/html.

In general I feel this suggestion is a big change, with a lot of design decisions, and really different to where the library is now. If you'd like to explore that space then I suggest rolling your own library.

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

No branches or pull requests

2 participants