Class: Kin::Nav::Builder

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

Overview

Provides the DSL used to create navigation menus.

Instance Method Summary collapse

Constructor Details

#initialize(name, formatter = nil) ⇒ Builder

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

  • formatter (Kin::Nav::Formatters::Basic) (defaults to: nil)

    A custom formatter to use when rendering the menu as HTML.



18
19
20
21
# File 'lib/kin/nav/builder.rb', line 18

def initialize(name, formatter = nil)
  @nav = Menu.new(name, formatter)
  @item_builders = []
end

Instance Method Details

#add(name, label) {|Kin::Nav::ItemBuilder| ... } ⇒ Kin::Nav::ItemBuilder

Adds an item to the menu, returning an item builder which provides a DSL for customising the item.

Parameters:

  • name (Symbol)

    A unique name for the Item instance.

  • label (String)

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

Yields:

Returns:

See Also:

  • Kin::Nav.build


53
54
55
56
57
58
# File 'lib/kin/nav/builder.rb', line 53

def add(name, label)
  ibuilder = ItemBuilder.new(name.to_sym, label, @nav)
  @item_builders << ibuilder
  yield ibuilder if block_given?
  ibuilder
end

#build {|Kin::Nav::Builder| ... } ⇒ Kin::Nav::Menu

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.

Builds the nav menu. Yields the builder to provide a nicer DSL.

Yields:

Returns:



31
32
33
34
35
# File 'lib/kin/nav/builder.rb', line 31

def build
  yield self if block_given?
  @item_builders.each { |b| @nav.items << b.item }
  @nav
end