Class: Navigation::Navigator
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #allowed? ⇒ Boolean
-
#css_class ⇒ Object
the css class of the parent <ul> element.
-
#initialize(name, options) ⇒ Navigator
constructor
A new instance of Navigator.
-
#links ⇒ Object
returns the list items, all properly nested (if needed).
Methods inherited from Base
Constructor Details
#initialize(name, options) ⇒ Navigator
Returns a new instance of Navigator.
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, ) # must have menu definitions at this point raise NoMenuDefinitions, NoMenuDefinitions. if MENUS.blank? # since multiple menus are supported, must have the name of the desired menu raise BlankMenuIdentifier, BlankMenuIdentifier. if name.blank? # menu name/key must exist in the current menu definitions raise InvalidMenuIdentifier, InvalidMenuIdentifier. unless valid?(name) # need a reference of the view/view # for building out the HTML @view = .delete(:view) # initialization @name, @options = normalize(name), # 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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/navigation/navigator.rb', line 3 def name @name end |
#view ⇒ Object (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
45 46 47 |
# File 'lib/navigation/navigator.rb', line 45 def allowed? execute_proc @proc end |
#css_class ⇒ Object
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 |
#links ⇒ Object
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 |