Class: SimpleNavigation::Renderer::BootstrapTopbarList

Inherits:
Base
  • Object
show all
Defined in:
lib/shoehorn/plugins/simple_navigation/renderer/bootstrap_topbar_list.rb

Overview

Renders an ItemContainer as a <ul> element and its containing items as <li> elements. Prepared to use inside the topbar of Twitter Bootstrap twitter.github.com/bootstrap/#navigation

Examples

render_navigation(level: 1..2, renderer: :bootstrap_topbar_list, expand_all: true)

Instance Method Summary collapse

Instance Method Details

#render(item_container) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shoehorn/plugins/simple_navigation/renderer/bootstrap_topbar_list.rb', line 9

def render(item_container)
  if options[:is_subnavigation]
    ul_class = "dropdown-menu"
  else
    ul_class = "nav"
  end

  list_content = item_container.items.inject([]) do |list, item|
    li_options = item.html_options.reject {|k, v| k == :link}
    if include_sub_navigation?(item)
      li_options[:class] = [li_options[:class], "dropdown"].flatten.compact.join(' ')
    end
    li_content = tag_for(item)
    if include_sub_navigation?(item)
      li_content << render_sub_navigation_for(item)
    end
    list << (:li, li_content, li_options)
  end.join
  if skip_if_empty? && item_container.empty?
    ''
  else
    (:ul, list_content, { :id => item_container.dom_id, :class => [item_container.dom_class, ul_class].flatten.compact.join(' ') })
  end
end

#render_sub_navigation_for(item) ⇒ Object



34
35
36
# File 'lib/shoehorn/plugins/simple_navigation/renderer/bootstrap_topbar_list.rb', line 34

def render_sub_navigation_for(item)
  item.sub_navigation.render(self.options.merge(:is_subnavigation => true))
end