Sha256: eda846e9e59525264697cfbb7a332dd267a6215ca05fcef11abf9a5e83c2f4a0
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
module StatefulLink module 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] || proc { action_state(active, chosen) } 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(¤t) : current end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stateful_link-0.0.8 | lib/stateful_link/helper.rb |
stateful_link-0.0.7 | lib/stateful_link/helper.rb |