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


29
30
31
# File 'lib/trestle/toolbar/menu.rb', line 29

def render_items
  (:ul, safe_join(items, "\n"), class: "dropdown-menu dropdown-menu-right", role: "menu")
end

#render_toggle(options = {}) ⇒ Object


20
21
22
23
24
25
26
27
# File 'lib/trestle/toolbar/menu.rb', line 20

def render_toggle(options={})
  (:button, type: "button", class: Array(options[:class]) + ["dropdown-toggle"], data: { toggle: "dropdown" }) do
    safe_join([
      (:span, "", class: "caret"),
      (:span, I18n.t("trestle.ui.toggle_dropdown", default: "Toggle dropdown"), class: "sr-only")
    ])
  end
end