-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Pre process Slim
templates embedded in Ruby files
#17336
Conversation
5707e32
to
6c1963c
Compare
This builds on top of the regex but also has support for back references. Note: backreferences make it much slower than using the regex crate directly, but we need to make sure that the heredoc is properly closed.
We were hard coding `slim`, but with this change anything works. Verified it by adding a `svelte_template` test.
Let's make the captures lazy instead of greedy to capture as few characters as possible.
CHANGELOG.md
Outdated
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
- Increase Standalone hardware compatibility on macOS x64 builds ([#17267](https://github.com/tailwindlabs/tailwindcss/pull/17267)) | |||
- Ensure that the CSS file rebuilds if a new CSS variable is used from templates ([#17301](https://github.com/tailwindlabs/tailwindcss/pull/17301)) | |||
- Fix class extraction followed by `(` in Pug ([#17320](https://github.com/tailwindlabs/tailwindcss/pull/17320)) | |||
- Pre process `Slim` templates embedded in Ruby files ([#17336](https://github.com/tailwindlabs/tailwindcss/pull/17336)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this was added to the 4.0.15 section too 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woopsie, yep, fixed
@@ -19,6 +19,7 @@ bexpand = "1.2.0" | |||
fast-glob = "0.4.3" | |||
classification-macros = { path = "../classification-macros" } | |||
regex = "1.11.1" | |||
fancy-regex = "0.14.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why the regex
library alone is not enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use std::sync; | ||
|
||
static TEMPLATE_REGEX: sync::LazyLock<Regex> = sync::LazyLock::new(|| { | ||
Regex::new(r#"\s*(.*?)_template\s*<<[-~]?([A-Z]+?)\n([\s\S]*?)\2"#).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about \2
🤯
This PR fixes an issue where embedded Slim templates inside of Ruby files are not pre processed because we pre process based on a file extension.
This PR also handles embedded SLIM templates using the following syntax:
As far as I can tell, this is only a Slim template thing and not a Haml template thing but I could be wrong here. See: https://viewcomponent.org/guide/templates.html#interpolationsThe ViewComponent package handles anything that looks like
{lang}_template
, so the lang here will be used as the pre processing language for now.Fixes: #17334
Test plan
Added an example where we have a
slim_template
and asvelte_template
to prove that it embeds based on the language. I also added ahtml_template
with Svelte syntax to really make sure that that doesn't work.