Class: Navigation::Navigator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#normalize

Constructor Details

#initialize(name, options) ⇒ Navigator

Returns a new instance of Navigator.

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/navigation/navigator.rb', line 5

def initialize(name, options)
  # must have menu definitions at this point
  raise NoMenuDefinitions, NoMenuDefinitions.message if MENUS.blank?
  # since multiple menus are supported, must have the name of the desired menu
  raise BlankMenuIdentifier, BlankMenuIdentifier.message if name.blank?
  # menu name/key must exist in the current menu definitions
  raise InvalidMenuIdentifier, InvalidMenuIdentifier.message unless valid?(name)
  
  # need a reference of the view/view
  # for building out the HTML
  @view = options.delete(:view)
  
  # initialization
  @name, @options = normalize(name), options
  
  # support building separate menus for actions,
  # without forcing it to be nested
  @action_menu = MENUS[@name][:action_menu]
  
  # menus can be shown/hidden based on
  # conditions by passing a Proc object
  #  Ex: 
  #   navigation.define :primary, :if => Proc.new { |c| c.logged_in? } do |menu|
  #     ...
  #   end
  @proc = MENUS[@name][:if]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/navigation/navigator.rb', line 3

def name
  @name
end

#viewObject (readonly)

Returns the value of attribute view.



3
4
5
# File 'lib/navigation/navigator.rb', line 3

def view
  @view
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/navigation/navigator.rb', line 45

def allowed?
  execute_proc @proc
end

#css_classObject

the css class of the parent <ul> element



35
36
37
# File 'lib/navigation/navigator.rb', line 35

def css_class
  @options[:class] || 'navigation'
end

returns the list items, all properly nested (if needed)



41
42
43
# File 'lib/navigation/navigator.rb', line 41

def links
  construct_html(self.items)
end