You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now the herb_extract_ruby method in extract.c is duplicated with a herb_extract_ruby_to_buffer_with_semicolons to have a version of the method that terminates the Ruby lines with semicolons.
In #98 we now updated the herb_extract_ruby and herb_extract_ruby_to_buffer_with_semicolons methods to ignore ERB Comment Nodes (<%#).
Ideally we only have one herb_extract_ruby method with two options so we can have all three versions of that functions available. The options would be:
bool semicolons (default: false)
bool comments (default: false)
The text was updated successfully, but these errors were encountered:
This pull request updates the `herb_extract_ruby` and
`herb_extract_ruby_to_buffer_with_semicolons` methods in `extract.c` to
not extract the content of ERB Comment Nodes (`<%#`) as Ruby code.
So a source file like this:
```html+erb
<%# This is a comment %>
<h1><%= title %></h1>
```
Was extracted to Ruby code as:
```ruby
# This is a comment
title
```
With the changes included in this pull request it's going to be:
```ruby
title
```
This is in order to resolve#91. It's valid to have multi-line ERB
Comments like:
```html+erb
<%#
This is
a comment
over multiple
lines
%>
```
Which before this pull request was extracted to Ruby as:
```ruby
#
This is
a comment
over multiple
lines
```
Which is not a valid Ruby comment anymore, but treated as actual Ruby
code from the second line on. If the comment itself included Ruby
keywords it would cause syntax errors.
For now, we don't extract the ERB Comments at all - which is the change
this pull request introduces.
In the future, we can implement #100 (and/or #102) and also make sure
that multi-line ERB Comments get extracted to multi-line Ruby Comments,
like:
```ruby
# This is
# a comment
# over multiple
# lines
```
or maybe even cleverer: replace the `<%` with a `=begin` and the `%>`
with a `=end`:
```ruby
=begin
This is
a comment
over multiple
lines
=end
```
Another case where it would break Ruby syntax is in this example:
```html+erb
<% if true %><%# Comment here %><% end %>
```
Which is going to comment out the `end` as well:
```ruby
if true # Comment here end
```
This use-case is also fixed with this pull request, since we just skip
over the ERB Comments content:
```ruby
if true end
```
This last example could be solved even more elegantly if Ruby shipped
the Inline Comments feature:
https://bugs.ruby-lang.org/issues/20405
This following example is still broken and this pull request does not
address that use-case. I opened #101 for this.
```html+erb
<% if true %><% # Comment here %><% end %>
```
Currently it does not address the case, where the comment is part of the
Ruby Code itself, so the comment is not seen as a "ERB Comment Node":
Right now the
herb_extract_ruby
method inextract.c
is duplicated with aherb_extract_ruby_to_buffer_with_semicolons
to have a version of the method that terminates the Ruby lines with semicolons.In #98 we now updated the
herb_extract_ruby
andherb_extract_ruby_to_buffer_with_semicolons
methods to ignore ERB Comment Nodes (<%#
).Ideally we only have one
herb_extract_ruby
method with two options so we can have all three versions of that functions available. The options would be:bool semicolons
(default:false
)bool comments
(default:false
)The text was updated successfully, but these errors were encountered: