Class: Katalyst::Navigation::Frontend::Builder
- Inherits:
-
Object
- Object
- Katalyst::Navigation::Frontend::Builder
- Defined in:
- app/helpers/katalyst/navigation/frontend/builder.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(template, list: {}, item: {}, **menu_attributes) ⇒ Builder
constructor
A new instance of Builder.
- #render(tree) ⇒ Object
- #render_button(link) ⇒ Object
- #render_children(item) ⇒ Object
- #render_heading(heading) ⇒ Object
- #render_item(item) ⇒ Object
- #render_link(link) ⇒ Object
Constructor Details
#initialize(template, list: {}, item: {}, **menu_attributes) ⇒ Builder
Returns a new instance of Builder.
12 13 14 15 16 17 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 12 def initialize(template, list: {}, item: {}, **) self.template = template @menu_attributes = .freeze @list_attributes = list.freeze @item_attributes = item.freeze end |
Instance Attribute Details
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 8 def template @template end |
Instance Method Details
#render(tree) ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 19 def render(tree) tag.ul(**(tree)) do tree.each do |item| concat render_item(item) end end end |
#render_button(link) ⇒ Object
52 53 54 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 52 def (link) link_to(link.title, link.url, **link.link_attributes) end |
#render_children(item) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 36 def render_children(item) tag.ul(**list_attributes(item)) do item.children.each do |child| concat render_item(child) end end end |
#render_heading(heading) ⇒ Object
44 45 46 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 44 def render_heading(heading) tag.span(heading.title) end |
#render_item(item) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 27 def render_item(item) return unless item.visible? tag.li(**item_attributes(item)) do concat public_send(:"render_#{item.model_name.param_key}", item) concat render_children(item) if item.children.any? end end |
#render_link(link) ⇒ Object
48 49 50 |
# File 'app/helpers/katalyst/navigation/frontend/builder.rb', line 48 def render_link(link) link_to(link.title, link.url, **link.link_attributes) end |