Module: Mxrb::Dsl::WidgetDsl

Included in:
ContainerBuilder, PageBuilder, TabPageBuilder
Defined in:
lib/mxrb/dsl/builder.rb

Overview

Shared widget-building methods for PageBuilder and ContainerBuilder. Includers must implement private _widget_list returning the target array.

Instance Method Summary collapse

Instance Method Details

#bson_binary(base64, subtype: :generic) ⇒ Object

Exported native widget payloads can contain BSON identifiers at any nesting level. Keep the reconstruction helper on the shared widget DSL so pages, containers, and tab pages all evaluate the same export.



102
103
104
# File 'lib/mxrb/dsl/builder.rb', line 102

def bson_binary(base64, subtype: :generic)
  BSON::Binary.new(Base64.strict_decode64(base64), subtype.to_sym)
end

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



53
54
55
# File 'lib/mxrb/dsl/builder.rb', line 53

def button(name, caption: nil, &block)
  _add_widget(:button, name, caption: caption || name.to_s, &block)
end

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



26
27
28
# File 'lib/mxrb/dsl/builder.rb', line 26

def check_box(name, attribute: nil, caption: nil, &block)
  _add_widget(:check_box, name, attribute: attribute, caption: caption, &block)
end

#container(name, class_name: nil, &block) ⇒ Object



73
74
75
76
77
# File 'lib/mxrb/dsl/builder.rb', line 73

def container(name, class_name: nil, &block)
  cb = ContainerBuilder.new(name, class_name: class_name)
  cb.instance_eval(&block) if block
  _widget_list << cb.to_h
end

#data_grid(name, entity: nil, &block) ⇒ Object



45
46
47
# File 'lib/mxrb/dsl/builder.rb', line 45

def data_grid(name, entity: nil, &block)
  _add_widget(:data_grid, name, entity: entity, &block)
end

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



30
31
32
# File 'lib/mxrb/dsl/builder.rb', line 30

def date_picker(name, attribute: nil, caption: nil, &block)
  _add_widget(:date_picker, name, attribute: attribute, caption: caption, &block)
end


57
58
59
60
61
62
63
# File 'lib/mxrb/dsl/builder.rb', line 57

def drop_down(name, attribute: nil, caption: nil)
  _widget_list << {
    type: :drop_down, name: name.to_s,
    options: { attribute: attribute&.to_s, caption: caption }.compact,
    events: []
  }
end

#native_widget(name, type:, deep_structure:) ⇒ Object

Raises:

  • (ArgumentError)


90
91
92
93
94
95
96
97
# File 'lib/mxrb/dsl/builder.rb', line 90

def native_widget(name, type:, deep_structure:)
  raise ArgumentError, "deep_structure requires a Hash" unless deep_structure.is_a?(Hash)

  _widget_list << {
    type: :native_widget, name: name.to_s,
    options: { native_type: type.to_s, deep_structure: deep_structure }, events: []
  }
end

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



16
17
18
# File 'lib/mxrb/dsl/builder.rb', line 16

def number_input(name, attribute: nil, caption: nil, &block)
  _add_widget(:number_input, name, attribute: attribute, caption: caption, &block)
end

#pluggable_widget(name, widget_id:, widget_name: nil, properties: {}, class_name: nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/mxrb/dsl/builder.rb', line 79

def pluggable_widget(name, widget_id:, widget_name: nil, properties: {}, class_name: nil)
  _widget_list << {
    type: :pluggable_widget, name: name.to_s,
    options: {
      widget_id: widget_id.to_s, widget_name: (widget_name || name).to_s,
      properties: properties, class: class_name
    }.compact,
    events: []
  }
end

#reference_selector(name, attribute: nil, caption: nil, display_attribute: nil, &block) ⇒ Object



34
35
36
37
38
39
# File 'lib/mxrb/dsl/builder.rb', line 34

def reference_selector(name, attribute: nil, caption: nil, display_attribute: nil, &block)
  _add_widget(
    :reference_selector, name, attribute: attribute, caption: caption,
                               display_attribute: display_attribute, &block
  )
end

#snippet(name, from: nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/mxrb/dsl/builder.rb', line 65

def snippet(name, from: nil)
  _widget_list << {
    type: :snippet, name: name.to_s,
    options: { snippet: (from || name).to_s },
    events: []
  }
end

#tab_control(name, &block) ⇒ Object



49
50
51
# File 'lib/mxrb/dsl/builder.rb', line 49

def tab_control(name, &block)
  _add_widget(:tab_control, name, &block)
end

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



41
42
43
# File 'lib/mxrb/dsl/builder.rb', line 41

def text(name, caption: nil, &block)
  _add_widget(:text, name, caption: caption || name.to_s, &block)
end

#text_area(name, attribute: nil, caption: nil, lines: 5, &block) ⇒ Object



20
21
22
23
24
# File 'lib/mxrb/dsl/builder.rb', line 20

def text_area(name, attribute: nil, caption: nil, lines: 5, &block)
  _add_widget(
    :text_area, name, attribute: attribute, caption: caption, lines: lines, &block
  )
end

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



12
13
14
# File 'lib/mxrb/dsl/builder.rb', line 12

def text_box(name, attribute: nil, caption: nil, &block)
  _add_widget(:text_box, name, attribute: attribute, caption: caption, &block)
end