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(context = nil) ⇒ Object
Returns sorted array of menu items that should be displayed in this context.
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
83 84 85 |
# File 'lib/active_admin/menu.rb', line 83 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 |
# File 'lib/active_admin/menu.rb', line 50 def add() = .dup # Make sure parameter is not modified item = if parent = .delete(:parent) (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.
69 70 71 |
# File 'lib/active_admin/menu.rb', line 69 def current?(item) self == item || include?(item) end |
#include?(item) ⇒ Boolean
Whether any children match the given item.
64 65 66 |
# File 'lib/active_admin/menu.rb', line 64 def include?(item) @children.value?(item) end |
#initialize ⇒ Object
24 25 26 |
# File 'lib/active_admin/menu.rb', line 24 def initialize @children = {} end |
#items(context = nil) ⇒ Object
Returns sorted array of menu items that should be displayed in this context. Sorts by priority first, then alphabetically by label if needed.
75 76 77 78 79 80 81 |
# File 'lib/active_admin/menu.rb', line 75 def items(context = nil) @children.values.select { |i| i.display?(context) }.sort do |a, b| result = a.priority <=> b.priority result = a.label(context) <=> b.label(context) if result == 0 result end end |