Represents an item in your navigation. Gets generated by the item method in the config-file.
Returns the configured #active_leaf_class if the item is the selected leaf, nil otherwise
# File lib/simple_navigation/item.rb, line 64 def active_leaf_class if !selected_by_subnav? && selected_by_condition? config.active_leaf_class end end
Returns the :#highlights_on option as set at initialization
# File lib/simple_navigation/item.rb, line 79 def highlights_on @highlights_on ||= options[:highlights_on] end
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.
# File lib/simple_navigation/item.rb, line 51 def html_options html_opts = options.fetch(:html) { Hash.new } html_opts[:id] ||= autogenerated_item_id classes = [html_opts[:class], selected_class, active_leaf_class] classes = classes.flatten.compact.join(' ') html_opts[:class] = classes if classes && !classes.empty? html_opts end
Returns the html attributes for the link as set with the :link_html option at initialization
# File lib/simple_navigation/item.rb, line 90 def link_html_options @link_html_options ||= options[:link_html] end
Returns the :method option as set at initialization
# File lib/simple_navigation/item.rb, line 84 def method @method ||= options[:method] end
Returns true if this navigation item should be rendered as ‘selected’. An item is selected if
it has a subnavigation and one of its subnavigation items is selected or
its url matches the url of the current request (auto highlighting)
# File lib/simple_navigation/item.rb, line 44 def selected? @selected ||= selected_by_subnav? || selected_by_condition? end
Returns the configured #selected_class if the item is selected, nil otherwise
# File lib/simple_navigation/item.rb, line 72 def selected_class if selected? container.selected_class || config.selected_class end end
Return true if auto_highlight is on for this item.
# File lib/simple_navigation/item.rb, line 118 def auto_highlight? config.auto_highlight && container.auto_highlight end
Returns the item’s id which is added to the rendered output.
# File lib/simple_navigation/item.rb, line 113 def autogenerated_item_id config.id_generator.call(key) if config.autogenerate_item_ids end
Returns true if both the item’s url and the request’s url are root_path
# File lib/simple_navigation/item.rb, line 108 def root_path_match? url == '/' && SimpleNavigation.request_path == '/' end
Returns true if the item’s url matches the request’s current url.
# File lib/simple_navigation/item.rb, line 103 def selected_by_condition? highlights_on ? selected_by_highlights_on? : selected_by_autohighlight? end
see SimpleNavigation::ItemContainer#item
The subnavigation (if any) is either provided by a block or passed in
directly as items
# File lib/simple_navigation/item.rb, line 14 def initialize(container, key, name, url = nil, opts = {}, &sub_nav_block) self.container = container self.key = key self.name = name.respond_to?(:call) ? name.call : name self.url = url.respond_to?(:call) ? url.call : url self.options = opts setup_sub_navigation(options[:items], &sub_nav_block) end