Pre process Slim templates embedded in Ruby files#17336
Merged
RobinMalfait merged 8 commits intomainfrom Mar 24, 2025
Merged
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.
philipp-spiess
approved these changes
Mar 24, 2025
CHANGELOG.md
Outdated
| - 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)) |
Contributor
There was a problem hiding this comment.
looks like this was added to the 4.0.15 section too 🙈
Member
Author
There was a problem hiding this comment.
Woopsie, yep, fixed
| fast-glob = "0.4.3" | ||
| classification-macros = { path = "../classification-macros" } | ||
| regex = "1.11.1" | ||
| fancy-regex = "0.14.0" |
Contributor
There was a problem hiding this comment.
I'm not sure why the regex library alone is not enough?
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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_templateand asvelte_templateto prove that it embeds based on the language. I also added ahtml_templatewith Svelte syntax to really make sure that that doesn't work.