Class: Navigation::NestedMenu

Inherits:
Base
  • Object
show all
Defined in:
lib/navigation/nested_menu.rb

Overview

handles adding nested menu items to a parent menu item

Instance Method Summary collapse

Methods inherited from Base

#normalize

Constructor Details

#initialize(menu, parent) ⇒ NestedMenu

Returns a new instance of NestedMenu.



5
6
7
8
9
10
11
# File 'lib/navigation/nested_menu.rb', line 5

def initialize(menu, parent)
  @menu, @parent = menu, parent
  
  # the entire nested menu is stored as a nested ordered hash
  # since we want multiple items in the same hash, only initialize once
  MENUS[@menu][@parent][SUBMENU] = ActiveSupport::OrderedHash.new unless MENUS[@menu][@parent].has_key?(SUBMENU)
end

Instance Method Details

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

Raises:

  • (InvalkeyBlock)


13
14
15
16
17
# File 'lib/navigation/nested_menu.rb', line 13

def item(key, options = {})
  # only support one level of nesting (the action-level)
  raise InvalkeyBlock, InvalkeyBlock.message if block_given?
  MENUS[@menu][@parent][SUBMENU].merge!(normalize(key) => options)
end