Class: Navigation::Menu

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

Overview

handles adding items to a specific menu

Instance Method Summary collapse

Methods inherited from Base

#normalize

Constructor Details

#initialize(name, options = {}) ⇒ Menu

Returns a new instance of Menu.



5
6
7
8
9
# File 'lib/navigation/menu.rb', line 5

def initialize(name, options = {})
  @name = name
  (MENUS[@name] = ActiveSupport::OrderedHash.new).merge!(
    :action_menu => options[:action_menu], :if => options[:if])
end

Instance Method Details

#item(key, options = {}) {|NestedMenu.new(@name, key)| ... } ⇒ Object

Yields:



11
12
13
14
15
16
17
18
19
20
# File 'lib/navigation/menu.rb', line 11

def item(key, options = {}, &block)
  key = normalize(key)
  
  MENUS[@name].merge!(key => options)
  
  # if a block is given to this method, it is
  # assumed that there will be nested navigation,
  # so yield a NestedMenu instance back to the block
  yield NestedMenu.new(@name, key) if block_given?
end