Class: Mxrb::Dsl::WidgetBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/dsl/builder.rb

Overview

Builds sub-widgets inside a data_grid column sub-items or inside a container.

Instance Method Summary collapse

Constructor Details

#initialize(type, name, **options) ⇒ WidgetBuilder

Returns a new instance of WidgetBuilder.



117
118
119
120
121
122
123
124
125
126
# File 'lib/mxrb/dsl/builder.rb', line 117

def initialize(type, name, **options)
  @type        = type
  @name        = name.to_s
  @options     = options
  @events      = []
  @columns     = []
  @tabs        = []
  @search_bar  = nil
  @toolbar     = nil
end

Instance Method Details

#column(name, attribute: nil, caption: nil) ⇒ Object



128
129
130
# File 'lib/mxrb/dsl/builder.rb', line 128

def column(name, attribute: nil, caption: nil)
  @columns << { name: name.to_s, attribute: attribute&.to_s, caption: caption }.compact
end

#search_bar(&block) ⇒ Object



138
139
140
141
142
# File 'lib/mxrb/dsl/builder.rb', line 138

def search_bar(&block)
  sb = SearchBarBuilder.new
  sb.instance_eval(&block) if block
  @search_bar = sb.to_h
end

#tab_page(name, caption: nil, &block) ⇒ Object



132
133
134
135
136
# File 'lib/mxrb/dsl/builder.rb', line 132

def tab_page(name, caption: nil, &block)
  tab = TabPageBuilder.new(name, caption: caption)
  tab.instance_eval(&block) if block
  @tabs << tab.to_h
end

#to_hObject



158
159
160
161
162
163
164
165
# File 'lib/mxrb/dsl/builder.rb', line 158

def to_h
  options = @options.dup
  options[:columns]    = @columns    unless @columns.empty?
  options[:tabs]       = @tabs       unless @tabs.empty?
  options[:search_bar] = @search_bar if @search_bar
  options[:toolbar]    = @toolbar    if @toolbar
  { type: @type, name: @name, options: options, events: @events }
end

#toolbar(&block) ⇒ Object



144
145
146
147
148
# File 'lib/mxrb/dsl/builder.rb', line 144

def toolbar(&block)
  tb = ToolbarBuilder.new
  tb.instance_eval(&block) if block
  @toolbar = tb.to_h
end