Sha256: 86c116e06281a918790ab3f9bf4f34a88ac06861d2c3da3422028659655f9f4f

Contents?: true

Size: 1.49 KB

Versions: 13

Compression:

Stored size: 1.49 KB

Contents

module ActiveAdmin
  module Views

    # Renders an ActiveAdmin::Menu as a set of unordered list items.
    #
    # This component takes cares of deciding which items should be
    # displayed given the current context and renders them appropriately.
    #
    # The entire component is rendered within one ul element.
    class TabbedNavigation < Component

      attr_reader :menu

      # Build a new tabbed navigation component.
      #
      # @param [ActiveAdmin::Menu] menu the Menu to render
      # @param [Hash] options the options as passed to the underlying ul element.
      #
      def build(menu, options = {})
        @menu = menu
        super(default_options.merge(options))
        build_menu
      end

      # The top-level menu items that should be displayed.
      def menu_items
        menu.items(self)
      end

      def tag_name
        'ul'
      end

      private

      def build_menu
        menu_items.each do |item|
          build_menu_item(item)
        end
      end

      def build_menu_item(item)
        li :id => item.id do |li|
          li.add_class "current" if item.current? assigns[:current_tab]

          text_node link_to item.label(self), item.url(self), item.html_options

          if children = item.items(self).presence
            li.add_class "has_nested"
            ul do
              children.each{ |child| build_menu_item child }
            end
          end
        end
      end

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

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/views/tabbed_navigation.rb
activeadmin-0.6.5 lib/active_admin/views/tabbed_navigation.rb
activeadmin-0.6.4 lib/active_admin/views/tabbed_navigation.rb
yousty-activeadmin-1.0.4.pre lib/active_admin/views/tabbed_navigation.rb
yousty-activeadmin-1.0.3.pre lib/active_admin/views/tabbed_navigation.rb
yousty-activeadmin-1.0.2.pre lib/active_admin/views/tabbed_navigation.rb
activeadmin-0.6.3 lib/active_admin/views/tabbed_navigation.rb
yousty-activeadmin-1.0.1.pre lib/active_admin/views/tabbed_navigation.rb
yousty-activeadmin-1.0.0.pre lib/active_admin/views/tabbed_navigation.rb
activeadmin-0.6.2 lib/active_admin/views/tabbed_navigation.rb
activeadmin-0.6.1 lib/active_admin/views/tabbed_navigation.rb
aa-rails4-0.6.0 lib/active_admin/views/tabbed_navigation.rb
activeadmin-0.6.0 lib/active_admin/views/tabbed_navigation.rb