Module: NavigationHelper
- Defined in:
- app/helpers/navigation_helper.rb
Instance Method Summary collapse
-
#nav_items(items) ⇒ Object
expects an array of hashes with the following members: :content - usually a navigation link :active? - an optional function determining whether the respective item is currently active :controller - an optional string, used instead of ‘active?` to check for a specific controller :authorized? - an optional function determining whether the respective item is available to the current user (defaults to true).
- #sidebar(&block) ⇒ Object
- #sidebar_header(text) ⇒ Object
- #sidebar_item(opts = {}, &block) ⇒ Object
Instance Method Details
#nav_items(items) ⇒ Object
expects an array of hashes with the following members: :content - usually a navigation link :active? - an optional function determining whether the respective item is
currently active
:controller - an optional string, used instead of ‘active?` to check for a
specific controller
:authorized? - an optional function determining whether the respective item
is available to the current user (defaults to true)
11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/navigation_helper.rb', line 11 def nav_items(items) items.map do |item| if (not item[:authorized?]) || instance_eval(&item[:authorized?]) active = item[:active?] ? instance_eval(&item[:active?]) : (item[:controller] ? params[:controller] == item[:controller] : false) content_tag "li", instance_eval(&item[:content]), :class => ("active" if active) end end.join.html_safe end |
#sidebar(&block) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/navigation_helper.rb', line 22 def (&block) content_for :sidebar do content_tag :div, :class => 'well sidebar' do content_tag :ul, :class => 'nav nav-list' do capture(&block) end end end end |
#sidebar_header(text) ⇒ Object
32 33 34 |
# File 'app/helpers/navigation_helper.rb', line 32 def (text) content_tag :li, text, :class => 'nav-header' end |
#sidebar_item(opts = {}, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/navigation_helper.rb', line 36 def (opts = {}, &block) if perms = opts.delete(:perms) return nil if cannot?(*perms) end css_class = '' css_class << 'active' if opts.delete(:active) content = if block_given? capture(&block) else desc = ActiveSupport::SafeBuffer.new if icon = opts.delete(:icon) desc << icon(icon) << " " end desc << opts.delete(:text).to_s link_to(desc.html_safe, opts.delete(:path), opts) end content_tag :li, content, :class => css_class end |