lambda-fairy / maud

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

Allow many ':' in attributes #393

Closed RedPhoenixQ closed 10 months ago

RedPhoenixQ commented 11 months ago

To do this, try_namespace_name now looks for nested namespaces. Because try_name'gets called, another Identmust be consumed to prevent and early return, which means that :: would not be valid, but a:b-c:d would be fine.

This allows for more custom attributes from different frameworks, specifically htmx's hx-on as mentioned in https://github.com/lambda-fairy/maud/issues/194#issuecomment-1734354727.

This is my first PR, I'll gladly take critique and make any changes necessary

fraschm1998 commented 11 months ago

Could you add support for alpine.js as well for '.':

x-on:scroll.window="showBar = (window.pageYOffset > 20) ? true : false"

RedPhoenixQ commented 11 months ago

Could you add support for alpine.js as well for '.':

x-on:scroll.window="showBar = (window.pageYOffset > 20) ? true : false"

I don't think this is easily done while keeping the class shorthand. Since the macro doesn't see whitespace foo.bar is the same as foo .bar which would be a valid attribute and then a class name via the shorthand.

The only way to do this would to somehow replace or escape the period . in the attribute name or add an escape character that would have to be a recognized Rust token. \ cannot be used as it isn't part of Rust syntax. Something like *. or ^. could work but isn't very elegant.

I don't want to make a change like class shorthand can only appear immediately after the element since that would be a breaking change.

fraschm1998 commented 11 months ago

Any idea how difficult it would be to add quoted attribute supported as mentioned here

RedPhoenixQ commented 11 months ago

Though about it and just tried it. I seem to have it working and will be making a new PR for that change, since it is not related to the changes in this PR.

RedPhoenixQ commented 11 months ago

396 Now fixes the same issue by allowing "literals"="true"

dacbd commented 11 months ago

Would like to see this feature too 👍 #396 would be just as good 👍