Module: Madmin::Menu::Node

Included in:
Madmin::Menu, Item
Defined in:
lib/madmin/menu.rb

Instance Method Summary collapse

Instance Method Details

#add(options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/madmin/menu.rb', line 32

def add(options)
  options = options.dup

  if (parent = options.delete(:parent))
    @children[parent] ||= Item.new(label: parent)
    @children[parent].add options
  else
    item = Item.new(**options)
    @children[item.label] = item
  end
end

#itemsObject



44
45
46
47
48
49
50
# File 'lib/madmin/menu.rb', line 44

def items
  @children.values.sort do |a, b|
    result = a.position <=> b.position
    result = a.label <=> b.label if result == 0 # sort alphabetically for the same position
    result
  end
end