Skip to content

Commit 669c7a2

Browse files
committed
handle %w… in Slim templates
1 parent 2fd7c8d commit 669c7a2

File tree

1 file changed

+47
-0
lines changed
  • crates/oxide/src/extractor/pre_processors

1 file changed

+47
-0
lines changed

crates/oxide/src/extractor/pre_processors/slim.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ impl PreProcessor for Slim {
5656
}
5757
}
5858

59+
// Handle Ruby syntax with `%w[]` arrays embedded in Slim directly.
60+
//
61+
// E.g.:
62+
//
63+
// ```
64+
// div [
65+
// class=%w[bg-blue-500 w-10 h-10]
66+
// ]
67+
// ```
68+
b'%' if matches!(cursor.next, b'w' | b'W')
69+
&& matches!(cursor.input.get(cursor.pos + 2), Some(b'[' | b'(' | b'{')) =>
70+
{
71+
result[cursor.pos] = b' '; // Replace `%`
72+
cursor.advance();
73+
result[cursor.pos] = b' '; // Replace `w`
74+
cursor.advance();
75+
result[cursor.pos] = b' '; // Replace `[` or `(` or `{`
76+
bracket_stack.push(cursor.curr);
77+
cursor.advance(); // Move past the bracket
78+
continue;
79+
}
80+
5981
// Any `[` preceded by an alphanumeric value will not be part of a candidate.
6082
//
6183
// E.g.:
@@ -281,4 +303,29 @@ mod tests {
281303
"#;
282304
Slim::test_extract_contains(input, vec!["flex", "items-center"]);
283305
}
306+
307+
// https://github.com/tailwindlabs/tailwindcss/issues/17542
308+
#[test]
309+
fn test_embedded_ruby_percent_w_extraction() {
310+
let input = r#"
311+
div[
312+
class=%w[bg-blue-500 w-10 h-10]
313+
]
314+
div[
315+
class=%w[w-10 bg-green-500 h-10]
316+
]
317+
"#;
318+
319+
let expected = r#"
320+
div
321+
class= bg-blue-500 w-10 h-10]
322+
]
323+
div
324+
class= w-10 bg-green-500 h-10]
325+
]
326+
"#;
327+
328+
Slim::test(input, expected);
329+
Slim::test_extract_contains(input, vec!["bg-blue-500", "bg-green-500", "w-10", "h-10"]);
330+
}
284331
}

0 commit comments

Comments
 (0)