Sha256: 105b3f9f7df168c557cf1c96f62422b0b737955f4b02f825adf1810d8db80f9f

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

module ActiveAdmin

  # Renders out a horizontal list of tabs.
  class TabsRenderer < Renderer

    # Pass in an ActiveAdmin::Menu and it will display the first level
    # of navigation as a horizontal list of tabs
    def to_html(menu, options = {})
      @options = default_options.merge(options)
      render_menu(menu)
    end

    protected

    def render_menu(menu)
      content_tag :ul, :id => @options[:id] do
        menu.items.collect do |item|
          render_item(item)
        end.join
      end
    end

    def render_item(item)
      content_tag :li, :id => item.dom_id, :class => ("current" if current?(item)) do
        link_to item.name, item.url
      end
    end

    # Returns true if the menu item name is @current_tab
    def current?(menu_item)
      menu_item.name == @current_tab
    end

    def default_options
      { :id => "tabs" }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin-0.1.1 lib/active_admin/tabs_renderer.rb
activeadmin-0.1.0 lib/active_admin/tabs_renderer.rb