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.



160
161
162
163
164
165
166
167
168
169
# File 'lib/mxrb/dsl/builder.rb', line 160

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



171
172
173
# File 'lib/mxrb/dsl/builder.rb', line 171

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

#search_bar(&block) ⇒ Object



181
182
183
184
185
# File 'lib/mxrb/dsl/builder.rb', line 181

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



175
176
177
178
179
# File 'lib/mxrb/dsl/builder.rb', line 175

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



201
202
203
204
205
206
207
208
# File 'lib/mxrb/dsl/builder.rb', line 201

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



187
188
189
190
191
# File 'lib/mxrb/dsl/builder.rb', line 187

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