Class: ActiveAdmin::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/menu_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ MenuItem

Builds a new menu item

NOTE: for :label, :url, and :if These options are evaluated in the view context at render time. Symbols are called as methods on self, and Procs are exec’d within self. Here are some examples of what you can do:

menu if:  :admin?
menu url: :new_book_path
menu url: :awesome_helper_you_defined
menu label: ->{ User.some_method }
menu label: ->{ I18n.t 'menus.user' }

Parameters:

  • options (Hash) (defaults to: {})

    The options for the menu

  • [ActiveAdmin::MenuItem] (Hash)

    a customizable set of options

Options Hash (options):

  • :label (String, Symbol, Proc)

    The label to display for this menu item. Default: Titleized Resource Name

  • :id (String)

    A custom id to reference this menu item with. Default: underscored_resource_name

  • :url (String, Symbol, Proc)

    The URL this item will link to.

  • :priority (Integer)

    The lower the priority, the earlier in the menu the item will be displayed. Default: 10

  • :if (Symbol, Proc)

    This decides whether the menu item will be displayed. Evaluated on each request.

  • :html_options (Hash)

    A hash of options to pass to link_to when rendering the item

Yields:

  • (_self)

Yield Parameters:



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_admin/menu_item.rb', line 45

def initialize(options = {})
  super() # MenuNode
  @label          = options[:label]
  @dirty_id       = options[:id]           || options[:label]
  @url            = options[:url]          || '#'
  @priority       = options[:priority]     || 10
  @html_options   = options[:html_options] || {}
  @should_display = options[:if]           || proc{true}
  @parent         = options[:parent]

  yield(self) if block_given? # Builder style syntax
end

Instance Attribute Details

#html_optionsObject (readonly)

Returns the value of attribute html_options.



4
5
6
# File 'lib/active_admin/menu_item.rb', line 4

def html_options
  @html_options
end

#labelObject (readonly)

Returns the value of attribute label.



62
63
64
# File 'lib/active_admin/menu_item.rb', line 62

def label
  @label
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/active_admin/menu_item.rb', line 4

def parent
  @parent
end

#priorityObject (readonly)

Returns the value of attribute priority.



4
5
6
# File 'lib/active_admin/menu_item.rb', line 4

def priority
  @priority
end

#should_displayObject (readonly)

Don’t display if the :if option passed says so



66
67
68
# File 'lib/active_admin/menu_item.rb', line 66

def should_display
  @should_display
end

#urlObject (readonly)

Returns the value of attribute url.



63
64
65
# File 'lib/active_admin/menu_item.rb', line 63

def url
  @url
end

Instance Method Details

#current?(item) ⇒ Boolean

Used in the UI to visually distinguish which menu item is selected.

Returns:

  • (Boolean)


69
70
71
# File 'lib/active_admin/menu_item.rb', line 69

def current?(item)
  self == item || submenu.include?(item)
end

#idObject



58
59
60
# File 'lib/active_admin/menu_item.rb', line 58

def id
  @id ||= Menu.normalize_id @dirty_id
end


75
76
77
# File 'lib/active_admin/menu_item.rb', line 75

def submenu
  @menu ||= Menu.new(self)
end