Module: Mxrb::Dsl::WidgetDsl

Included in:
ContainerBuilder, PageBuilder, TabPageBuilder, WidgetBuilder
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.



153
154
155
# File 'lib/mxrb/dsl/builder.rb', line 153

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

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



104
105
106
# File 'lib/mxrb/dsl/builder.rb', line 104

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



69
70
71
# File 'lib/mxrb/dsl/builder.rb', line 69

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



124
125
126
127
128
# File 'lib/mxrb/dsl/builder.rb', line 124

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, selection: nil, &block) ⇒ Object



88
89
90
# File 'lib/mxrb/dsl/builder.rb', line 88

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

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



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

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


108
109
110
111
112
113
114
# File 'lib/mxrb/dsl/builder.rb', line 108

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

Gallery projections remain present beside an authoritative page deep_structure in exported projects. Accept the concise projection at every widget nesting level so arbitrary native pages can be evaluated and reconstructed from their lossless payload.



96
97
98
# File 'lib/mxrb/dsl/builder.rb', line 96

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

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

Raises:

  • (ArgumentError)


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

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



59
60
61
# File 'lib/mxrb/dsl/builder.rb', line 59

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



130
131
132
133
134
135
136
137
138
139
# File 'lib/mxrb/dsl/builder.rb', line 130

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



77
78
79
80
81
82
# File 'lib/mxrb/dsl/builder.rb', line 77

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



116
117
118
119
120
121
122
# File 'lib/mxrb/dsl/builder.rb', line 116

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



100
101
102
# File 'lib/mxrb/dsl/builder.rb', line 100

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

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



84
85
86
# File 'lib/mxrb/dsl/builder.rb', line 84

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



63
64
65
66
67
# File 'lib/mxrb/dsl/builder.rb', line 63

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



55
56
57
# File 'lib/mxrb/dsl/builder.rb', line 55

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