Class: Navtastic::Item
- Inherits:
-
Object
- Object
- Navtastic::Item
- Defined in:
- lib/navtastic/item.rb
Overview
A single menu item
Instance Attribute Summary collapse
-
#menu ⇒ Menu
readonly
The containing menu.
-
#name ⇒ String
readonly
The name to be displayed in the menu.
-
#options ⇒ Hash
readonly
Extra options to configure individual items.
-
#submenu ⇒ Menu?
The submenu of this item, if defined.
Instance Method Summary collapse
-
#active? ⇒ Bool
Check if the item has a current child in its submenu (or deeper).
-
#current? ⇒ Bool
Check if this item is the current item in the menu.
- #inspect ⇒ Object
-
#submenu? ⇒ Bool
True if the item has a submenu, false other.
-
#url ⇒ String?
The url for this item, if the item has a url.
-
#url? ⇒ Bool
Check if item has a link or not.
Instance Attribute Details
#menu ⇒ Menu (readonly)
Returns the containing menu.
5 6 7 |
# File 'lib/navtastic/item.rb', line 5 def end |
#name ⇒ String (readonly)
Returns the name to be displayed in the menu.
8 9 10 |
# File 'lib/navtastic/item.rb', line 8 def name @name end |
#options ⇒ Hash (readonly)
Returns extra options to configure individual items.
11 12 13 |
# File 'lib/navtastic/item.rb', line 11 def end |
#submenu ⇒ Menu?
Returns the submenu of this item, if defined.
14 15 16 |
# File 'lib/navtastic/item.rb', line 14 def end |
Instance Method Details
#active? ⇒ Bool
Check if the item has a current child in its submenu (or deeper)
Also returns true if this is the current item.
53 54 55 56 57 58 |
# File 'lib/navtastic/item.rb', line 53 def active? return true if current? return false unless .items.any?(&:active?) end |
#current? ⇒ Bool
Check if this item is the current item in the menu
41 42 43 |
# File 'lib/navtastic/item.rb', line 41 def current? .current_item == self end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/navtastic/item.rb', line 65 def inspect "#<Item \"#{name}\" [#{url}] current?:#{current?}>" end |
#submenu? ⇒ Bool
Returns true if the item has a submenu, false other.
61 62 63 |
# File 'lib/navtastic/item.rb', line 61 def !.nil? end |
#url ⇒ String?
The url for this item, if the item has a url
Will prepend the base_url for the menu if it is present
81 82 83 84 85 86 87 88 |
# File 'lib/navtastic/item.rb', line 81 def url return nil unless url? return @url if [:root] url = "#{@menu.base_url}#{@url}" url.chomp!('/') unless url == '/' url end |
#url? ⇒ Bool
Check if item has a link or not
72 73 74 |
# File 'lib/navtastic/item.rb', line 72 def url? !@url.nil? end |