Class: SimpleMenu::MenuHelper::MenuBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selected) ⇒ MenuBuilder

Returns a new instance of MenuBuilder



30
31
32
33
# File 'lib/simple_menu.rb', line 30

def initialize(selected)
  @items = []
  @selected = selected 
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items



28
29
30
# File 'lib/simple_menu.rb', line 28

def items
  @items
end

Instance Method Details

#item(name, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/simple_menu.rb', line 35

def item(name, options={})
  link = name.to_s.humanize
  options[:id] = "#{name.to_s}_link" unless options[:id]

  options[:link_text] = options.delete(:text) || link
  options[:link_url] = options.delete(:url) || name 

  options[:class] = "#{options[:class]} current" if is_selected?(name)

  @items.push options 
  nil
end