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
-
#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) :items - a list of hashes to be used as second-level navigation items.
- #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)
: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 |
# 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] content_tag :li, class: 'dropdown' do raw(link_to(element_value(item[:text]).html_safe + content_tag(:b, nil, class: 'caret'), '#', class: 'dropdown-toggle', data: { toggle: 'dropdown' }) + content_tag(:ul, item[:items].map { |i| nav_item(i) }.join.html_safe, class: 'dropdown-menu')) end else nav_item(item) end end end.join.html_safe end |
#sidebar(&block) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/navigation_helper.rb', line 47 def (&block) content_for :sidebar do content_tag :div, class: 'sidebar' do content_tag :div, class: 'list-group' do capture(&block) end end end end |
#sidebar_header(text) ⇒ Object
57 58 59 |
# File 'app/helpers/navigation_helper.rb', line 57 def (text) content_tag :h4, text, class: 'sidebar-header' end |
#sidebar_item(opts = {}, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/navigation_helper.rb', line 61 def (opts = {}, &block) if perms = opts.delete(:perms) return nil if cannot?(*perms) end opts[:class] = '' if opts[:class].blank? opts[:class] += ' list-group-item' 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) << ' ' end desc << opts.delete(:text).to_s link_to(desc.html_safe, opts.delete(:path), opts) end content end |