I have the following entry in an erb
template:
# Lorem Ipsum...
<% unless @foo['bar'] == nil %>
<% @foo['bar'].each do |property, value| %>
<%= "zaz.#{property} #{value}" %>
<% end %>
<% end %>
That is parsed to:
# Lorem Ipsum...
zaz.property value
How can I remove the leading spaces so that lines are not indented in the resolved template?
I would like to avoid using something like:
# Lorem Ipsum...
<% unless @foo['bar'] == nil %>
<% @foo['bar'].each do |property, value| %>
<%= "zaz.#{property} #{value}" %>
<% end %>
<% end %>
The only solution I can offer is hackish adding <%- 'whatever here' %>
before the <%= %>
entry:
<% [1,2,3].each do |f| %>
<%- 1 %><%= f %>
<% end %>
it outputs in irb
irb(main):018:0> ERB.new(File.read('f.txt'), nil, '-').result
=> "\n1\n\n2\n\n3\n\n"
Rails doc claims, that default value for ERB trim_mode is -
http://edgeguides.rubyonrails.org/configuring.html#configuring-action-view
And according to https://www.systutorials.com/docs/linux/man/1-erb/ ERB should remove spaces before <%-
when -
mode is enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With