Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suggestion] collection counter #392

Open
dreyks opened this issue Apr 25, 2016 · 7 comments
Open

[suggestion] collection counter #392

dreyks opened this issue Apr 25, 2016 · 7 comments

Comments

@dreyks
Copy link

dreyks commented Apr 25, 2016

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
@apotonick
Copy link
Member

@dreyks
Copy link
Author

dreyks commented Apr 26, 2016

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

@dreyks dreyks closed this as completed Apr 26, 2016
@dreyks
Copy link
Author

dreyks commented Apr 27, 2016

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 dreyks reopened this Apr 27, 2016
@apotonick
Copy link
Member

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?

@dreyks
Copy link
Author

dreyks commented Apr 28, 2016

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)

@apotonick
Copy link
Member

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

@dreyks
Copy link
Author

dreyks commented Apr 28, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants