lambda-fairy / maud

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

Tailwind class sorting #436

Open steadygaze opened 3 months ago

steadygaze commented 3 months ago

The Tailwind team created a prettier plugin that automatically sorts Tailwind utility classes in a defined order (https://tailwindcss.com/blog/automatic-class-sorting-with-prettier). This has the advantage of not having to think about what order the classes should be in, not having to keep them in the right order manually, and of compressing better if classes always appear in a consistent order.

I was wondering if there was a way to get something like that working in maud, or if it's infeasible. Sadly, doing it the "right" way by extending cargo fmt seems more on the infeasible side because it depends on https://github.com/rust-lang/rustfmt/issues/8, which would let library authors specify how their macros should be formatted.

In something like Askama, the templates look enough like HTML for prettier to work out of the box.

I guess maybe I can create an external program that does this if I care enough, even if that seems hacky.

Another solution I can think of is to reorder classes at compile time in maud, but that is also way too hacky and doesn't have the benefit of sorting them in source.

steadygaze commented 3 months ago

Actually, I think something like sorting the class names alphabetically in Maud's output is general enough to potentially justify adding to Maud, even if it doesn't do it in Tailwind's semantic ordering.