class RocketNavigation::Item
Represents an item in your navigation.
Attributes
container[RW]
key[RW]
name[RW]
options[RW]
url[RW]
Public Class Methods
new(container, key, name, url = nil, opts = {}, &sub_nav_block)
click to toggle source
The subnavigation (if any) is either provided by a block or passed in directly as items
# File lib/rocket_navigation/item.rb, line 21 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
Public Instance Methods
active_branch?()
click to toggle source
# File lib/rocket_navigation/item.rb, line 50 def active_branch? @active_branch ||= selected_by_subnav? && !selected_by_condition? end
active_leaf?()
click to toggle source
# File lib/rocket_navigation/item.rb, line 54 def active_leaf? @active_leaf ||= selected_by_condition? && !selected_by_subnav? end
highlights_on()
click to toggle source
Returns the :highlights_on option as set at initialization
# File lib/rocket_navigation/item.rb, line 59 def highlights_on @highlights_on ||= options[:highlights_on] end
inspect()
click to toggle source
# File lib/rocket_navigation/item.rb, line 84 def inspect "#<RocketNavigation::Item:#{object_id} @key=#{@key} @name=#{@name} @sub_navigation=#{@sub_navigation.inspect} @url=#{@url.inspect} @options=#{@options.inspect} >" end
method()
click to toggle source
Returns the :method option as set at initialization
# File lib/rocket_navigation/item.rb, line 64 def method @method ||= options[:method] end
root_path_match?()
click to toggle source
Returns true if both the item's url and the request's url are root_path
# File lib/rocket_navigation/item.rb, line 80 def root_path_match? url == '/' end
selected?()
click to toggle source
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/rocket_navigation/item.rb, line 46 def selected? @selected ||= selected_by_subnav? || selected_by_condition? end
selected_by_condition?()
click to toggle source
Returns true if the item's url matches the request's current url.
# File lib/rocket_navigation/item.rb, line 75 def selected_by_condition? is_active_nav_link?(url, highlights_on) end
Private Instance Methods
remove_anchors(url_with_anchors)
click to toggle source
# File lib/rocket_navigation/item.rb, line 105 def remove_anchors(url_with_anchors) url_with_anchors && url_with_anchors.split('#').first end
remove_query_params(url_with_params)
click to toggle source
# File lib/rocket_navigation/item.rb, line 109 def remove_query_params(url_with_params) url_with_params && url_with_params.split('?').first end