Class: Tabulatr::Data::ButtonBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/tabulatr/data/button_builder.rb

Instance Method Summary collapse

Constructor Details

#initializeButtonBuilder

Returns a new instance of ButtonBuilder.



37
38
39
40
41
42
# File 'lib/tabulatr/data/button_builder.rb', line 37

def initialize
  @mode = :buttons
  @buttons = []
  @submenu = []
  val
end

Instance Method Details

#button(icon, path, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/tabulatr/data/button_builder.rb', line 48

def button(icon, path, options={})
  label = options.dup.delete(:label)
  if @mode == :buttons
    @buttons << {icon: icon, path: path, options: options}
  else
    @submenu << {icon: icon, label: label, path: path, options: options}
  end
  val
end

#dividerObject



66
67
68
69
70
# File 'lib/tabulatr/data/button_builder.rb', line 66

def divider
  raise "use dividers only in submenu" unless @mode == :submenu
  @submenu << :divider
  val
end

Yields:

  • (_self)

Yield Parameters:



58
59
60
61
62
63
64
# File 'lib/tabulatr/data/button_builder.rb', line 58

def submenu(&block)
  raise "No submenus in submenus, sorry" if @mode == :submenu
  @mode = :submenu
  yield(self)
  @mode = :buttons
  val
end

#valObject



44
45
46
# File 'lib/tabulatr/data/button_builder.rb', line 44

def val
  {buttons: @buttons, submenu: @submenu}
end