Sha256: 31fc839dc8be309dea9aace44b35278dcaec0441c8963631cc67d3e931d737c9
Contents?: true
Size: 1.67 KB
Versions: 12
Compression:
Stored size: 1.67 KB
Contents
module NavigationHelper # 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) 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 def sidebar(&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 def sidebar_header(text) content_tag :li, text, :class => 'nav-header' end 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 content_tag :li, content, :class => css_class end end
Version data entries
12 entries across 12 versions & 1 rubygems