cells icon indicating copy to clipboard operation
cells copied to clipboard

[suggestion] collection counter

Open dreyks opened this issue 9 years ago • 7 comments

Similar to rails providing item_counter variable for render partial: 'blah', collection: items, index could be passed as a parameter for cell method. This simplifies things for something (say javascripts) that has to be rendered only once for entire collection Cell::Collection#call almost has it, just needs to pass that index further

def call(state=:show)
  # original
  # join(@join) { |cell, i| cell.(@method || state) }.html_safe

  # proposed
  join(@join) { |cell, i| cell.(@method || state, i) }.html_safe
end

dreyks avatar Apr 25 '16 15:04 dreyks

In 4.1, this is implemented: https://github.com/apotonick/cells/blob/4d39f994e6dd288367e75d30cec2d30ac7e1aec6/test/public_test.rb#L70

Is that cool?

apotonick avatar Apr 25 '16 23:04 apotonick

so Cell::Collection#join is the public API? that's good then, waiting for that 4.1 to release. Thx

dreyks avatar Apr 26 '16 08:04 dreyks

ok, how is this supposed to look like in an erb template?

<%= cell('item', collection: @item).join do |cell, index| %>
  <% cell.(:show, first_call: index.zero?) %>
<% end.html_safe %>

Am I doing this right? Looks not particularly nice, especially because of the need of html_safe

dreyks avatar Apr 27 '16 10:04 dreyks

The html_safe shouldn't be necessary since that's done via cells-rails automatically. Other than that, what API would you like to have?

apotonick avatar Apr 27 '16 23:04 apotonick

Uhm, that gem does not exist yet, does it?

Other than that, would be nice if index was merged into options, passed to @cell_class#build, though you may consider this being too much magic)

dreyks avatar Apr 28 '16 08:04 dreyks

We actually thought of a "collection context object". We could totally do that, that's not really magic.

apotonick avatar Apr 28 '16 08:04 apotonick

:+1:

dreyks avatar Apr 28 '16 08:04 dreyks