Sha256: cc2cbd32dc72430dd8c59178c35cc652e08e31a5b600fee2e604ef27acfa5bed

Contents?: true

Size: 1.49 KB

Versions: 14

Compression:

Stored size: 1.49 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)
        if skip_if_empty? && item_container.empty?
          ''
        else
          tag = options[:ordered] ? :ol : :ul
          content = list_content(item_container)
          content_tag(tag, content, item_container.dom_attributes)
        end
      end

      private

      def list_content(item_container)
        item_container.items.map { |item|
          li_options = item.html_options.except(:link)
          li_content = tag_for(item)
          if include_sub_navigation?(item)
            li_content << render_sub_navigation_for(item)
          end
          content_tag(:li, li_content, li_options)
        }.join
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
simple-navigation-4.4.0 lib/simple_navigation/renderer/list.rb
simple-navigation-4.3.0 lib/simple_navigation/renderer/list.rb
simple-navigation-4.2.0 lib/simple_navigation/renderer/list.rb
simple-navigation-4.1.0 lib/simple_navigation/renderer/list.rb
simple-navigation-4.0.5 lib/simple_navigation/renderer/list.rb
simple-navigation-4.0.4 lib/simple_navigation/renderer/list.rb
simple-navigation-4.0.3 lib/simple_navigation/renderer/list.rb
simple-navigation-4.0.2 lib/simple_navigation/renderer/list.rb
simple-navigation-4.0.1 lib/simple_navigation/renderer/list.rb
simple-navigation-4.0.0 lib/simple_navigation/renderer/list.rb
simple-navigation-3.14.0 lib/simple_navigation/rendering/renderer/list.rb
simple-navigation-3.13.0 lib/simple_navigation/rendering/renderer/list.rb
simple-navigation-3.12.2 lib/simple_navigation/rendering/renderer/list.rb
simple-navigation-3.12.1 lib/simple_navigation/rendering/renderer/list.rb