Module: Merb::Helpers::Text
- Included in:
- GlobalHelpers
- Defined in:
- merb-helpers/lib/merb-helpers/text_helpers.rb
Instance Method Summary (collapse)
-
- (String) cycle(*values)
Allows you to cycle through elements in an array.
-
- (true?) reset_cycle(name = :default)
Reset a cycle.
Instance Method Details
- (String) cycle(*values)
Note:
Default name is :default.
Allows you to cycle through elements in an array.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'merb-helpers/lib/merb-helpers/text_helpers.rb', line 15 def cycle(*values) = (values) || {} key = ([:name] || :default).to_sym (@cycle_positions ||= {})[key] ||= {:position => -1, :values => values} unless values == @cycle_positions[key][:values] @cycle_positions[key] = {:position => -1, :values => values} end current = @cycle_positions[key][:position] @cycle_positions[key][:position] = current + 1 values.at( (current + 1) % values.length).to_s end |
- (true?) reset_cycle(name = :default)
TODO:
Docs, correctness, true/false would be better?
Note:
Default name is :default.
Reset a cycle.
42 43 44 45 |
# File 'merb-helpers/lib/merb-helpers/text_helpers.rb', line 42 def reset_cycle(name = :default) (@cycle_positions[name.to_sym] = nil) && true if @cycle_positions && @cycle_positions[name.to_sym] end |