Module: NavigationHelper

Defined in:
app/helpers/navigation_helper.rb

Instance Method Summary collapse

Instance Method Details

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)

       "li", instance_eval(&item[:content]),
          :class => ("active" if active)
    end
  end.join.html_safe
end


22
23
24
25
26
27
28
29
30
# File 'app/helpers/navigation_helper.rb', line 22

def sidebar(&block)
  content_for :sidebar do
     :div, :class => 'well sidebar' do
       :ul, :class => 'nav nav-list' do
        capture(&block)
      end
    end
  end
end


32
33
34
# File 'app/helpers/navigation_helper.rb', line 32

def sidebar_header(text)
   :li, text, :class => 'nav-header'
end


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 sidebar_item(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

   :li, content, :class => css_class
end