Skip to content
Merged
Prev Previous commit
Next Next commit
Replace comments in Ruby code
  • Loading branch information
thecrypticace committed Nov 12, 2025
commit 54617bc1d9f5cd6cbcd2d0d8364a1f09eea28d1d
33 changes: 33 additions & 0 deletions crates/oxide/src/extractor/pre_processors/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ impl PreProcessor for Ruby {
continue;
},

// Replace comments in Ruby files
b'#' => {
result[cursor.pos] = b' ';
cursor.advance();

while cursor.pos < len {
match cursor.curr {
// End of the comment
b'\n' => break,

// Everything else is part of the comment and replaced
_ => {
result[cursor.pos] = b' ';
cursor.advance();
},
};
}

cursor.advance();
continue;
},

_ => {}
}

Expand Down Expand Up @@ -224,6 +246,11 @@ mod tests {
// (not nested array).
(r#"%w[foo[bar baz]qux]"#, r#"%w foo[bar baz]qux "#),

(
"# test\n# test\n# {ActiveRecord::Base#save!}[rdoc-ref:Persistence#save!]\n%w[flex px-2.5]",
" \n \n \n%w flex px-2.5 "
),

(r#""foo # bar""#, r#""foo # bar""#),
(r#"'foo # bar'"#, r#"'foo # bar'"#),
(
Expand Down Expand Up @@ -262,6 +289,12 @@ mod tests {
"%w(flex data-[state=pending]:bg-(--my-color) flex-col)",
vec!["flex", "data-[state=pending]:bg-(--my-color)", "flex-col"],
),

(
"# test\n# test\n# {ActiveRecord::Base#save!}[rdoc-ref:Persistence#save!]\n%w[flex px-2.5]",
vec!["flex", "px-2.5"],
),

(r#""foo # bar""#, vec!["foo", "bar"]),
(r#"'foo # bar'"#, vec!["foo", "bar"]),
] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
.relative
^^^^^^^^
- # Blurred background star
^^^^^^^^^^ ^^^^
.absolute.left-0.z-0{ class: "-top-[400px] -right-[400px]" }
^^^^^^^^ ^^^^^^ ^^^ ^^^^^ ^^^^^^^^^^^^ ^^^^^^^^^^^^^^
.flex.justify-end.blur-3xl
Expand Down Expand Up @@ -196,7 +195,6 @@
^^^^^^^^ ^^^^ ^^^ ^^^^ ^^
:escaped
- # app/components/character_component.html.haml
^^^^
= part(:component) do
^^
= part(:head)
Expand Down