Class: SimpleNavigation::Item
- Inherits:
-
Object
- Object
- SimpleNavigation::Item
- Defined in:
- lib/simple_navigation/item.rb
Overview
Represents an item in your navigation. Gets generated by the item method in the config-file.
Instance Attribute Summary collapse
-
#html_options(current_navigation) ⇒ Object
Returns the html-options hash for the item, i.e.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sub_navigation ⇒ Object
readonly
Returns the value of attribute sub_navigation.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(key, name, url, options, sub_nav_block) ⇒ Item
constructor
see ItemContainer#item.
-
#selected?(current_navigation) ⇒ Boolean
Returns true if this navigation item should be rendered as ‘selected’ for the specified current_navigation.
-
#selected_class(current_navigation) ⇒ Object
:nodoc:.
Constructor Details
#initialize(key, name, url, options, sub_nav_block) ⇒ Item
see ItemContainer#item
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/simple_navigation/item.rb', line 9 def initialize(key, name, url, , sub_nav_block) @key = key @method = .delete(:method) @name = name @url = url @html_options = if sub_nav_block @sub_navigation = ItemContainer.new sub_nav_block.call @sub_navigation end end |
Instance Attribute Details
#html_options(current_navigation) ⇒ Object
Returns the html-options hash for the item, i.e. the options specified for this item in the config-file. It also adds the ‘selected’ class to the list of classes if necessary.
28 29 30 31 32 33 34 |
# File 'lib/simple_navigation/item.rb', line 28 def () = self.autogenerate_item_ids? ? {:id => key.to_s} : {} = .merge(@html_options) [:class] = [@html_options[:class], self.selected_class()].flatten.compact.join(' ') .delete(:class) if [:class].blank? end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/simple_navigation/item.rb', line 5 def key @key end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/simple_navigation/item.rb', line 5 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/simple_navigation/item.rb', line 5 def name @name end |
#sub_navigation ⇒ Object (readonly)
Returns the value of attribute sub_navigation.
5 6 7 |
# File 'lib/simple_navigation/item.rb', line 5 def @sub_navigation end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/simple_navigation/item.rb', line 5 def url @url end |
Instance Method Details
#selected?(current_navigation) ⇒ Boolean
Returns true if this navigation item should be rendered as ‘selected’ for the specified current_navigation.
22 23 24 |
# File 'lib/simple_navigation/item.rb', line 22 def selected?() key == end |
#selected_class(current_navigation) ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/simple_navigation/item.rb', line 36 def selected_class() #:nodoc: selected?() ? SimpleNavigation.config.selected_class : nil end |