On Tue, Apr 15, 2014 at 1:20 PM, Erik Dalén <[email protected]>wrote:

> 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.
>
>
I'm not too keen on this. I think that I'd rather keep the single way to do
it instead of branching out into various aliases for functionality.

I am considering Joshua's request for the concat function. It would provide
a way to emit text from within the embedded code in the template, and might
help in some situations. But it another case where it adds a bit of special
stuff to do something that that already be achieved with a little
refactoring.


> 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<https://groups.google.com/d/msgid/puppet-dev/CAAAzDLc_ZZxfrSfb5XjK6XTLqttcZDXFKG5Zc2a0BrLKMVs_3A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Andrew Parker
[email protected]
Freenode: zaphod42
Twitter: @aparker42
Software Developer

*Join us at PuppetConf 2014 <http://www.puppetconf.com/>, September
22-24 in San Francisco*
*Register by May 30th to take advantage of the Early Adopter discount
<http://links.puppetlabs.com/puppetconf-early-adopter> **—**save $349!*

-- 
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/CANhgQXvka6QBhdx2unib-6pW7nspTbeT0VEkKZ_ZVG3SpJOD1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to