<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,7 @@
 *Edge*
 
+* Introduce current_cycle helper method to return the current value without bumping the cycle.  #417 [Ken Collins]
+
 * Allow polymorphic_url helper to take url options. #880 [Tarmo T&#228;nav]
 
 * Switched integration test runner to use Rack processor instead of CGI [Josh Peek]</diff>
      <filename>actionpack/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -448,8 +448,10 @@ module ActionView
       # array every time it is called. This can be used for example, to alternate
       # classes for table rows.  You can use named cycles to allow nesting in loops.
       # Passing a Hash as the last parameter with a &lt;tt&gt;:name&lt;/tt&gt; key will create a
-      # named cycle.  You can manually reset a cycle by calling reset_cycle and passing the
-      # name of the cycle.
+      # named cycle. The default name for a cycle without a +:name+ key is
+      # &lt;tt&gt;&quot;default&quot;&lt;/tt&gt;. You can manually reset a cycle by calling reset_cycle
+      # and passing the name of the cycle. The current cycle string can be obtained
+      # anytime using the current_cycle method.
       #
       # ==== Examples
       #   # Alternate CSS classes for even and odd numbers...
@@ -496,6 +498,23 @@ module ActionView
         return cycle.to_s
       end
 
+      # Returns the current cycle string after a cycle has been started. Useful
+      # for complex table highlighing or any other design need which requires
+      # the current cycle string in more than one place.
+      #
+      # ==== Example
+      #   # Alternate background colors
+      #   @items = [1,2,3,4]
+      #   &lt;% @items.each do |item| %&gt;
+      #     &lt;div style=&quot;background-color:&lt;%= cycle(&quot;red&quot;,&quot;white&quot;,&quot;blue&quot;) %&gt;&quot;&gt;
+      #       &lt;span style=&quot;background-color:&lt;%= current_cycle %&gt;&lt;%= item %&gt;&lt;/span&gt;
+      #     &lt;/div&gt;
+      #   &lt;% end %&gt;
+      def current_cycle(name = &quot;default&quot;)
+        cycle = get_cycle(name)
+        cycle.current_value unless cycle.nil?
+      end
+
       # Resets a cycle so that it starts from the first element the next time
       # it is called. Pass in +name+ to reset a named cycle.
       #
@@ -532,11 +551,29 @@ module ActionView
           @index = 0
         end
 
+        def current_value
+          @values[previous_index].to_s
+        end
+
         def to_s
           value = @values[@index].to_s
-          @index = (@index + 1) % @values.size
+          @index = next_index
           return value
         end
+
+        private
+
+        def next_index
+          step_index(1)
+        end
+
+        def previous_index
+          step_index(-1)
+        end
+
+        def step_index(n)
+          (@index + n) % @values.size
+        end
       end
 
       private</diff>
      <filename>actionpack/lib/action_view/helpers/text_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -369,6 +369,40 @@ class TextHelperTest &lt; ActionView::TestCase
     assert_equal(&quot;red&quot;, cycle(&quot;red&quot;, &quot;blue&quot;, :name =&gt; &quot;colors&quot;))
   end
 
+  def test_current_cycle_with_default_name
+    cycle(&quot;even&quot;,&quot;odd&quot;)
+    assert_equal &quot;even&quot;, current_cycle
+    cycle(&quot;even&quot;,&quot;odd&quot;)
+    assert_equal &quot;odd&quot;, current_cycle
+    cycle(&quot;even&quot;,&quot;odd&quot;)
+    assert_equal &quot;even&quot;, current_cycle
+  end
+
+  def test_current_cycle_with_named_cycles
+    cycle(&quot;red&quot;, &quot;blue&quot;, :name =&gt; &quot;colors&quot;)
+    assert_equal &quot;red&quot;, current_cycle(&quot;colors&quot;)
+    cycle(&quot;red&quot;, &quot;blue&quot;, :name =&gt; &quot;colors&quot;)
+    assert_equal &quot;blue&quot;, current_cycle(&quot;colors&quot;)
+    cycle(&quot;red&quot;, &quot;blue&quot;, :name =&gt; &quot;colors&quot;)
+    assert_equal &quot;red&quot;, current_cycle(&quot;colors&quot;)
+  end
+
+  def test_current_cycle_safe_call
+    assert_nothing_raised { current_cycle }
+    assert_nothing_raised { current_cycle(&quot;colors&quot;) }
+  end
+
+  def test_current_cycle_with_more_than_two_names
+    cycle(1,2,3)
+    assert_equal &quot;1&quot;, current_cycle
+    cycle(1,2,3)
+    assert_equal &quot;2&quot;, current_cycle
+    cycle(1,2,3)
+    assert_equal &quot;3&quot;, current_cycle
+    cycle(1,2,3)
+    assert_equal &quot;1&quot;, current_cycle
+  end
+
   def test_default_named_cycle
     assert_equal(&quot;1&quot;, cycle(1, 2, 3))
     assert_equal(&quot;2&quot;, cycle(1, 2, 3, :name =&gt; &quot;default&quot;))</diff>
      <filename>actionpack/test/template/text_helper_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e42a235dd18a39ccc83382365088de96f24fa236</id>
    </parent>
  </parents>
  <author>
    <name>Ken Collins</name>
    <login></login>
    <email>ken@metaskills.net</email>
  </author>
  <url>http://github.com/rails/rails/commit/f277e1d8fddfa417104c6fe095c15559f0c8713d</url>
  <id>f277e1d8fddfa417104c6fe095c15559f0c8713d</id>
  <committed-date>2008-08-27T23:06:20-07:00</committed-date>
  <authored-date>2008-06-14T11:06:27-07:00</authored-date>
  <message>Added TextHelper#current_cycle to return the current cycle for better design options.

[#417 state:resolved]

Signed-off-by: Jeremy Kemper &lt;jeremy@bitsweat.net&gt;</message>
  <tree>39865611a3e8b3b8d3df441c1c646dad30c03edb</tree>
  <committer>
    <name>Jeremy Kemper</name>
    <login>jeremy</login>
    <email>jeremy@bitsweat.net</email>
  </committer>
</commit>
