Class: Kin::Nav::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/kin/nav.rb

Overview

Represents a single item/tab in a navigation menu.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, label) ⇒ Item

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Item.

Parameters:

  • id (Symbol)

    A unique identifier for this item.

  • label (String)

    The text label for this item.



187
188
189
190
# File 'lib/kin/nav.rb', line 187

def initialize(id, label)
  @id, @label = id, label
  @resource, @url, @title, @guard = nil, nil, nil, nil
end

Instance Attribute Details

#guardObject

Returns the value of attribute guard.



172
173
174
# File 'lib/kin/nav.rb', line 172

def guard
  @guard
end

#idObject (readonly)

Returns the value of attribute id.



171
172
173
# File 'lib/kin/nav.rb', line 171

def id
  @id
end

#resourceObject

Returns the value of attribute resource.



172
173
174
# File 'lib/kin/nav.rb', line 172

def resource
  @resource
end

#title(inject = nil) ⇒ String

Returns the item title (hover tooltip). If no title is set, the label will be used intead.

Parameters:

  • inject (Array) (defaults to: nil)

    An optional array containing (escaped) strings for injection.

Returns:



227
228
229
# File 'lib/kin/nav.rb', line 227

def title(inject = nil)
  @title || label(inject)
end

#url(given_resource = nil) ⇒ Object

Returns the URL for this Item. If the item expects a resource, it should be provided as the sole parameter to this method.



237
238
239
# File 'lib/kin/nav.rb', line 237

def url(given_resource = nil)
  expects_resource? ? resource_url(given_resource) : @url
end

Instance Method Details

#display?(guards = {}) ⇒ Boolean

Returns if this item can be displayed.

Parameters:

  • Permitted (Array)

    guard conditions.

Returns:

  • (Boolean)


198
199
200
# File 'lib/kin/nav.rb', line 198

def display?(guards = {})
  @guard.nil? || guards[@guard]
end

#inspectObject



175
176
177
# File 'lib/kin/nav.rb', line 175

def inspect
  "#<Kin::Nav::Item #{id}>"
end

#label(inject = nil) ⇒ String

Returns the item label.

Parameters:

  • inject (Array) (defaults to: nil)

    An optional array containing (escaped) strings for injection.

Returns:



212
213
214
# File 'lib/kin/nav.rb', line 212

def label(inject = nil)
  inject ? @label % inject : @label
end