Class: Kin::Nav::ItemBuilder

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

Overview

Provides the DSL used to create navigation items.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, label, menu) ⇒ ItemBuilder

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 Builder instance.

Parameters:

  • name (Symbol)

    A unique name for the Item instance.

  • label (String)

    Text which will be used on the item when rendered as HTML.

  • The (Kin::Nav::Menu)

    menu instance to which the item belongs.



79
80
81
82
# File 'lib/kin/nav/builder.rb', line 79

def initialize(name, label, menu)
  @item = Item.new(name, label)
  @menu = menu
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



65
66
67
# File 'lib/kin/nav/builder.rb', line 65

def item
  @item
end

Instance Method Details

#active_on(*pairs) ⇒ Kin::Nav::ItemBuilder

Sets on which controllers and actions the nav item should be considered to be the active item.

Examples:

# The 'home' tab will be active on any action on the 'home'
# controller, or the index action of the dashboard controller.
menu.add(:home, 'Home').active_on('home/*', 'dashboard/index')

Parameters:

  • pairs (Array<String>)

    An array of controller/action names.

Returns:



164
165
166
167
168
169
170
# File 'lib/kin/nav/builder.rb', line 164

def active_on(*pairs)
  pairs.each do |pair|
    @menu.add_active_match(pair, @item)
  end

  self
end

#guard(guard) ⇒ Kin::Nav::ItemBuilder

Sets a guard condition so that the item is only displayed if the guard is true when the item is rendered.

Parameters:

  • The (Symbol)

    guard condition.

Returns:

See Also:



142
143
144
145
# File 'lib/kin/nav/builder.rb', line 142

def guard(guard)
  @item.guard = guard
  self
end

#resource(verb) ⇒ Kin::Nav::ItemBuilder

Sets a resource verb to be used to create a URL.

Parameters:

  • The (Symbol)

    resource verb.

Returns:



109
110
111
112
# File 'lib/kin/nav/builder.rb', line 109

def resource(verb)
  @item.resource = verb
  self
end

#title(title) ⇒ Kin::Nav::ItemBuilder

Sets the (rollover) title applied to the anchor element.

Parameters:

  • Text (String)

    to be used as the title.

Returns:



94
95
96
97
# File 'lib/kin/nav/builder.rb', line 94

def title(title)
  @item.title = title
  self
end

#url(url) ⇒ Kin::Nav::ItemBuilder

Sets a URL to be used for the item.

Parameters:

  • A (#to_s)

    URL.

Returns:



124
125
126
127
# File 'lib/kin/nav/builder.rb', line 124

def url(url)
  @item.url = url.to_s
  self
end