Class: Kin::Nav::Builder
- Inherits:
-
Object
- Object
- Kin::Nav::Builder
- Defined in:
- lib/kin/nav/builder.rb
Overview
Provides the DSL used to create navigation menus.
Instance Method Summary collapse
-
#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.
-
#build {|Kin::Nav::Builder| ... } ⇒ Kin::Nav::Menu
private
Builds the nav menu.
-
#initialize(name, formatter = nil) ⇒ Builder
constructor
private
Returns a new Builder instance.
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.
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.
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.
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 |