Sha256: 45263f2108c89c7dd48d98454575eeaba5f18070bffdbe951365d1e8ccb82c32

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

module SimpleNavigation
  module Renderer
    
    # 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 <tt>autogenerate_item_ids</tt> 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.
    class List < SimpleNavigation::Renderer::Base

      def render(item_container)
        list_content = item_container.items.inject([]) do |list, item|
          html_options = item.html_options
          li_content = link_to(html_safe(item.name), item.url, :class => item.selected_class, :method => item.method)
          if include_sub_navigation?(item)
            li_content << render_sub_navigation_for(item)
          end  
          list << content_tag(:li, li_content, html_options)
        end.join
        content_tag(:ul, html_safe(list_content), {:id => item_container.dom_id, :class => item_container.dom_class})
      end
    end
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple-navigation-2.5.4 lib/simple_navigation/renderer/list.rb
simple-navigation-2.5.3 lib/simple_navigation/renderer/list.rb
simple-navigation-2.5.2 lib/simple_navigation/renderer/list.rb
simple-navigation-2.5.1 lib/simple_navigation/renderer/list.rb
simple-navigation-2.5.0 lib/simple_navigation/renderer/list.rb