class ActiveAdmin::MenuItem
def self.generate_item_id(id)
def self.generate_item_id(id) id.to_s.downcase.gsub(" ", "_") end
def <=>(other)
def <=>(other) result = priority <=> other.priority result = label <=> other.label if result == 0 result end
def [](id)
Returns the child item with the name passed in
def [](id) @children.find_by_id(id) end
def add(*menu_items)
def add(*menu_items) menu_items.each do |menu_item| menu_item.parent = self @children << menu_item end end
def ancestors
Returns an array of the ancestory of this menu item
def ancestors return [] unless parent? [parent, parent.ancestors].flatten end
def children
def children @children.sort end
def display_if_block
Returns the display if block. If the block was not explicitly defined
def display_if_block @display_if_block || lambda { |_| true } end
def dom_id
def dom_id id.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' ) end
def initialize(options = {})
(**options)
-
:parent
(Proc
) -- -
:if
(Proc
) -- -
:priority
(Integer
) -- -
:url
(String, Symbol
) -- -
:id
(String
) -- -
:label
(String, Proc
) --
Parameters:
-
options
(Hash
) -- The options for the menu
def initialize(options = {}) @label = options[:label] @id = MenuItem.generate_item_id(options[:id] || label) @url = options[:url] @priority = options[:priority] || 10 @children = Menu::ItemCollection.new @parent = options[:parent] @display_if_block = options[:if] yield(self) if block_given? # Builder style syntax end
def label
def label case @label when Proc @label.call else @label.to_s end end
def parent?
def parent? !parent.nil? end