Module: StatefulLink::Helper

Defined in:
lib/stateful_link/helper.rb

Overview

:doc:

Instance Method Summary collapse

Instance Method Details

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 => "

  • Good!
  • ", :chosen => "
  • #StatefulLink::Helper.link_to(..link_to(...)
  • " )

    
    
    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)
      options = args.extract_options!
      active = args.first
      chosen = args.second
      state = options[: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 = options[state]
      current.is_a?(Proc) ? instance_exec(&current) : current
    end