From 1f5b360466c3494267cc9aad08a19d1ace4763d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Junstr=C3=B6m?= Date: Sun, 16 Sep 2012 22:45:08 +0200 Subject: Added PartialIteration class used when rendering collections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. [Joel Junström + Lucas Uyezu] --- actionpack/lib/action_view/partial_iteration.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 actionpack/lib/action_view/partial_iteration.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/partial_iteration.rb b/actionpack/lib/action_view/partial_iteration.rb new file mode 100644 index 0000000000..5b33a40722 --- /dev/null +++ b/actionpack/lib/action_view/partial_iteration.rb @@ -0,0 +1,19 @@ +module ActionView + class PartialIteration # :nodoc: + attr_reader :size, :index + + def initialize(size, index) + @size = size + @index = index + end + + def first? + index == 0 + end + + def last? + index == size - 1 + end + + end +end -- cgit v1.2.3