Class: Trestle::Toolbar::Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/toolbar/menu.rb

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#itemsObject (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_itemsObject



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(options={})
  tag.button(type: "button", class: Array(options[: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