Module: ActiveAdmin::Menu::MenuNode

Included in:
ActiveAdmin::Menu, ActiveAdmin::MenuItem
Defined in:
lib/active_admin/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



79
80
81
# File 'lib/active_admin/menu.rb', line 79

def children
  @children
end

Instance Method Details

#[](id) ⇒ Object



28
29
30
# File 'lib/active_admin/menu.rb', line 28

def [](id)
  @children[normalize_id(id)]
end

#[]=(id, child) ⇒ Object



32
33
34
# File 'lib/active_admin/menu.rb', line 32

def []=(id, child)
  @children[normalize_id(id)] = child
end

#add(options) {|item| ... } ⇒ Object

Recursively builds any given menu items. There are two syntaxes supported, as shown in the below examples. Both create an identical menu structure.

Example 1:

menu = Menu.new
menu.add label: 'Dashboard' do |dash|
  dash.add label: 'My Child Dashboard'
end

Example 2:

menu = Menu.new
menu.add label:  'Dashboard'
menu.add parent: 'Dashboard', label: 'My Child Dashboard'

Yields:

  • (item)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_admin/menu.rb', line 50

def add(options)
  parent_chain = Array.wrap(options.delete(:parent))

  item = if parent = parent_chain.shift
           options[:parent] = parent_chain if parent_chain.any?
           (self[parent] || add(label: parent)).add options
         else
           _add options.merge parent: self
         end

  yield(item) if block_given?

  item
end

#current?(item) ⇒ Boolean

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

Returns:

  • (Boolean)


71
72
73
# File 'lib/active_admin/menu.rb', line 71

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

#include?(item) ⇒ Boolean

Whether any children match the given item.

Returns:

  • (Boolean)


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

def include?(item)
  @children.values.include?(item) || @children.values.any? { |child| child.include?(item) }
end

#initializeObject



24
25
26
# File 'lib/active_admin/menu.rb', line 24

def initialize
  @children = {}
end

#itemsObject



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

def items
  @children.values
end