File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 33use crate :: cursor;
44use crate :: extractor:: bracket_stack;
55use crate :: extractor:: pre_processors:: pre_processor:: PreProcessor ;
6+ use crate :: pre_process_input;
7+ use bstr:: ByteSlice ;
8+ use regex:: Regex ;
9+ use std:: sync;
10+
11+ static SLIM_TEMPLATE_REGEX : sync:: LazyLock < Regex > =
12+ sync:: LazyLock :: new ( || Regex :: new ( r#"<<[-~]SLIM\n([\s\S]*?)SLIM"# ) . unwrap ( ) ) ;
613
714#[ derive( Debug , Default ) ]
815pub struct Ruby ;
@@ -14,6 +21,18 @@ impl PreProcessor for Ruby {
1421 let mut cursor = cursor:: Cursor :: new ( content) ;
1522 let mut bracket_stack = bracket_stack:: BracketStack :: default ( ) ;
1623
24+ // Extract embedded Slim languages
25+ // https://viewcomponent.org/guide/templates.html#interpolations
26+ let content_as_str = std:: str:: from_utf8 ( content) . unwrap ( ) ;
27+ for ( _, [ body] ) in SLIM_TEMPLATE_REGEX
28+ . captures_iter ( content_as_str)
29+ . map ( |c| c. extract ( ) )
30+ {
31+ let replaced = pre_process_input ( body. as_bytes ( ) , "slim" ) ;
32+ result = result. replace ( body, replaced) ;
33+ }
34+
35+ // Ruby extraction
1736 while cursor. pos < len {
1837 // Looking for `%w` or `%W`
1938 if cursor. curr != b'%' && !matches ! ( cursor. next, b'w' | b'W' ) {
You can’t perform that action at this time.
0 commit comments