Sha256: a50c3f9b1e1ee68d5e995511d01a381855255eb21f04fb3dec701a6dd4605f43

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 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 Overview < SimpleNavigation::Renderer::Base

      OVERVIEW_PREFIX = 'overview'

      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 << content_tag(:li, li_content, modify_html_options(html_options))
        end.join
        if skip_if_empty? && item_container.empty?
          ''
        else
          content_tag(:ul, list_content, {:class => "#{OVERVIEW_PREFIX}-list level-#{item_container.level}"})
        end
      end

      private

      #
      # Modifies the html options
      #
      def modify_html_options(options)
        # Adds a prefix to the ids so that the ids not appear twice.
        options[:id] = "#{OVERVIEW_PREFIX}-#{options[:id]}"
        # Removes tooltip cause of w3c validation.
        options.delete(:tooltip)

        options
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bookyt-0.0.1 lib/simple_navigation/renderer/overview.rb