Class: Koi::Menu::Builder
- Inherits:
-
Object
- Object
- Koi::Menu::Builder
- Defined in:
- lib/koi/menu/builder.rb
Instance Method Summary collapse
- #add_button(title:, url:, **options) ⇒ Object
- #add_item(title, value) ⇒ Object
- #add_items(items) ⇒ Object
- #add_link(title:, url:, **options) ⇒ Object
- #add_menu(title:, **options) {|_self| ... } ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #render ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
6 7 8 9 10 |
# File 'lib/koi/menu/builder.rb', line 6 def initialize @menu = Katalyst::Navigation::Menu.new @index = 0 @depth = 0 end |
Instance Method Details
#add_button(title:, url:, **options) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/koi/menu/builder.rb', line 52 def (title:, url:, **) @menu.items.build(type: Katalyst::Navigation::Button.name, title:, url:, **, index: @index, depth: @depth) @index += 1 end |
#add_item(title, value) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/koi/menu/builder.rb', line 18 def add_item(title, value) if value.is_a?(Hash) (title:) do |b| value.each do |k, v| b.add_item(k, v) end end else add_link(title:, url: value) end end |
#add_items(items) ⇒ Object
12 13 14 15 16 |
# File 'lib/koi/menu/builder.rb', line 12 def add_items(items) items.each do |k, v| add_item(k, v) end end |
#add_link(title:, url:, **options) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/koi/menu/builder.rb', line 42 def add_link(title:, url:, **) @menu.items.build(type: Katalyst::Navigation::Link.name, title:, url:, **, index: @index, depth: @depth) @index += 1 end |
#add_menu(title:, **options) {|_self| ... } ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/koi/menu/builder.rb', line 30 def (title:, **, &) @menu.items.build(type: Katalyst::Navigation::Heading.name, title:, **, index: @index, depth: @depth) @index += 1 @depth += 1 yield(self) @depth -= 1 end |
#render ⇒ Object
62 63 64 65 |
# File 'lib/koi/menu/builder.rb', line 62 def render @menu.published_version = @menu.build_draft_version @menu end |