Not so much a DRYML thing, but ActiveSupport has a nice helper that
should get you most of the way across the finish line: in_groups_of.
An example:
irb --> h = {:a => 1, :b => 2, :c => 3, :d => 4, :e => 5}
==> {:d=>4, :a=>1, :b=>2, :e=>5, :c=>3}
irb --> h.to_a.in_groups_of(3)
==> [[[:d, 4], [:a, 1], [:b, 2]], [[:e, 5], [:c, 3], nil]]
The one tricky part is that in_groups_of doesn't work on hashes; you
may need some tweaks to whatever's generating the data if order is
important to you.
From there, note that it's possible to use <repeat> and friends on
arrays, which should tidy things up nicely. If you want to do
something nice to the last row, the DRYML "last_item?" helper may come
in handy.
An unrelated note: I really, really, *really* hope that $result is a
typo. Global variables are teh bad...
--Matt Jones
On Jun 19, 2010, at 7:47 PM, Togg wrote:
I have want to fill a table manually with some data. There should be
maximum of three columns to be filled, then a new row to be created.
The following dryml/erb combination doesnt seem to work, also I feel
its unneccessary complicated...
Is there something nicer to do this in dryml completely?
<table>
<% unless $result.nil? -%>
<tr>
<td>Items</td>
<% cnt_td = 1 %>
<% cnt_newtr = 0 %>
<% $result.each do |key, content| %>
<% if (cnt_td > 3) %>
<% if (cnt_newtr > 0) %>
</tr>
<%= cnt_newtr += -1 %>
<% end %>
<tr>
<% cnt_newtr += 1 %>
<% cnt_td = 0 %>
<% end %>
<td>
<% key %>
</a> (<%= number_to_human_size(content, :precision => 2)
%>)
</td>
<% cnt_td += 1 %>
<% end %>
<% if (cnt_newtr > 0) %></tr><% end %>
</tr>
<% end -%>
</table
Thanks,
Sebastian
--
You received this message because you are subscribed to the Google
Groups "Hobo Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]
.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en
.
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.