Module: StatefulLink::Helper
- Defined in:
- lib/stateful_link/helper.rb
Overview
:doc:
Instance Method Summary collapse
-
#stateful_link_to(*args) ⇒ Object
Generates stateful link to something.
Instance Method Details
#stateful_link_to(*args) ⇒ Object
Generates stateful link to something.
Options:
:inactive - template of inactive state (block or string).
:active - template of active state.
:chosen - template of chosen state.
:state - state (action_state called if none) - block, symbol or boolean
Any option may be proc.
Example:
stateful_link_to("foos#index", "bars#index",
:active => "<li class='active'>Good!</li>",
:chosen => "<li class='chosen'>#{link_to(...)}</li>"
)
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stateful_link/helper.rb', line 19 def stateful_link_to(*args) = args. active = args.first chosen = args.second state = [:state] state = proc { action_state(active, chosen) } if state.nil? state = state.is_a?(Proc) ? instance_exec(&state) : state state = :active if state == true state = :inactive if state == false current = [state] current.is_a?(Proc) ? instance_exec(¤t) : current end |