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
44
45
46
47
48
# File 'app/helpers/navigation_helper.rb', line 27

def nav_items(items)
  items.map do |item|
    if !item.has_key?(:authorized?) || instance_eval(&item[:authorized?])
      if item[:items]
         :li, class: 'nav-item dropdown' do
          raw(link_to(element_value(item[:text]).html_safe +
                  (:i), '#',
                  class: 'nav-link dropdown-toggle',
                  role: 'button',
                  'aria-haspopup': true,
                  'aria-expanded': false,
                  data: { toggle: 'dropdown' }) +
              (:div,
                  item[:items].map { |i| dropdown_nav_item(i) }.join.html_safe,
                  class: 'dropdown-menu'))
        end
      else
        nav_item(item)
      end
    end
  end.join.html_safe
end


50
51
52
53
54
55
56
57
58
# File 'app/helpers/navigation_helper.rb', line 50

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


60
61
62
# File 'app/helpers/navigation_helper.rb', line 60

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


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/navigation_helper.rb', line 64

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