class ActiveAdmin::MenuItem
def <=>(other)
def <=>(other) result = priority <=> other.priority result = name <=> other.name if result == 0 result end
def [](name)
Returns the child item with the name passed in
def [](name) @children.find{ |i| i.name == name } end
def add(name, url, priority=10, options = {}, &block)
def add(name, url, priority=10, options = {}, &block) item = MenuItem.new(name, url, priority, options, &block) item.parent = self @children << item 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 name.downcase.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' ) end
def initialize(name, url, priority = 10, options = {})
def initialize(name, url, priority = 10, options = {}) @name, @url, @priority = name, url, priority @children = [] @cached_url = {} # Stores the cached url in a hash to allow us to change it and still cache it @display_if_block = options.delete(:if) yield(self) if block_given? # Builder style syntax end
def parent?
def parent? !parent.nil? end