Class: Navtastic::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/navtastic/item.rb

Overview

A single menu item

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the containing menu.

Returns:

  • (Menu)

    the containing menu



5
6
7
# File 'lib/navtastic/item.rb', line 5

def menu
  @menu
end

#nameString (readonly)

Returns the name to be displayed in the menu.

Returns:

  • (String)

    the name to be displayed in the menu



8
9
10
# File 'lib/navtastic/item.rb', line 8

def name
  @name
end

#optionsHash (readonly)

Returns extra options to configure individual items.

Returns:

  • (Hash)

    extra options to configure individual items



11
12
13
# File 'lib/navtastic/item.rb', line 11

def options
  @options
end

Returns the submenu of this item, if defined.

Returns:

  • (Menu, nil)

    the submenu of this item, if defined



14
15
16
# File 'lib/navtastic/item.rb', line 14

def submenu
  @submenu
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.

Returns:

  • (Bool)

    if the item is the current item

See Also:



53
54
55
56
57
58
# File 'lib/navtastic/item.rb', line 53

def active?
  return true if current?
  return false unless submenu

  submenu.items.any?(&:active?)
end

#current?Bool

Check if this item is the current item in the menu

Returns:

  • (Bool)

    if the item is the current item

See Also:



41
42
43
# File 'lib/navtastic/item.rb', line 41

def current?
  @menu.current_item == self
end

#inspectObject



65
66
67
# File 'lib/navtastic/item.rb', line 65

def inspect
  "#<Item \"#{name}\" [#{url}] current?:#{current?}>"
end

Returns true if the item has a submenu, false other.

Returns:

  • (Bool)

    true if the item has a submenu, false other



61
62
63
# File 'lib/navtastic/item.rb', line 61

def submenu?
  !@submenu.nil?
end

#urlString?

The url for this item, if the item has a url

Will prepend the base_url for the menu if it is present

Returns:

  • (String, nil)


81
82
83
84
85
86
87
88
# File 'lib/navtastic/item.rb', line 81

def url
  return nil unless url?
  return @url if options[:root]

  url = "#{@menu.base_url}#{@url}"
  url.chomp!('/') unless url == '/'
  url
end

#url?Bool

Check if item has a link or not

Returns:

  • (Bool)


72
73
74
# File 'lib/navtastic/item.rb', line 72

def url?
  !@url.nil?
end