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

Added PartialIteration object used when rendering collections #7698

Closed
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
8 participants
@joeljunstrom
Contributor

joeljunstrom commented Sep 19, 2012

Based on the ideas in #5634 but refactored into an object as per the comments.

The iteration object is available as the local variable
"template_name_iteration" when rendering partials with collections.

It gives access to the +size+ of the collection beeing iterated over,
the current +index+ and two convinicence methods +first?+ and +last?+

For now the "template_name_counter" variable is kept but is deprecated.

@frodsan

This comment has been minimized.

Show comment
Hide comment
@frodsan
Contributor

frodsan commented Oct 26, 2012

@frodsan

View changes

Show outdated Hide outdated actionpack/test/controller/render_test.rb Outdated
@frodsan

View changes

Show outdated Hide outdated actionpack/test/controller/render_test.rb Outdated
@frodsan

View changes

Show outdated Hide outdated actionpack/lib/action_view/partial_iteration.rb Outdated
@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Oct 26, 2012

Contributor

Comments applied and rebased

Contributor

joeljunstrom commented Oct 26, 2012

Comments applied and rebased

@frodsan

This comment has been minimized.

Show comment
Hide comment
@frodsan

frodsan Oct 26, 2012

Contributor

Please squash your commits.

Contributor

frodsan commented Oct 26, 2012

Please squash your commits.

@lucasuyezu

This comment has been minimized.

Show comment
Hide comment
@lucasuyezu

lucasuyezu Nov 29, 2012

Contributor

+1 for this pull request. Since PartialIteration implements #index, I believe the best solution regarding variable_counter would be to print/log a deprecation warning and remove it in 4.1 or another release. I could try to implement this if you guys want. Also let me know if I can help with anything.

Contributor

lucasuyezu commented Nov 29, 2012

+1 for this pull request. Since PartialIteration implements #index, I believe the best solution regarding variable_counter would be to print/log a deprecation warning and remove it in 4.1 or another release. I could try to implement this if you guys want. Also let me know if I can help with anything.

@SKoschnicke

This comment has been minimized.

Show comment
Hide comment
@SKoschnicke

SKoschnicke Nov 29, 2012

+1. This would be a big improvement.

SKoschnicke commented Nov 29, 2012

+1. This would be a big improvement.

@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Nov 29, 2012

Contributor

@lucasuyezu In the current implementation the counter is just a local variable making it a bit awkward adding a deprecation warning when accessing it.

If you have ideas on a implementation I can give you access to my repo.

Contributor

joeljunstrom commented Nov 29, 2012

@lucasuyezu In the current implementation the counter is just a local variable making it a bit awkward adding a deprecation warning when accessing it.

If you have ideas on a implementation I can give you access to my repo.

@lucasuyezu

This comment has been minimized.

Show comment
Hide comment
@lucasuyezu

lucasuyezu Nov 29, 2012

Contributor

@joeljunstrom We can turn the counter into a method with the same name that prints/logs the deprecation warning and return the variable. I will clone your repo and implement it.

Contributor

lucasuyezu commented Nov 29, 2012

@joeljunstrom We can turn the counter into a method with the same name that prints/logs the deprecation warning and return the variable. I will clone your repo and implement it.

@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Nov 29, 2012

Contributor

Yea I just could'nt come up with what to put the method on =) Sounds good!

Contributor

joeljunstrom commented Nov 29, 2012

Yea I just could'nt come up with what to put the method on =) Sounds good!

@lucasuyezu

This comment has been minimized.

Show comment
Hide comment
@lucasuyezu

lucasuyezu Nov 29, 2012

Contributor

@joeljunstrom Done! Can I has repo acces?

Contributor

lucasuyezu commented Nov 29, 2012

@joeljunstrom Done! Can I has repo acces?

@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Nov 30, 2012

Contributor

@lucasuyezu sorry, I was sleeping =) You now have access!

Contributor

joeljunstrom commented Nov 30, 2012

@lucasuyezu sorry, I was sleeping =) You now have access!

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Nov 30, 2012

Member

@joeljunstrom @lucasuyezu guys, just ping me when done.

Thanks.

Member

rafaelfranca commented Nov 30, 2012

@joeljunstrom @lucasuyezu guys, just ping me when done.

Thanks.

@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Nov 30, 2012

Contributor

Will do

Contributor

joeljunstrom commented Nov 30, 2012

Will do

@lucasuyezu

This comment has been minimized.

Show comment
Hide comment
@lucasuyezu

lucasuyezu Dec 3, 2012

Contributor

@rafaelfranca Would you like to take a look now? I believe it is ok.

Contributor

lucasuyezu commented Dec 3, 2012

@rafaelfranca Would you like to take a look now? I believe it is ok.

@lucasuyezu

This comment has been minimized.

Show comment
Hide comment
@lucasuyezu

lucasuyezu Dec 5, 2012

Contributor

@joeljunstrom @rafaelfranca hello? Is anyone there? 😟

Contributor

lucasuyezu commented Dec 5, 2012

@joeljunstrom @rafaelfranca hello? Is anyone there? 😟

@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Dec 19, 2012

Contributor

@rafaelfranca & @lucasuyezu Sorry about the delay, I've rebased and squashed including lucasuyezu's additions (deprecating the use of the template_name_counter local. I'm a bit hesitant regarding the extra complexity surrounding the deprecation warning but maybe it does not matter much.

Contributor

joeljunstrom commented Dec 19, 2012

@rafaelfranca & @lucasuyezu Sorry about the delay, I've rebased and squashed including lucasuyezu's additions (deprecating the use of the template_name_counter local. I'm a bit hesitant regarding the extra complexity surrounding the deprecation warning but maybe it does not matter much.

@carlosantoniodasilva

View changes

Show outdated Hide outdated actionpack/lib/action_view/template.rb Outdated
@@ -0,0 +1,31 @@
require 'abstract_unit'
require 'action_view/partial_iteration'
class PartialIterationTest < ActiveSupport::TestCase

This comment has been minimized.

@carlosantoniodasilva

carlosantoniodasilva Dec 19, 2012

Member

Add space before this line, and remove space after class and before the last end (the class body).

@carlosantoniodasilva

carlosantoniodasilva Dec 19, 2012

Member

Add space before this line, and remove space after class and before the last end (the class body).

def last?
index == size - 1
end

This comment has been minimized.

@carlosantoniodasilva

carlosantoniodasilva Dec 19, 2012

Member

No need for empty line.

@carlosantoniodasilva

carlosantoniodasilva Dec 19, 2012

Member

No need for empty line.

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Dec 19, 2012

Member

Nice @joeljunstrom, I'd like to get this in for Rails 4 👍

Member

carlosantoniodasilva commented Dec 19, 2012

Nice @joeljunstrom, I'd like to get this in for Rails 4 👍

@josevalim

View changes

Show outdated Hide outdated actionpack/lib/action_view/template.rb Outdated
@mattgoldman

This comment has been minimized.

Show comment
Hide comment
@mattgoldman

mattgoldman Aug 1, 2013

any updates on this? is it pretty much good to go?

mattgoldman commented Aug 1, 2013

any updates on this? is it pretty much good to go?

@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Aug 2, 2013

Contributor

The problem is that getting this functionality with an deprecation warning for the old counter variable is as I see it pretty much impossible without adding (some what hard to follow) code to ActionView::Template without a major refactor of how locals are assigned to templates.

When looking at this again I have a hard time feeling the addition is worth hacking ActionView::Template.

So unless someone have a great idea of how to achieve this maybe we should close this for now 😕

Contributor

joeljunstrom commented Aug 2, 2013

The problem is that getting this functionality with an deprecation warning for the old counter variable is as I see it pretty much impossible without adding (some what hard to follow) code to ActionView::Template without a major refactor of how locals are assigned to templates.

When looking at this again I have a hard time feeling the addition is worth hacking ActionView::Template.

So unless someone have a great idea of how to achieve this maybe we should close this for now 😕

@lucasuyezu

This comment has been minimized.

Show comment
Hide comment
@lucasuyezu

lucasuyezu Aug 2, 2013

Contributor

The code is pretty much good to go, apart from the deprecation warning. I can revert it so this can ship, and prepare the deprecation warning on another pull request, if everybody agrees.

Contributor

lucasuyezu commented Aug 2, 2013

The code is pretty much good to go, apart from the deprecation warning. I can revert it so this can ship, and prepare the deprecation warning on another pull request, if everybody agrees.

joeljunstrom and others added some commits Sep 16, 2012

Added PartialIteration class used when rendering collections
The iteration object is available as the local variable
"template_name_iteration" when rendering partials with collections.

It gives access to the +size+ of the collection beeing iterated over,
the current +index+ and two convinicence methods +first?+ and +last?+

"template_name_counter" variable is kept but is deprecated.
@lucasuyezu

This comment has been minimized.

Show comment
Hide comment
@lucasuyezu

lucasuyezu Aug 3, 2013

Contributor

@joeljunstrom I have removed the deprecation warning. I also rebased the code based on the current rails master and fixed a spec that broke since then. Please let me know if there is any other thing blocking this.

Contributor

lucasuyezu commented Aug 3, 2013

@joeljunstrom I have removed the deprecation warning. I also rebased the code based on the current rails master and fixed a spec that broke since then. Please let me know if there is any other thing blocking this.

@joeljunstrom

This comment has been minimized.

Show comment
Hide comment
@joeljunstrom

joeljunstrom Aug 3, 2013

Contributor

I guess we should squash it and apply carlosantoniodasilva's formatting comments if I forgot to do it =)

Contributor

joeljunstrom commented Aug 3, 2013

I guess we should squash it and apply carlosantoniodasilva's formatting comments if I forgot to do it =)

@SKoschnicke

This comment has been minimized.

Show comment
Hide comment
@SKoschnicke

SKoschnicke Jul 16, 2014

What prevents this from being merged? Can I help?

SKoschnicke commented Jul 16, 2014

What prevents this from being merged? Can I help?

rafaelfranca added a commit that referenced this pull request Jul 16, 2014

Merge branch 'joeljunstrom-local-iterator-for-partial-collections'
Squash and merge #7698 doing some improvements to the original
implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment