Class: Phlexi::Menu::Builder
- Inherits:
-
Object
- Object
- Phlexi::Menu::Builder
- Defined in:
- lib/phlexi/menu/builder.rb
Overview
Builder class for constructing hierarchical menu structures. Provides a DSL for creating nested menu items with support for labels, URLs, icons, and badges.
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#items ⇒ Array<Phlexi::Menu::Item>
readonly
The collection of top-level menu items.
Instance Method Summary collapse
-
#initialize {|builder| ... } ⇒ Builder
constructor
Initializes a new menu builder.
-
#inspect ⇒ String
Returns a string representation of the menu structure.
-
#item(label) {|item| ... } ⇒ Phlexi::Menu::Item
Creates and adds a new menu item to the current menu level.
Constructor Details
#initialize {|builder| ... } ⇒ Builder
Initializes a new menu builder.
28 29 30 31 32 |
# File 'lib/phlexi/menu/builder.rb', line 28 def initialize(&) @items = [] yield self if block_given? end |
Instance Attribute Details
#items ⇒ Array<Phlexi::Menu::Item> (readonly)
Returns The collection of top-level menu items.
19 20 21 |
# File 'lib/phlexi/menu/builder.rb', line 19 def items @items end |
Instance Method Details
#inspect ⇒ String
Returns a string representation of the menu structure.
53 54 55 |
# File 'lib/phlexi/menu/builder.rb', line 53 def inspect "#<#{self.class} items=#{@items.map(&:inspect)}>" end |
#item(label) {|item| ... } ⇒ Phlexi::Menu::Item
Creates and adds a new menu item to the current menu level.
42 43 44 45 46 47 48 |
# File 'lib/phlexi/menu/builder.rb', line 42 def item(label, **, &) raise ArgumentError, "Label cannot be nil" unless label new_item = self.class::Item.new(label, **, &) @items << new_item new_item end |