[#91458] [Ruby trunk Feature#4475] default variable name for parameter — matz@...
Issue #4475 has been updated by matz (Yukihiro Matsumoto).
3 messages
2019/02/07
[ruby-core:91545] [Ruby trunk Feature#15538] Erb indenting / unindenting
From:
kimmo.lehto@...
Date:
2019-02-14 08:34:45 UTC
List:
ruby-core #91545
Issue #15538 has been updated by kke (Kimmo Lehto).
Description updated
Subject changed from Erb indenting / unindenting trim mode to Erb indenting / unindenting
Perhaps `<%~` would be good as it resembles the squiggly heredoc `<<~EOB`
I'll try to improve on your PoC.
It seems to only work when the `<%|` is in the beginning of the line, for anything else it fails. I have yet to find a way to find the index of `stag`, but I have a hunch it has to be done in the line scanner and yielded there.
Also, something like this should work:
```
<%= "abcd" %> <%~ [1.2.3].each do |num| -%>
<%= num %>
<%~ end -%>
```
which would produce:
```
abcd 1
2
3
```
----------------------------------------
Feature #15538: Erb indenting / unindenting
https://bugs.ruby-lang.org/issues/15538#change-76808
* Author: kke (Kimmo Lehto)
* Status: Third Party's Issue
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
In `Erb`, would it be possible to add a new tag that would indent the following content to match the depth of the tag? The tag could be `<%~` (to resemble the `<<~EOS` squiggy heredoc).
## Reason
Something like this would be easy to follow:
``` ruby
1
<%- [2, 3, 4].each do |num| -%>
<%- unless num == 3 -%>
<%= num %>
<%- end -%>
<%- end -%>
5
```
But unfortunately it will render with "extra" indentation:
```
1
2
4
5
```
Currently, to avoid this, you have to write your template using either no indentation:
```
1
<%- [2, 3, 4].each do |num| -%>
<%- unless num == 3 -%>
<%= num %>
<%- end -%>
<%- end -%>
5
```
Or a weird jumpy indentation:
```
1
<%- [2, 3, 4].each do |num| -%>
<%- unless num == 3 -%>
<%= num %>
<%- end -%>
<%- end -%>
5
```
With the `<%~` it could be written as:
```ruby
1
<%~ [2, 3, 4].each do |num| -%>
<%- unless num == 3 -%>
<%= num %>
<%- end -%>
<%~ end -%>
5
```
And it would output as desired without the "extra" indentation:
```
1
2
4
5
```
Another example:
```
<%= "abcd" %> <%~ [1.2.3].each do |num| -%>
<%= num %>
<%~ end -%>
```
would produce:
```
abcd 1
2
3
```
## Using with `=`
It would also be handy if the `~` could be used in `<%=` statements, perhaps as `<%~=`. This would be excellent for example when templating YAML's:
```yaml
<%- bars = %w(abc def)" -%>
foo:
bar:
<%~= bars.map { |bar| "- #{bar}\n" } %>
```
Which would reindent the statement outcome to produce something like:
```yaml
foo:
bar:
- abc
- def
```
This would require these new tags:
1. `<%~` begin a code block and begin or end reindentation mode. content produced inside the block will be reindented to the depth of the `<` character in `<%~`. If the indentation mode was already active due to a previous `<%~`, it ends the indentation mode.
2. `<%~=` like regular `<%=` but multiline strings will be reindented to the column of the `<` character
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>