Class: RocketNavigation::Item

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rocket_navigation/item.rb

Overview

Represents an item in your navigation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, key, name, url = nil, opts = {}, &sub_nav_block) ⇒ Item

see ItemContainer#item

The subnavigation (if any) is either provided by a block or passed in directly as items



19
20
21
22
23
24
25
26
27
# File 'lib/rocket_navigation/item.rb', line 19

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

Instance Attribute Details

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/rocket_navigation/item.rb', line 6

def key
  @key
end

#name(options = {}) ⇒ Object

Returns the item’s name. If :apply_generator option is set to true (default), the name will be passed to the name_generator specified in the configuration.



34
35
36
# File 'lib/rocket_navigation/item.rb', line 34

def name
  @name
end

Returns the value of attribute sub_navigation.



6
7
8
# File 'lib/rocket_navigation/item.rb', line 6

def sub_navigation
  @sub_navigation
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/rocket_navigation/item.rb', line 6

def url
  @url
end

Instance Method Details

#active_branch?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rocket_navigation/item.rb', line 48

def active_branch?
  @active_branch ||= selected_by_subnav? && !selected_by_condition?
end

#active_leaf?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/rocket_navigation/item.rb', line 52

def active_leaf?
  @active_leaf ||= selected_by_condition?
end

#highlights_onObject

Returns the :highlights_on option as set at initialization



57
58
59
# File 'lib/rocket_navigation/item.rb', line 57

def highlights_on
  @highlights_on ||= options[:highlights_on]
end

#methodObject

Returns the :method option as set at initialization



62
63
64
# File 'lib/rocket_navigation/item.rb', line 62

def method
  @method ||= options[:method]
end

#root_path_match?Boolean

Returns true if both the item’s url and the request’s url are root_path

Returns:

  • (Boolean)


78
79
80
# File 'lib/rocket_navigation/item.rb', line 78

def root_path_match?
  url == '/'
end

#selected?Boolean

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)

Returns:

  • (Boolean)


44
45
46
# File 'lib/rocket_navigation/item.rb', line 44

def selected?
  @selected ||= selected_by_subnav? || selected_by_condition?
end

#selected_by_condition?Boolean

Returns true if the item’s url matches the request’s current url.

Returns:

  • (Boolean)


73
74
75
# File 'lib/rocket_navigation/item.rb', line 73

def selected_by_condition?
  is_active_nav_link?(url, highlights_on)
end

#selected_by_subnav?Boolean

Returns true if item has a subnavigation and the sub_navigation is selected

Returns:

  • (Boolean)


68
69
70
# File 'lib/rocket_navigation/item.rb', line 68

def selected_by_subnav?
  sub_navigation && sub_navigation.selected?
end