class Navtastic::Item

A single menu item

Attributes

menu[R]

@return [Menu] the containing menu

name[R]

@return [String] the name to be displayed in the menu

options[R]

@return [Hash] extra options to configure individual items

submenu[RW]

@return [Menu,nil] the submenu of this item, if defined

Public Class Methods

new(menu, name, url = nil, options = {}) click to toggle source

Create a new item

This should not be used directly. Use the {Menu#item} method instead.

@private

@param menu [Menu] the menu this items belongs to @param name [String] the name to display when rendering @param url [String] the url to link to, if the item is a link @param options [Hash] extra configuration options

# File lib/navtastic/item.rb, line 26
def initialize(menu, name, url = nil, options = {})
  @menu = menu
  @name = name
  @url = url
  @options = options

  @submenu = nil
end

Public Instance Methods

active?() click to toggle source

Check if the item has a current child in its submenu (or deeper)

Also returns true if this is the current item.

@see file:README.md#Current_item documentation on how the current item is

selected

@return [Bool] if the item is the current item

# File lib/navtastic/item.rb, line 53
def active?
  return true if current?
  return false unless submenu

  submenu.items.any?(&:active?)
end
current?() click to toggle source

Check if this item is the current item in the menu

@see file:README.md#Current_item documentation on how the current item is

selected

@return [Bool] if the item is the current item

# File lib/navtastic/item.rb, line 41
def current?
  @menu.current_item == self
end
inspect() click to toggle source
# File lib/navtastic/item.rb, line 65
def inspect
  "#<Item \"#{name}\" [#{url}] current?:#{current?}>"
end
submenu?() click to toggle source

@return [Bool] true if the item has a submenu, false other

url() click to toggle source

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

Will prepend the `base_url` for the menu if it is present

@return [String,nil]

# 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?() click to toggle source

Check if item has a link or not

@return [Bool]

# File lib/navtastic/item.rb, line 72
def url?
  !@url.nil?
end