class Navtastic::Item
A single menu item
Attributes
@return [String] the name to be displayed in the menu
@return [Hash] extra options to configure individual items
Public Class Methods
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
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
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
# File lib/navtastic/item.rb, line 65 def inspect "#<Item \"#{name}\" [#{url}] current?:#{current?}>" end
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
Check if item has a link or not
@return [Bool]
# File lib/navtastic/item.rb, line 72 def url? !@url.nil? end