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.



33
34
35
# File 'lib/trestle/toolbar/menu.rb', line 33

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

Instance Method Details

#dividerObject



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

def divider
  item { tag.hr(class: "dropdown-divider") }
end

#header(text) ⇒ Object



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

def header(text)
  item { tag.h6(text, class: "dropdown-header") }
end

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



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

def item(options={}, &block)
  item = block_given? ? tag.li(**options, &block) : tag.li("", **options)

  @menu.items << item

  nil
end


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

def link(content, instance_or_url=nil, options={}, &block)
  if instance_or_url.is_a?(Hash)
    instance_or_url, options = nil, instance_or_url
  end

  options[:class] = Array(options[:class])
  options[:class] << "dropdown-item"

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