Class: SimpleNavigation::Renderer::Overview

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_navigation/renderer/overview.rb

Overview

Renders an ItemContainer as a <ul> element and its containing items as <li> elements. It adds the ‘selected’ class to li element AND the link inside the li element that is currently active.

If the sub navigation should be included (based on the level and expand_all options), it renders another <ul> containing the sub navigation inside the active <li> element.

By default, the renderer sets the item’s key as dom_id for the rendered <li> element unless the config option autogenerate_item_ids is set to false. The id can also be explicitely specified by setting the id in the html-options of the ‘item’ method in the config/navigation.rb file.

Constant Summary collapse

OVERVIEW_PREFIX =
'overview'

Instance Method Summary collapse

Instance Method Details

#render(item_container) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_navigation/renderer/overview.rb', line 15

def render(item_container)
  list_content = item_container.items.inject([]) do |list, item|
    html_options = item.html_options
    li_content = link_to(item.name, item.url, :class => item.selected_class, :method => item.method, :title => html_options[:tooltip])
    if include_sub_navigation?(item)
      li_content << render_sub_navigation_for(item)
    end
    list << (:li, li_content, modify_html_options(html_options))
  end.join
  if skip_if_empty? && item_container.empty?
    ''
  else
    (:ul, list_content, {:class => "#{OVERVIEW_PREFIX}-list level-#{item_container.level}"})
  end
end