Class: Trestle::Toolbar::Menu
- Inherits:
-
Object
- Object
- Trestle::Toolbar::Menu
- Defined in:
- lib/trestle/toolbar/menu.rb
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #build(&block) ⇒ Object
-
#initialize(template) ⇒ Menu
constructor
A new instance of Menu.
- #render_items ⇒ Object
- #render_toggle(options = {}) ⇒ Object
Constructor Details
#initialize(template) ⇒ Menu
Returns a new instance of Menu.
8 9 10 11 |
# File 'lib/trestle/toolbar/menu.rb', line 8 def initialize(template) @template = template @items = [] end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
6 7 8 |
# File 'lib/trestle/toolbar/menu.rb', line 6 def items @items end |
Instance Method Details
#build(&block) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/trestle/toolbar/menu.rb', line 13 def build(&block) builder = Builder.new(self, @template) result = @template.capture { @template.instance_exec(builder, &block) } items << result if result.present? end |
#render_items ⇒ Object
26 27 28 |
# File 'lib/trestle/toolbar/menu.rb', line 26 def render_items tag.ul(safe_join(items, "\n"), class: "dropdown-menu dropdown-menu-end", role: "menu") end |
#render_toggle(options = {}) ⇒ Object
20 21 22 23 24 |
# File 'lib/trestle/toolbar/menu.rb', line 20 def render_toggle(={}) tag.(type: "button", class: Array([:class]) + ["dropdown-toggle dropdown-toggle-split"], data: { bs_toggle: "dropdown" }, aria: { expanded: false }) do tag.span(I18n.t("trestle.ui.toggle_dropdown", default: "Toggle dropdown"), class: "visually-hidden") end end |