Open caikan opened 2 years ago
Any progress in this problem?
Doesn't the escaping kill the readability? wouldn't div(class='w-1/2 text-#00f')
be better?
Doesn't the escaping kill the readability? wouldn't
div(class='w-1/2 text-#00f')
be better?
If you have a lot of escaped class literals, yes.
But in simpler cases it helps avoid clutter imho. Compare these two definitions of the same div:
.my-3rem.mx-auto.w-60\%
div(class="my-3rem mx-auto w-60%")
The only problem is the %
-Symbol, and a \
there doesn’t hurt readability in any significant way.
Part of what makes pug great for me is being able to quickly differentiate between classes/styling and functional parts of tags, as well as structural and functional components. This is mostly accomplished by the class literals syntax.
.h-csreen.flex.justify-center
.max-w-25rem.w-full
.my-3rem.mx-auto.w-60%
img(:src="logo")
button.btn.btn-primary(@click="visitPage()") Take me there!
Here I can quickly tell what parts are there just for layout and styling, and what is actual content, mostly due to syntax highlighting. Most of the time, I use this deliberately, too. If I have a div
which also serves some kind of purpose other than layouting, I use div.class-1.class-2
to indicate its function.
tl;dr - I support escaping of class literals, when used sparingly it can greatly improve readability and discoverability of code over using attributes on elements.
@tgrelka couldn't you solve the issue by just being explicit about what the div is?
.base-layout(class='h-csreen flex justify-center')
.content-layout(class='max-w-25rem w-full')
.card(class='my-3rem mx-auto w-60%')
img(:src="logo")
button(class='btn btn-primary' @click="visitPage()") Take me there!
@blazmrak I appreciate your input.
It does not solve anything in my view however, as I have said previously:
I think our workflows simply are different. I work with a mix of Bootstrap (for styling components) and atomic CSS for utilities. Elements which carry any semantic value are named appropriately, like card
- which is an actual bootstrap card, but the whole point of atomic CSS is to not be explicit about what an element is.
What I don’t understand is why you are arguing agains the option to escape characters in pug - would that harm your workflows in any way?
I support this proposal for extending "class literals" syntax, as it will solve a common headache for developers using Tailwindcss:
Pug Version: 3.0.2
Node Version: 14
Input Pug
Expected HTML
Actual HTML
Additional Comments
This will be very useful when using pug with TailwindCSS/WindiCSS.