Sha256: e13885864fb2aa5155625f6c36edafb9f8c75117909137e10a6ae3e4dfd7e635

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

module RocketNavigation
  module Renderer
    # Renders an ItemContainer as a <div> element and its containing items as
    # <a> elements.
    # It adds the 'selected' class to the <a> element that is currently active.
    #
    # The Links renderer cannot be used to render nested navigations. If you
    # would like it to use with nested navigations, you have to render each
    # level separately.
    #
    # By default, the renderer sets the item's key as dom_id for the rendered
    # <a> 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.
    # The ItemContainer's dom_attributes are applied to the surrounding <div>
    # element.
    class Links < RocketNavigation::Renderer::Base
      def render(item_container)
        div_content = ActiveSupport::SafeBuffer.new
        item_container.items.each_with_index do |item, index|
          div_content << tag_for(item)
          unless index == item_container.items.length - 1
            div_content << join_with
          end
        end
        content_tag :div, div_content, container_html
      end

      def join_with
        @join_with ||= options[:join_with] || ''.html_safe
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rocket_navigation-0.3.3 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.3.2 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.3.1 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.3.0 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.2.3 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.2.2 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.2.1 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.2.0 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.1.3 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.1.2 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.1.1 lib/rocket_navigation/renderer/links.rb
rocket_navigation-0.1.0 lib/rocket_navigation/renderer/links.rb