Class: PushType::MenuBuilder::Menu
- Defined in:
- lib/push_type/menu_builder/menu.rb
Instance Attribute Summary collapse
-
#active_class ⇒ Object
Returns the value of attribute active_class.
-
#element ⇒ Object
Returns the value of attribute element.
-
#html_options ⇒ Object
Returns the value of attribute html_options.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #build(&block) ⇒ Object
-
#initialize ⇒ Menu
constructor
A new instance of Menu.
- #insert_after(context, key, &block) ⇒ Object
- #insert_at(index, key, &block) ⇒ Object
- #insert_before(context, key, &block) ⇒ Object
- #item(key, &block) ⇒ Object
Constructor Details
#initialize ⇒ Menu
Returns a new instance of Menu.
10 11 12 13 14 15 |
# File 'lib/push_type/menu_builder/menu.rb', line 10 def initialize @items = [] @element = :ul @html_options = {} @active_class = 'active' end |
Instance Attribute Details
#active_class ⇒ Object
Returns the value of attribute active_class.
8 9 10 |
# File 'lib/push_type/menu_builder/menu.rb', line 8 def active_class @active_class end |
#element ⇒ Object
Returns the value of attribute element.
8 9 10 |
# File 'lib/push_type/menu_builder/menu.rb', line 8 def element @element end |
#html_options ⇒ Object
Returns the value of attribute html_options.
8 9 10 |
# File 'lib/push_type/menu_builder/menu.rb', line 8 def @html_options end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/push_type/menu_builder/menu.rb', line 7 def items @items end |
Instance Method Details
#build(&block) ⇒ Object
17 18 19 |
# File 'lib/push_type/menu_builder/menu.rb', line 17 def build(&block) PushType::MenuBuilder::Dsl::Menu.build(self, &block) end |
#insert_after(context, key, &block) ⇒ Object
39 40 41 |
# File 'lib/push_type/menu_builder/menu.rb', line 39 def insert_after(context, key, &block) insert_at find_item_index(context, 1), key, &block end |
#insert_at(index, key, &block) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/push_type/menu_builder/menu.rb', line 28 def insert_at(index, key, &block) itm = find_or_create_item(key) @items.insert index, itm itm.build(&block) if block_given? itm end |
#insert_before(context, key, &block) ⇒ Object
35 36 37 |
# File 'lib/push_type/menu_builder/menu.rb', line 35 def insert_before(context, key, &block) insert_at find_item_index(context), key, &block end |
#item(key, &block) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/push_type/menu_builder/menu.rb', line 21 def item(key, &block) itm = find_or_create_item(key) @items.push itm unless @items.include?(itm) itm.build(&block) if block_given? itm end |