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
There are several related examples of this (kind of weird) pattern using capture to extract part of a template as a string to be passed into another template:
capture with do ... end for block and curly braces for template variable
Rails renders the template, but stree format raises a syntax error
ERB-snippet
<%= render 'shared/template', { greeting: capture do %><p>This block is captured as a string object and is available to the template as `greeting`</p><p>The date and time is <%= Time.now %></p><% end } do %><p>This content is displayed where the template `yield`s</p><% end %>
Actual formatting
Error: syntax error, unexpected end-of-input, expecting '}'
> 1 | <%= render 'shared/template', { greeting: capture do %>
| ^
2 | <p>This block is captured as a string object and is available to the template as `greeting`</p>
3 | <p>The date and time is <%= Time.now %></p>
4 | <% end } do %>
capture with { ... } for block and curly braces for template variable
Rails renders the template, but stree format raises a syntax error
ERB-snippet
<%= render 'shared/template', { greeting: capture { %><p>This block is captured as a string object and is available to the template as `greeting`</p><p>The date and time is <%= Time.now %></p><% } } do %><p>This content is displayed where the template `yield`s</p><% end %>
Actual formatting
Syntax error, even though Rails renders
Error: syntax error, unexpected end-of-input
> 1 | <%= render 'shared/template', { greeting: capture { %>
| ^
2 | <p>This block is captured as a string object and is available to the template as `greeting`</p>
3 | <p>The date and time is <%= Time.now %></p>
4 | <% } } do %>
capture with { ... } for block and no braces for template variable
Rails renders the template, but stree format raises a syntax error
ERB-snippet
<%= render 'shared/template', greeting: capture { %><p>This block is captured as a string object and is available to the template as `greeting`</p><p>The date and time is <%= Time.now %></p><% } do %><p>This content is displayed where the template `yield`s</p><% end %>
Actual formatting
Syntax error, even though Rails renders
Error: syntax error, unexpected end-of-input
> 1 | <%= render 'shared/template', greeting: capture { %>
| ^
2 | <p>This block is captured as a string object and is available to the template as `greeting`</p>
3 | <p>The date and time is <%= Time.now %></p>
4 | <% } do %>
capture with do ... end for block and no braces for template variable
The opposite issue. Rails raises a syntax error, but stree format formats successfully
ERB-snippet
<%= render 'shared/template', greeting: capture do %><p>This block is captured as a string object and is available to the template as `greeting`</p><p>The date and time is <%= Time.now %></p><% end do %><p>This content is displayed where the template `yield`s</p><% end %>
the Rails error is
SyntaxError: /<path>/app/views/capture.html.erb:4: syntax error, unexpected `do', expecting `end''.freeze; end do ^~/<path>/app/views/capture.html.erb:8: syntax error, unexpected `end', expecting end-of-input end ^~~
Actual formatting
"Successful" output of bundle exec stree format --plugins=erb app/views/capture.html.erb.
<%= render "shared/template", greeting: capture do %><p>This block is captured as a string object and is available to the template as `greeting`</p><p>The date and time is <%= Time.now %></p><% end do %><p>This content is displayed where the template `yield`s</p><% end %>
Expected formatting
Not 100% sure what the expected format should be, but I sort of like this:
<%= render 'shared/template', {
greeting: capture do %><p>This block is captured as a string object and is available to the template as `greeting`</p><p>The date and time is <%= Time.now %></p><% end
} do %><p>This content is displayed where the template `yield`s</p><% end %>
Comment
Had a couple examples of this in some legacy code I maintain. Also worth noting that this was hard to find at first because the syntax doesn't usually point to the correct location. It often (in my case) would point to line 3 even if the offending code was nowhere near there (e.g. around line 100+)
Versions
syntax_tree: 0.10.5
syntax_tree-erb: 6.1.1
The text was updated successfully, but these errors were encountered:
There are several related examples of this (kind of weird) pattern using
capture
to extract part of a template as a string to be passed into another template:capture
withdo ... end
for block and curly braces for template variableRails renders the template, but
stree format
raises a syntax errorERB-snippet
Actual formatting
capture
with{ ... }
for block and curly braces for template variableRails renders the template, but
stree format
raises a syntax errorERB-snippet
Actual formatting
Syntax error, even though Rails renderscapture
with{ ... }
for block and no braces for template variableRails renders the template, but
stree format
raises a syntax errorERB-snippet
Actual formatting
Syntax error, even though Rails renderscapture
withdo ... end
for block and no braces for template variableThe opposite issue. Rails raises a syntax error, but
stree format
formats successfullyERB-snippet
the Rails error is
Actual formatting
"Successful" output of
bundle exec stree format --plugins=erb app/views/capture.html.erb
.Expected formatting
Not 100% sure what the expected format should be, but I sort of like this:Comment
Had a couple examples of this in some legacy code I maintain. Also worth noting that this was hard to find at first because the syntax doesn't usually point to the correct location. It often (in my case) would point to line 3 even if the offending code was nowhere near there (e.g. around line 100+)
Versions
syntax_tree: 0.10.5
syntax_tree-erb: 6.1.1
The text was updated successfully, but these errors were encountered: