-
-
Notifications
You must be signed in to change notification settings - Fork 501
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
Support of Tailwind Arbitrary Classes #906
Comments
As a first step I removed square brackets from Slim::Engine.options[:attr_list_delims] = {
'(' => ')',
'{' => '}'
} But it still doesn't work. For example: |
You need at least also remove them from |
@bb Thanks, but but it still doesn't work. |
Yeah, sorry. Maybe I'll give it another try later but no plans for now. |
I couldn't stop myself and gave it another look: We'll need to change https://github.com/slim-template/slim/blob/main/lib/slim/parser.rb#L73 from
to include From what I can see right now, code_attr_delims doesn't matter, it's only used after end of attribute which cannot happen at these positions, so my previous comment was actually misleading. |
Haha, I know that feeling :) @attr_shortcut_re = /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/ I was looking at that line too but didn't understand it fully enough to suggest any changes. I'm happy to help test though. |
So setting
and and changing Line 73 to actually makes
and
That worked for me for a quick test, but actually, we can't just change L73 as I did above but need to add each (actual) letter out of As we're here anyway: we also need So now I'm at And it still isn't conditional on attr_list_delims and I don't know why usage of |
Neither worked with the previous state.
|
non_attr_chars = Regexp.escape ('"></='.split(//) + @attr_list_delims.flatten + @attr_shortcut.keys).uniq.join I see that |
You're right. I did some additional changes: Also needed to forbid the dynamic So this is the result:
The line assigning splat prefix was just moved up from the bottom of the function. Finally, this is the additional test:
I was afraid the whole thing might be a bit slower because of the two additional lookarounds, but I didn't see a benchmark to try it. Just looking at assertions/s from the test suite, they seem to be equal. I also noticed yet another thing which is not supported this way: classes However, I noticed another issue: Tailwinds content-class-finder (previously pruner) doesn't detect classes which start with So, if I have
I see font-bold and bg-cyan-300 as generated css classes but not the others. |
Well done getting all that to work.
Tailwind's test for slim templates doesn't check classes containing I cloned the Tailwind repo and tried to experiment but I couldn't get the tests to run at all.
Sounds like it. |
Running the tailwindcss tests worked fine for me. After cloning and Looking at this commit: https://github.com/tailwindlabs/tailwindcss/pull/8569/files#diff-4b945b54be020aaf62bfce1f632eb903751230a871fa1e87aa6b7f95c15b3d9dR94 - the "inner matches" regex in line 94 (which is line 119 in master) seems to be the one responsible for slim to work... but it also leads to overgenerating CSS. You can see that in the tests where "not contain pr-1" was removed after expecting "pr-1.5". I tried to modify it and also to duplicate it and additionally have similar rule to work with the new test cases I added, but I couldn't get it to work yet. Also, changes like adding So, I tried another path and basically changed all positions where a backtick was added to also add the dot. This broke all existing tests which contained a decimal value. Third variation: duplicate all those rules, one with and one without the dot. You see, I didn't even try to understand all of it. I was just pattern matching the match patterns 😃 This lead to only 8 failed tests, those where all others. I'm afraid it will be really, really complex to both split at I wonder if our mighty overlord @adamwathan would want to take a look here 👀. This is the current state: wip.patch |
@bb Phew, that's a lot of work! Perhaps a simpler approach would be for Slim to require "special" characters to be escaped in class names when used in a It would require updating both Slim and Tailwind, but hopefully just to match (and ignore) a backslash here and there. Well, it sounds straightforward :) In the meantime, |
Can we get support for Tailwind Arbitrary classes?
Ex:
div[class='p-1 border border-midnight-20 rounded-b-[3px]']
works finebut if we did
.p-1.border.border-midnight-20.rounded-b-[3px]
slim will not parse correctly.The text was updated successfully, but these errors were encountered: