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
```html
<%= render 'shared/template', { greeting: capture do %>
This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end } do %>
This content is displayed where the template `yield`s
<% end %>
```
Actual formatting
```html
Error: syntax error, unexpected end-of-input, expecting '}'
> 1 | <%= render 'shared/template', { greeting: capture do %>
| ^
2 |
This block is captured as a string object and is available to the template as `greeting`
3 |
The date and time is <%= Time.now %>
4 | <% end } do %>
```
capture with { ... } for block and curly braces for template variable
Rails renders the template, but stree format raises a syntax error
This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% } do %>
This content is displayed where the template `yield`s
<% end %>
```
Actual formatting
Syntax error, even though Rails renders
```html
Error: syntax error, unexpected end-of-input
> 1 | <%= render 'shared/template', greeting: capture { %>
| ^
2 |
This block is captured as a string object and is available to the template as `greeting`
3 |
The date and time is <%= Time.now %>
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
```html
<%= render 'shared/template', greeting: capture do %>
This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end do %>
This content is displayed where the template `yield`s
<% end %>
```
the Rails error is
```sh
SyntaxError: //app/views/capture.html.erb:4: syntax error, unexpected `do', expecting `end'
'.freeze; end do
^~
//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`.
```html
<%= render "shared/template", greeting: capture do %>
This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end do %>
This content is displayed where the template `yield`s
<% end %>
```
Expected formatting
Not 100% sure what the expected format should be, but I sort of like this:
```html
<%= render 'shared/template', {
greeting: capture do %>
This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end
} do %>
This content is displayed where the template `yield`s
<% 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+)
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
```html <%= render 'shared/template', { greeting: capture do %>This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end } do %>This content is displayed where the template `yield`s
<% end %> ```Actual formatting
```html Error: syntax error, unexpected end-of-input, expecting '}' > 1 | <%= render 'shared/template', { greeting: capture do %> | ^ 2 |This block is captured as a string object and is available to the template as `greeting`
3 |The date and time is <%= Time.now %>
4 | <% end } do %> ```capture
with{ ... }
for block and curly braces for template variableRails renders the template, but
stree format
raises a syntax errorERB-snippet
```html <%= render 'shared/template', { greeting: capture { %>This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% } } do %>This content is displayed where the template `yield`s
<% end %> ```Actual formatting
Syntax error, even though Rails renders ```html Error: syntax error, unexpected end-of-input > 1 | <%= render 'shared/template', { greeting: capture { %> | ^ 2 |This block is captured as a string object and is available to the template as `greeting`
3 |The date and time is <%= Time.now %>
4 | <% } } do %> ```capture
with{ ... }
for block and no braces for template variableRails renders the template, but
stree format
raises a syntax errorERB-snippet
```html <%= render 'shared/template', greeting: capture { %>This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% } do %>This content is displayed where the template `yield`s
<% end %> ```Actual formatting
Syntax error, even though Rails renders ```html Error: syntax error, unexpected end-of-input > 1 | <%= render 'shared/template', greeting: capture { %> | ^ 2 |This block is captured as a string object and is available to the template as `greeting`
3 |The date and time is <%= Time.now %>
4 | <% } do %> ```capture
withdo ... end
for block and no braces for template variableThe opposite issue. Rails raises a syntax error, but
stree format
formats successfullyERB-snippet
```html <%= render 'shared/template', greeting: capture do %>This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end do %>This content is displayed where the template `yield`s
<% end %> ``` the Rails error is ```sh SyntaxError: /Actual formatting
"Successful" output of `bundle exec stree format --plugins=erb app/views/capture.html.erb`. ```html <%= render "shared/template", greeting: capture do %>This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end do %>This content is displayed where the template `yield`s
<% end %> ```Expected formatting
Not 100% sure what the expected format should be, but I sort of like this: ```html <%= render 'shared/template', { greeting: capture do %>This block is captured as a string object and is available to the template as `greeting`
The date and time is <%= Time.now %>
<% end } do %>This content is displayed where the template `yield`s
<% 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