Module: NavigationHelper

Defined in:
app/helpers/navigation_helper.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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)

:items - a list of hashes to be used as second-level navigation items



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/navigation_helper.rb', line 27

def nav_items(items)
  items.map do |item|
    if nav_item_authorized?(item)
      if item[:items]
         :li, class: 'nav-item dropdown' do
          raw(nav_link(item, has_children: true) +
              (:div,
                  item[:items].select { |i| nav_item_authorized?(i) }
                              .map { |i| nav_link(i, class: 'dropdown-item') }.join.html_safe,
                  class: 'dropdown-menu'))
        end
      else
        nav_item(item)
      end
    end
  end.join.html_safe
end


45
46
47
48
49
50
51
52
53
# File 'app/helpers/navigation_helper.rb', line 45

def sidebar(&block)
  content_for :sidebar do
     :div, class: 'sidebar' do
       :div, class: 'list-group' do
        capture(&block)
      end
    end
  end
end


55
56
57
# File 'app/helpers/navigation_helper.rb', line 55

def sidebar_header(text)
   :h3, text, class: 'sidebar-header'
end


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/navigation_helper.rb', line 59

def sidebar_item(opts = {}, &block)
  if perms = opts.delete(:perms)
    return nil if cannot?(*perms)
  end

  opts[:class] = '' if opts[:class].blank?
  opts[:class] += ' list-group-item list-group-item-action'
  opts[: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, 'fa-fw') << ' '
    end
    desc << opts.delete(:text).to_s
    link_to(desc.html_safe, opts.delete(:path), opts)
  end

  content
end