Class: Trestle::Toolbar::Menu::Builder

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

Instance Method Summary collapse

Constructor Details

#initialize(menu, template) ⇒ Builder

Returns a new instance of Builder.


36
37
38
# File 'lib/trestle/toolbar/menu.rb', line 36

def initialize(menu, template)
  @menu, @template = menu, template
end

Instance Method Details

#dividerObject


51
52
53
# File 'lib/trestle/toolbar/menu.rb', line 51

def divider
  item(class: "divider")
end

#header(text) ⇒ Object


47
48
49
# File 'lib/trestle/toolbar/menu.rb', line 47

def header(text)
  item(class: "dropdown-header") { text }
end

#item(options = {}, &block) ⇒ Object


55
56
57
58
59
60
61
62
# File 'lib/trestle/toolbar/menu.rb', line 55

def item(options={}, &block)
  opts = { role: "presentation" }.merge(options)
  item = block_given? ? (:li, opts, &block) : (:li, "", opts)

  @menu.items << item

  nil
end

40
41
42
43
44
45
# File 'lib/trestle/toolbar/menu.rb', line 40

def link(content, instance_or_url=nil, options={}, &block)
  options[:class] = Array(options[:class])
  options[:class] << "dropdown-item"

  item { admin_link_to(content, instance_or_url, options, &block) }
end