module ActiveAdmin::Menu::MenuNode
def [](id)
def [](id) @children[normalize_id(id)] end
def []=(id, child)
def []=(id, child) @children[normalize_id(id)] = child end
def _add(options)
The method that actually adds new menu items. Called by the public method.
def _add(options) item = ActiveAdmin::MenuItem.new(options) item.send :children=, self[item.id].children if self[item.id] self[item.id] = item end
def add(options)
menu.add parent: 'Dashboard', label: 'My Child Dashboard'
menu.add label: 'Dashboard'
menu = Menu.new
Example 2:
end
dash.add label: 'My Child Dashboard'
menu.add label: 'Dashboard' do |dash|
menu = Menu.new
Example 1:
as shown in the below examples. Both create an identical menu structure.
Recursively builds any given menu items. There are two syntaxes supported,
def add(options) item = if parent = options.delete(:parent) (self[parent] || add(:label => parent)).add options else _add options.merge :parent => self end yield(item) if block_given? item end
def current?(item)
def current?(item) self == item || include?(item) end
def include?(item)
def include?(item) @children.values.include? item end
def initialize
def initialize @children = {} end
def items(context = nil)
Returns sorted array of menu items that should be displayed in this context.
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
def normalize_id(id)
def normalize_id(id) case id when String, Symbol id.to_s.downcase.gsub ' ', '_' else raise TypeError, "#{id.class} isn't supported as a Menu ID" end end