Another way to improve it would be if the % and-or <> flags were passed to the ERB builder. % enables Ruby code processing for lines beginning with %. <> omit newline for lines starting with <% and ending in %>. They would allow you to skip a lot of the <%- -%> tags.
Obviously this would be a backwards incompatible change for the regular template function. But for EPP we could do it. On 15 April 2014 21:28, John Bollinger <[email protected]> wrote: > > > On Tuesday, April 15, 2014 1:38:53 PM UTC-5, Joshua Hoblitt wrote: >> >> I see the "Non Goals" section at the top of the arm but... >> >> The biggest frustration I have with ERB is when you end up needing >> nested flow control logic. As example, to walk through a >> hash/array/etc. nested inside some conditional logic. The result is an >> eye gouging mix of nested <% ... %> and <% end %> tags that are either >> unindented or you have have to salt all the tags with -'s to try and >> properly eat the whitespace. >> >> Here's a snippet from a template I was working on yesterday: >> >> ``` >> <% if megaraid_device and megaraid_device != '' and >> @megaraid_adapters and @megaraid_adapters.to_i > 0 -%> >> <%- unless @megaraid_physical_drives_sata.nil? -%> >> <%- @megaraid_physical_drives_sata.split(/,/).sort.each do >> |drive| -%> >> <%= megaraid_device %> -d sat+megaraid,<%= drive.to_i -%> >> <%- if megaraid_options %><%= ' ' + megaraid_options %><% end >> %> >> <%- end -%> >> <%- end -%> >> <%- unless @megaraid_physical_drives_sas.nil? -%> >> <%- @megaraid_physical_drives_sas.split(/,/).sort.each do >> |drive| -%> >> <%= megaraid_device %> -d megaraid,<%= drive.to_i -%> >> <%- if megaraid_options %><%= ' ' + megaraid_options %><% end >> %> >> <%- end -%> >> <%- end -%> >> <% end -%> >> ``` >> >> > > You are complaining about a problem partially of your own making: you > break up the Ruby a lot more than you need to do. Obviously you *can* do > it like that, but why? > > Here's an alternative that I like a lot better: > > <% > if megaraid_device and megaraid_device != '' and > @megaraid_adapters and @megaraid_adapters.to_i > 0 > option_str = (megaraid_options ? ' ' + megaraid_options : '') > unless @megaraid_physical_drives_sata.nil? > @megaraid_physical_drives_sata.split(/,/).sort.each do |drive| > -%> > <%= megaraid_device %> -d sat+megaraid,<%= drive.to_i %><%= option_str %> > <% > end > end > unless @megaraid_physical_drives_sas.nil? > @megaraid_physical_drives_sas.split(/,/).sort.each do |drive| > -%> > <%= megaraid_device %> -d megaraid,<%= drive.to_i %><%= option_str %> > <% > end > end > end > -%> > > > Or I don't like this one as much, but it's still better than what you > started with: > > <% if megaraid_device and megaraid_device != '' and @megaraid_adapters and > @megaraid_adapters.to_i > 0 -%> > <% unless @megaraid_physical_drives_sata.nil? -%> > <% @megaraid_physical_drives_sata.split(/,/).sort.each do |drive| > -%> > <%= megaraid_device %> -d sat+megaraid,<%= drive.to_i -%> > <% if megaraid_options %><%= ' ' + megaraid_options %><% end %> > <% end -%> > <% end -%> > <% unless @megaraid_physical_drives_sas.nil? -%> > <% @megaraid_physical_drives_sas.split(/,/).sort.each do |drive| > -%> > <%= megaraid_device %> -d megaraid,<%= drive.to_i -%> > <% if megaraid_options %><%= ' ' + megaraid_options %><% end %> > <% end -%> > <% end -%> > <% end -%> > > > John > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-dev/3c46642a-5ede-42e5-ac69-7a8ac438ea43%40googlegroups.com<https://groups.google.com/d/msgid/puppet-dev/3c46642a-5ede-42e5-ac69-7a8ac438ea43%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Erik Dalén -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/CAAAzDLc_ZZxfrSfb5XjK6XTLqttcZDXFKG5Zc2a0BrLKMVs_3A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
