class Olelo::Menu
Attributes
name[R]
Public Class Methods
new(name)
click to toggle source
# File lib/olelo/menu.rb, line 7 def initialize(name) @name = name.to_sym @items = {} end
Public Instance Methods
<<(item)
click to toggle source
# File lib/olelo/menu.rb, line 35 def <<(item) raise TypeError, "Only items allowed" unless MenuItem === item raise "Item #{item.name} exists already in #{path.join('/')}" if @items.include?(item.name) item.parent = self @items[item.name] = item end
[](name)
click to toggle source
# File lib/olelo/menu.rb, line 16 def [](name) path = path.to_s i = path.index('/') if i item = @items[path[0...i]] item[path[i+1..-1]] if item else @items[name.to_sym] end end
append(items)
click to toggle source
# File lib/olelo/menu.rb, line 31 def append(items) items.each {|item| self << item } end
clear()
click to toggle source
# File lib/olelo/menu.rb, line 46 def clear @items.clear end
each(&block)
click to toggle source
# File lib/olelo/menu.rb, line 12 def each(&block) @items.each_value(&block) end
empty?()
click to toggle source
# File lib/olelo/menu.rb, line 42 def empty? @items.empty? end
html_id()
click to toggle source
# File lib/olelo/menu.rb, line 69 def html_id escape_html path.join('-') end
item(name, options = {})
click to toggle source
# File lib/olelo/menu.rb, line 27 def item(name, options = {}) self << MenuItem.new(name, options) end
path()
click to toggle source
# File lib/olelo/menu.rb, line 73 def path [name] end
remove(name)
click to toggle source
# File lib/olelo/menu.rb, line 50 def remove(name) path = name.to_s i = path.index('/') if i item = @items[path[0...i]] item.remove(path[i+1..-1]) if item else @items.delete(name.to_sym) end end
to_html()
click to toggle source
# File lib/olelo/menu.rb, line 65 def to_html build_menu.html_safe end