Module: ActiveAdmin::Menu::MenuNode
- Included in:
- ActiveAdmin::Menu, ActiveAdmin::MenuItem
- Defined in:
- lib/active_admin/menu.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, child) ⇒ Object
-
#add(options) {|item| ... } ⇒ Object
Recursively builds any given menu items.
-
#current?(item) ⇒ Boolean
Used in the UI to visually distinguish which menu item is selected.
-
#include?(item) ⇒ Boolean
Whether any children match the given item.
- #initialize ⇒ Object
- #items ⇒ Object
Instance Attribute Details
#children ⇒ Object
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.new
.add label: 'Dashboard' do |dash|
dash.add label: 'My Child Dashboard'
end
Example 2:
= Menu.new
.add label: 'Dashboard'
.add parent: 'Dashboard', label: 'My Child Dashboard'
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_admin/menu.rb', line 50 def add() parent_chain = Array.wrap(.delete(:parent)) item = if parent = parent_chain.shift [:parent] = parent_chain if parent_chain.any? (self[parent] || add(label: parent)).add else _add .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.
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.
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 |
#initialize ⇒ Object
24 25 26 |
# File 'lib/active_admin/menu.rb', line 24 def initialize @children = {} end |
#items ⇒ Object
75 76 77 |
# File 'lib/active_admin/menu.rb', line 75 def items @children.values end |