Class: SimpleNavigation::Item
- Inherits:
-
Object
- Object
- SimpleNavigation::Item
- Defined in:
- lib/simple_navigation/core/item.rb,
lib/simple_navigation/rails_controller_methods.rb
Overview
Represents an item in your navigation. Gets generated by the item method in the config-file.
Instance Attribute Summary (collapse)
-
- (Object) highlights_on
readonly
Returns the value of attribute highlights_on.
-
- (Object) html_options
Returns the html-options hash for the item, i.e.
-
- (Object) key
readonly
Returns the value of attribute key.
-
- (Object) method
readonly
Returns the value of attribute method.
-
- (Object) sub_navigation
readonly
Returns the value of attribute sub_navigation.
-
- (Object) url
readonly
Returns the value of attribute url.
Instance Method Summary (collapse)
-
- (Object) active_leaf_class
Returns the configured active_leaf_class if the item is the selected leaf, nil otherwise.
-
- (Item) initialize(container, key, name, url_or_options = {}, options_or_nil = {}, items = nil, &sub_nav_block)
constructor
see ItemContainer#item.
-
- (Object) name(options = {})
Returns the item's name.
-
- (Boolean) selected?
Returns true if this navigation item should be rendered as 'selected'.
- - (Boolean) selected_by_config?
-
- (Object) selected_class
Returns the configured selected_class if the item is selected, nil otherwise.
Constructor Details
- (Item) initialize(container, key, name, url_or_options = {}, options_or_nil = {}, items = nil, &sub_nav_block)
see ItemContainer#item
The subnavigation (if any) is either provided by a block or passed in directly as items
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/simple_navigation/core/item.rb', line 11 def initialize(container, key, name, = {}, ={}, items=nil, &sub_nav_block) @container = container = (, ) @container.dom_class = .delete(:container_class) if [:container_class] @container.dom_id = .delete(:container_id) if [:container_id] @key = key @method = .delete(:method) @name = name if sub_nav_block || items @sub_navigation = ItemContainer.new(@container.level + 1) sub_nav_block.call @sub_navigation if sub_nav_block @sub_navigation.items = items if items end end |
Instance Attribute Details
- (Object) highlights_on (readonly)
Returns the value of attribute highlights_on
5 6 7 |
# File 'lib/simple_navigation/core/item.rb', line 5 def highlights_on @highlights_on end |
- (Object) html_options
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.
51 52 53 54 55 56 57 |
# File 'lib/simple_navigation/core/item.rb', line 51 def = self.autogenerate_item_ids? ? {:id => autogenerated_item_id} : {} = .merge(@html_options) [:class] = [@html_options[:class], self.selected_class, self.active_leaf_class].flatten.compact.join(' ') .delete(:class) if [:class].nil? || [:class] == '' end |
- (Object) key (readonly)
Returns the value of attribute key
5 6 7 |
# File 'lib/simple_navigation/core/item.rb', line 5 def key @key end |
- (Object) method (readonly)
Returns the value of attribute method
5 6 7 |
# File 'lib/simple_navigation/core/item.rb', line 5 def method @method end |
- (Object) sub_navigation (readonly)
Returns the value of attribute sub_navigation
5 6 7 |
# File 'lib/simple_navigation/core/item.rb', line 5 def @sub_navigation end |
- (Object) url (readonly)
Returns the value of attribute url
5 6 7 |
# File 'lib/simple_navigation/core/item.rb', line 5 def url @url end |
Instance Method Details
- (Object) active_leaf_class
Returns the configured active_leaf_class if the item is the selected leaf, nil otherwise
61 62 63 |
# File 'lib/simple_navigation/core/item.rb', line 61 def active_leaf_class ! && selected_by_condition? ? SimpleNavigation.config.active_leaf_class : nil end |
- (Object) name(options = {})
Returns the item's name. If option :apply_generator is set to true (default), the name will be passed to the name_generator specified in the configuration.
29 30 31 32 33 34 35 36 |
# File 'lib/simple_navigation/core/item.rb', line 29 def name( = {}) .reverse_merge!(:apply_generator => true) if ([:apply_generator]) SimpleNavigation.config.name_generator.call(@name) else @name end end |
- (Boolean) selected?
Returns true if this navigation item should be rendered as 'selected'. An item is selected if
-
it has been explicitly selected in a controller or
-
it has a subnavigation and one of its subnavigation items is selected or
-
its url matches the url of the current request (auto highlighting)
45 46 47 |
# File 'lib/simple_navigation/core/item.rb', line 45 def selected? @selected = @selected || selected_by_config? || || selected_by_condition? end |
- (Boolean) selected_by_config?
78 79 80 |
# File 'lib/simple_navigation/core/item.rb', line 78 def selected_by_config? false end |
- (Object) selected_class
Returns the configured selected_class if the item is selected, nil otherwise
67 68 69 |
# File 'lib/simple_navigation/core/item.rb', line 67 def selected_class selected? ? SimpleNavigation.config.selected_class : nil end |