Sha256: 293999370056fb49704a946767c287d7611161f4074fe47a0a12b84ecbb0ceff

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# <https://github.com/gzigzigzeo/stateful_link>.
module Adminos::StatefulLink::Helper#:doc:
  # 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>"
  #  )
  #
  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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adminos-1.0.0.pre.rc.5 lib/adminos/stateful_link/helper.rb
adminos-1.0.0.pre.rc.4 lib/adminos/stateful_link/helper.rb
adminos-1.0.0.pre.rc.3 lib/adminos/stateful_link/helper.rb
adminos-1.0.0.pre.rc.2 lib/adminos/stateful_link/helper.rb
adminos-1.0.0.pre.rc.1 lib/adminos/stateful_link/helper.rb