Sha256: b4e5e765de00c76c45655d944c9831e56af33c9c852dd5fb014ddb2d6addfada

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

module ActiveAdmin
  module Views

    # Arbre component used to render ActiveAdmin::MenuItem
    class MenuItem < Component
      builder_method :menu_item
      attr_reader :label
      attr_reader :url
      attr_reader :priority

      def build(item, options = {})
        super(options.merge(id: item.id))
        @label = helpers.render_in_context self, item.label
        @url = helpers.render_in_context self, item.url
        @priority = item.priority
        @submenu = nil

        add_class "current" if item.current? assigns[:current_tab]

        if url
          text_node link_to label, url, **item.html_options
        else
          span label, item.html_options
        end

        if item.items.any?
          add_class "has_nested"
          @submenu = menu(item)
        end
      end

      def tag_name
        "li"
      end

      # Sorts by priority first, then alphabetically by label if needed.
      def <=>(other)
        result = priority <=> other.priority
        result == 0 ? label <=> other.label : result
      end

      def visible?
        url.nil? || real_url? || @submenu && @submenu.children.any?
      end

      def to_s
        visible? ? super : ""
      end

      private

      # URL is not nil, empty, or '#'
      def real_url?
        url && url.present? && url != "#"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/views/components/menu_item.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/views/components/menu_item.rb
activeadmin-2.9.0 lib/active_admin/views/components/menu_item.rb
activeadmin-2.8.1 lib/active_admin/views/components/menu_item.rb