glimmer-dsl-opal 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/README.md +1003 -58
- data/VERSION +1 -1
- data/lib/glimmer-dsl-opal.rb +26 -8
- data/lib/glimmer/data_binding/element_binding.rb +1 -1
- data/lib/glimmer/data_binding/ext/observable_model.rb +40 -0
- data/lib/glimmer/data_binding/list_selection_binding.rb +1 -1
- data/lib/glimmer/data_binding/table_items_binding.rb +70 -0
- data/lib/glimmer/dsl/opal/async_exec_expression.rb +17 -0
- data/lib/glimmer/dsl/opal/column_properties_expression.rb +22 -0
- data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/dsl.rb +10 -12
- data/lib/glimmer/dsl/opal/layout_data_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/{text_expression.rb → layout_expression.rb} +5 -5
- data/lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb +2 -3
- data/lib/glimmer/dsl/opal/message_box_expression.rb +20 -0
- data/lib/glimmer/dsl/opal/observe_expression.rb +32 -0
- data/lib/glimmer/dsl/opal/shell_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/{composite_expression.rb → table_column_expression.rb} +3 -3
- data/lib/glimmer/dsl/opal/{list_expression.rb → table_expression.rb} +3 -3
- data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +29 -0
- data/lib/glimmer/dsl/opal/widget_expression.rb +23 -0
- data/lib/glimmer/opal/display_proxy.rb +23 -0
- data/lib/glimmer/opal/element_proxy.rb +48 -13
- data/lib/glimmer/swt/browser_proxy.rb +27 -0
- data/lib/glimmer/swt/button_proxy.rb +40 -0
- data/lib/glimmer/{opal/select_proxy.rb → swt/combo_proxy.rb} +15 -11
- data/lib/glimmer/swt/composite_proxy.rb +31 -0
- data/lib/glimmer/{opal → swt}/event_listener_proxy.rb +1 -1
- data/lib/glimmer/{opal → swt}/grid_layout_proxy.rb +7 -18
- data/lib/glimmer/swt/label_proxy.rb +30 -0
- data/lib/glimmer/swt/layout_data_proxy.rb +52 -0
- data/lib/glimmer/swt/layout_proxy.rb +60 -0
- data/lib/glimmer/{opal → swt}/list_proxy.rb +18 -15
- data/lib/glimmer/swt/message_box_proxy.rb +146 -0
- data/lib/glimmer/{opal → swt}/point.rb +1 -1
- data/lib/glimmer/{opal → swt}/property_owner.rb +1 -1
- data/lib/glimmer/swt/shell_proxy.rb +235 -0
- data/lib/glimmer/swt/tab_folder_proxy.rb +52 -0
- data/lib/glimmer/swt/tab_item_proxy.rb +101 -0
- data/lib/glimmer/swt/table_column_proxy.rb +56 -0
- data/lib/glimmer/swt/table_item_proxy.rb +147 -0
- data/lib/glimmer/swt/table_proxy.rb +177 -0
- data/lib/glimmer/swt/text_proxy.rb +46 -0
- data/lib/glimmer/swt/widget_proxy.rb +389 -0
- data/lib/jquery.js +2 -0
- data/lib/samples/elaborate/contact_manager.rb +2 -3
- data/lib/samples/elaborate/login.rb +0 -1
- data/lib/samples/elaborate/tic_tac_toe.rb +5 -5
- data/lib/samples/hello/hello_computed.rb +19 -19
- data/lib/samples/hello/hello_tab.rb +2 -2
- metadata +92 -59
- data/lib/glimmer/config.rb +0 -22
- data/lib/glimmer/dsl/engine.rb +0 -193
- data/lib/glimmer/dsl/expression.rb +0 -42
- data/lib/glimmer/dsl/expression_handler.rb +0 -48
- data/lib/glimmer/dsl/opal/browser_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/button_expression.rb +0 -18
- data/lib/glimmer/dsl/opal/combo_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/grid_layout_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/label_expression.rb +0 -17
- data/lib/glimmer/dsl/parent_expression.rb +0 -12
- data/lib/glimmer/dsl/static_expression.rb +0 -36
- data/lib/glimmer/dsl/top_level_expression.rb +0 -7
- data/lib/glimmer/error.rb +0 -6
- data/lib/glimmer/invalid_keyword_error.rb +0 -6
- data/lib/glimmer/opal/div_proxy.rb +0 -20
- data/lib/glimmer/opal/document_proxy.rb +0 -90
- data/lib/glimmer/opal/iframe_proxy.rb +0 -23
- data/lib/glimmer/opal/input_proxy.rb +0 -41
- data/lib/glimmer/opal/label_proxy.rb +0 -25
- data/lib/glimmer/opal/layout_data_proxy.rb +0 -31
@@ -37,11 +37,11 @@ class TicTacToe
|
|
37
37
|
display_game_over_message("Draw!")
|
38
38
|
end
|
39
39
|
|
40
|
-
def display_game_over_message(
|
41
|
-
message_box
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def display_game_over_message(message_text)
|
41
|
+
message_box(@shell) {
|
42
|
+
text 'Game Over'
|
43
|
+
message message_text
|
44
|
+
}.open
|
45
45
|
@tic_tac_toe_board.reset
|
46
46
|
end
|
47
47
|
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'hello_computed/contact'
|
2
2
|
|
3
3
|
class HelloComputed
|
4
4
|
include Glimmer
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@contact = Contact.new(
|
8
|
-
first_name:
|
9
|
-
last_name:
|
8
|
+
first_name: 'Barry',
|
9
|
+
last_name: 'McKibbin',
|
10
10
|
year_of_birth: 1985
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
14
|
def launch
|
15
15
|
shell {
|
16
|
-
text
|
16
|
+
text 'Hello, Computed!'
|
17
17
|
composite {
|
18
18
|
grid_layout {
|
19
19
|
num_columns 2
|
@@ -21,44 +21,44 @@ class HelloComputed
|
|
21
21
|
horizontal_spacing 20
|
22
22
|
vertical_spacing 10
|
23
23
|
}
|
24
|
-
label {text
|
24
|
+
label {text 'First &Name: '}
|
25
25
|
text {
|
26
26
|
text bind(@contact, :first_name)
|
27
27
|
layout_data {
|
28
|
-
|
29
|
-
|
28
|
+
horizontal_alignment :fill
|
29
|
+
grab_excess_horizontal_space true
|
30
30
|
}
|
31
31
|
}
|
32
|
-
label {text
|
32
|
+
label {text '&Last Name: '}
|
33
33
|
text {
|
34
34
|
text bind(@contact, :last_name)
|
35
35
|
layout_data {
|
36
|
-
|
37
|
-
|
36
|
+
horizontal_alignment :fill
|
37
|
+
grab_excess_horizontal_space true
|
38
38
|
}
|
39
39
|
}
|
40
|
-
label {text
|
40
|
+
label {text '&Year of Birth: '}
|
41
41
|
text {
|
42
42
|
text bind(@contact, :year_of_birth)
|
43
43
|
layout_data {
|
44
|
-
|
45
|
-
|
44
|
+
horizontal_alignment :fill
|
45
|
+
grab_excess_horizontal_space true
|
46
46
|
}
|
47
47
|
}
|
48
|
-
label {text
|
48
|
+
label {text 'Name: '}
|
49
49
|
label {
|
50
50
|
text bind(@contact, :name, computed_by: [:first_name, :last_name])
|
51
51
|
layout_data {
|
52
|
-
|
53
|
-
|
52
|
+
horizontal_alignment :fill
|
53
|
+
grab_excess_horizontal_space true
|
54
54
|
}
|
55
55
|
}
|
56
|
-
label {text
|
56
|
+
label {text 'Age: '}
|
57
57
|
label {
|
58
58
|
text bind(@contact, :age, on_write: :to_i, computed_by: [:year_of_birth])
|
59
59
|
layout_data {
|
60
|
-
|
61
|
-
|
60
|
+
horizontal_alignment :fill
|
61
|
+
grab_excess_horizontal_space true
|
62
62
|
}
|
63
63
|
}
|
64
64
|
}
|
@@ -2,7 +2,7 @@ class HelloTab
|
|
2
2
|
include Glimmer
|
3
3
|
def launch
|
4
4
|
shell {
|
5
|
-
text "Hello Tab"
|
5
|
+
text "Hello, Tab!"
|
6
6
|
tab_folder {
|
7
7
|
tab_item {
|
8
8
|
text "English"
|
@@ -13,7 +13,7 @@ class HelloTab
|
|
13
13
|
tab_item {
|
14
14
|
text "French"
|
15
15
|
label {
|
16
|
-
text "Bonjour Univers!"
|
16
|
+
text "Bonjour, Univers!"
|
17
17
|
}
|
18
18
|
}
|
19
19
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -16,42 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.9.
|
19
|
+
version: 0.9.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.9.
|
26
|
+
version: 0.9.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: glimmer-dsl-xml
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 3.5.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.5.0
|
48
|
-
type: :development
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
40
|
+
version: 0.1.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: puts_debuggerer
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,28 +118,70 @@ dependencies:
|
|
132
118
|
requirements:
|
133
119
|
- - "~>"
|
134
120
|
- !ruby/object:Gem::Version
|
135
|
-
version: 0.
|
121
|
+
version: 0.8.0.alpha2
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - "~>"
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 0.8.0.alpha2
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
name: opal-rails
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - "~>"
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: 1.1.2
|
136
|
+
type: :development
|
137
|
+
prerelease: false
|
138
|
+
version_requirements: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - "~>"
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 1.1.2
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: opal-async
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 1.1.0
|
136
150
|
type: :development
|
137
151
|
prerelease: false
|
138
152
|
version_requirements: !ruby/object:Gem::Requirement
|
139
153
|
requirements:
|
140
154
|
- - "~>"
|
141
155
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
156
|
+
version: 1.1.0
|
143
157
|
- !ruby/object:Gem::Dependency
|
144
|
-
name: opal-
|
158
|
+
name: opal-jquery
|
145
159
|
requirement: !ruby/object:Gem::Requirement
|
146
160
|
requirements:
|
147
161
|
- - "~>"
|
148
162
|
- !ruby/object:Gem::Version
|
149
|
-
version: 0.
|
163
|
+
version: 0.4.4
|
150
164
|
type: :development
|
151
165
|
prerelease: false
|
152
166
|
version_requirements: !ruby/object:Gem::Requirement
|
153
167
|
requirements:
|
154
168
|
- - "~>"
|
155
169
|
- !ruby/object:Gem::Version
|
156
|
-
version: 0.
|
170
|
+
version: 0.4.4
|
171
|
+
- !ruby/object:Gem::Dependency
|
172
|
+
name: glimmer-dsl-opal
|
173
|
+
requirement: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
type: :development
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
157
185
|
description: Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
|
158
186
|
email: andy.am@gmail.com
|
159
187
|
executables: []
|
@@ -168,48 +196,53 @@ files:
|
|
168
196
|
- README.md
|
169
197
|
- VERSION
|
170
198
|
- lib/glimmer-dsl-opal.rb
|
171
|
-
- lib/glimmer/config.rb
|
172
199
|
- lib/glimmer/data_binding/element_binding.rb
|
200
|
+
- lib/glimmer/data_binding/ext/observable_model.rb
|
173
201
|
- lib/glimmer/data_binding/list_selection_binding.rb
|
174
202
|
- lib/glimmer/data_binding/observable_element.rb
|
175
|
-
- lib/glimmer/
|
176
|
-
- lib/glimmer/dsl/
|
177
|
-
- lib/glimmer/dsl/expression_handler.rb
|
203
|
+
- lib/glimmer/data_binding/table_items_binding.rb
|
204
|
+
- lib/glimmer/dsl/opal/async_exec_expression.rb
|
178
205
|
- lib/glimmer/dsl/opal/bind_expression.rb
|
179
|
-
- lib/glimmer/dsl/opal/
|
180
|
-
- lib/glimmer/dsl/opal/button_expression.rb
|
181
|
-
- lib/glimmer/dsl/opal/combo_expression.rb
|
206
|
+
- lib/glimmer/dsl/opal/column_properties_expression.rb
|
182
207
|
- lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb
|
183
|
-
- lib/glimmer/dsl/opal/composite_expression.rb
|
184
208
|
- lib/glimmer/dsl/opal/data_binding_expression.rb
|
185
209
|
- lib/glimmer/dsl/opal/dsl.rb
|
186
|
-
- lib/glimmer/dsl/opal/grid_layout_expression.rb
|
187
|
-
- lib/glimmer/dsl/opal/label_expression.rb
|
188
210
|
- lib/glimmer/dsl/opal/layout_data_expression.rb
|
189
|
-
- lib/glimmer/dsl/opal/
|
211
|
+
- lib/glimmer/dsl/opal/layout_expression.rb
|
190
212
|
- lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb
|
213
|
+
- lib/glimmer/dsl/opal/message_box_expression.rb
|
214
|
+
- lib/glimmer/dsl/opal/observe_expression.rb
|
191
215
|
- lib/glimmer/dsl/opal/property_expression.rb
|
192
216
|
- lib/glimmer/dsl/opal/shell_expression.rb
|
193
|
-
- lib/glimmer/dsl/opal/
|
217
|
+
- lib/glimmer/dsl/opal/table_column_expression.rb
|
218
|
+
- lib/glimmer/dsl/opal/table_expression.rb
|
219
|
+
- lib/glimmer/dsl/opal/table_items_data_binding_expression.rb
|
220
|
+
- lib/glimmer/dsl/opal/widget_expression.rb
|
194
221
|
- lib/glimmer/dsl/opal/widget_listener_expression.rb
|
195
|
-
- lib/glimmer/
|
196
|
-
- lib/glimmer/dsl/static_expression.rb
|
197
|
-
- lib/glimmer/dsl/top_level_expression.rb
|
198
|
-
- lib/glimmer/error.rb
|
199
|
-
- lib/glimmer/invalid_keyword_error.rb
|
200
|
-
- lib/glimmer/opal/div_proxy.rb
|
201
|
-
- lib/glimmer/opal/document_proxy.rb
|
222
|
+
- lib/glimmer/opal/display_proxy.rb
|
202
223
|
- lib/glimmer/opal/element_proxy.rb
|
203
|
-
- lib/glimmer/
|
204
|
-
- lib/glimmer/
|
205
|
-
- lib/glimmer/
|
206
|
-
- lib/glimmer/
|
207
|
-
- lib/glimmer/
|
208
|
-
- lib/glimmer/
|
209
|
-
- lib/glimmer/
|
210
|
-
- lib/glimmer/
|
211
|
-
- lib/glimmer/
|
212
|
-
- lib/glimmer/
|
224
|
+
- lib/glimmer/swt/browser_proxy.rb
|
225
|
+
- lib/glimmer/swt/button_proxy.rb
|
226
|
+
- lib/glimmer/swt/combo_proxy.rb
|
227
|
+
- lib/glimmer/swt/composite_proxy.rb
|
228
|
+
- lib/glimmer/swt/event_listener_proxy.rb
|
229
|
+
- lib/glimmer/swt/grid_layout_proxy.rb
|
230
|
+
- lib/glimmer/swt/label_proxy.rb
|
231
|
+
- lib/glimmer/swt/layout_data_proxy.rb
|
232
|
+
- lib/glimmer/swt/layout_proxy.rb
|
233
|
+
- lib/glimmer/swt/list_proxy.rb
|
234
|
+
- lib/glimmer/swt/message_box_proxy.rb
|
235
|
+
- lib/glimmer/swt/point.rb
|
236
|
+
- lib/glimmer/swt/property_owner.rb
|
237
|
+
- lib/glimmer/swt/shell_proxy.rb
|
238
|
+
- lib/glimmer/swt/tab_folder_proxy.rb
|
239
|
+
- lib/glimmer/swt/tab_item_proxy.rb
|
240
|
+
- lib/glimmer/swt/table_column_proxy.rb
|
241
|
+
- lib/glimmer/swt/table_item_proxy.rb
|
242
|
+
- lib/glimmer/swt/table_proxy.rb
|
243
|
+
- lib/glimmer/swt/text_proxy.rb
|
244
|
+
- lib/glimmer/swt/widget_proxy.rb
|
245
|
+
- lib/jquery.js
|
213
246
|
- lib/samples/elaborate/contact_manager.rb
|
214
247
|
- lib/samples/elaborate/contact_manager/contact.rb
|
215
248
|
- lib/samples/elaborate/contact_manager/contact_manager_presenter.rb
|
@@ -233,7 +266,7 @@ homepage: http://github.com/AndyObtiva/glimmer-dsl-opal
|
|
233
266
|
licenses:
|
234
267
|
- MIT
|
235
268
|
metadata: {}
|
236
|
-
post_install_message:
|
269
|
+
post_install_message:
|
237
270
|
rdoc_options: []
|
238
271
|
require_paths:
|
239
272
|
- lib
|
@@ -249,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
282
|
version: '0'
|
250
283
|
requirements: []
|
251
284
|
rubygems_version: 3.1.2
|
252
|
-
signing_key:
|
285
|
+
signing_key:
|
253
286
|
specification_version: 4
|
254
287
|
summary: Glimmer DSL for Opal
|
255
288
|
test_files: []
|
data/lib/glimmer/config.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module Glimmer
|
2
|
-
module Config
|
3
|
-
class << self
|
4
|
-
# Returns Glimmer logger (standard Ruby logger)
|
5
|
-
def logger
|
6
|
-
# unless defined? @@logger
|
7
|
-
# @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
|
8
|
-
# end
|
9
|
-
@@logger if defined? @@logger
|
10
|
-
end
|
11
|
-
|
12
|
-
def enable_logging
|
13
|
-
@@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
if ENV['GLIMMER_LOGGER_LEVEL']
|
20
|
-
Glimmer::Config.enable_logging
|
21
|
-
Glimmer::Config.logger.level = ENV['GLIMMER_LOGGER_LEVEL'].downcase
|
22
|
-
end
|
data/lib/glimmer/dsl/engine.rb
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
require 'glimmer'
|
2
|
-
require 'glimmer/dsl/expression_handler'
|
3
|
-
|
4
|
-
module Glimmer
|
5
|
-
module DSL
|
6
|
-
# Glimmer DSL Engine
|
7
|
-
#
|
8
|
-
# Follows Interpreter and Chain of Responsibility Design Patterns
|
9
|
-
#
|
10
|
-
# When DSL engine interprets an expression, it attempts to handle
|
11
|
-
# with ordered expression array specified via `.expressions=` method.
|
12
|
-
class Engine
|
13
|
-
class << self
|
14
|
-
def dsl=(dsl_name)
|
15
|
-
dsl_name = dsl_name&.to_sym
|
16
|
-
if dsl_name
|
17
|
-
dsl_stack.push(dsl_name)
|
18
|
-
else
|
19
|
-
dsl_stack.clear
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def dsl
|
24
|
-
dsl_stack.last
|
25
|
-
end
|
26
|
-
|
27
|
-
def dsls
|
28
|
-
static_expressions.values.map(&:keys).flatten.uniq
|
29
|
-
end
|
30
|
-
|
31
|
-
def disable_dsl(dsl_name)
|
32
|
-
dsl_name = dsl_name.to_sym
|
33
|
-
disabled_dsls << dsl_name
|
34
|
-
end
|
35
|
-
|
36
|
-
def enable_dsl(dsl_name)
|
37
|
-
dsl_name = dsl_name.to_sym
|
38
|
-
disabled_dsls.delete(dsl_name)
|
39
|
-
end
|
40
|
-
|
41
|
-
def disabled_dsls
|
42
|
-
@disabled_dsls ||= []
|
43
|
-
end
|
44
|
-
|
45
|
-
def enabled_dsls=(dsl_names)
|
46
|
-
dsls.each {|dsl_name| disable_dsl(dsl_name)}
|
47
|
-
dsl_names.each {|dsl_name| enable_dsl(dsl_name)}
|
48
|
-
end
|
49
|
-
|
50
|
-
# Resets Glimmer's engine activity and configuration. Useful in rspec before or after blocks in tests.
|
51
|
-
def reset
|
52
|
-
parent_stacks.values.each do |a_parent_stack|
|
53
|
-
a_parent_stack.clear
|
54
|
-
end
|
55
|
-
dsl_stack.clear
|
56
|
-
disabled_dsls.clear
|
57
|
-
end
|
58
|
-
|
59
|
-
# Dynamic expression chains of responsibility indexed by dsl
|
60
|
-
def dynamic_expression_chains_of_responsibility
|
61
|
-
@dynamic_expression_chains_of_responsibility ||= {}
|
62
|
-
end
|
63
|
-
|
64
|
-
# Static expressions indexed by keyword and dsl
|
65
|
-
def static_expressions
|
66
|
-
@static_expressions ||= {}
|
67
|
-
end
|
68
|
-
|
69
|
-
# Sets an ordered array of DSL expressions to support
|
70
|
-
#
|
71
|
-
# Every expression has an underscored name corresponding to an upper
|
72
|
-
# camelcase AbstractExpression subclass name in glimmer/dsl
|
73
|
-
#
|
74
|
-
# They are used in order following the Chain of Responsibility Design
|
75
|
-
# Pattern when interpretting a DSL expression
|
76
|
-
def add_dynamic_expressions(dsl_namespace, expression_names)
|
77
|
-
dsl = dsl_namespace.name.split("::").last.downcase.to_sym
|
78
|
-
dynamic_expression_chains_of_responsibility[dsl] = expression_names.reverse.map do |expression_name|
|
79
|
-
expression_class(dsl_namespace, expression_name).new
|
80
|
-
end.reduce(nil) do |last_expresion_handler, expression|
|
81
|
-
Glimmer::Config.logger&.debug "Adding dynamic expression: #{expression.class.name}"
|
82
|
-
expression_handler = ExpressionHandler.new(expression)
|
83
|
-
expression_handler.next = last_expresion_handler if last_expresion_handler
|
84
|
-
expression_handler
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def add_static_expression(static_expression)
|
89
|
-
Glimmer::Config.logger&.debug "Adding static expression: #{static_expression.class.name}"
|
90
|
-
keyword = static_expression.class.keyword
|
91
|
-
static_expression_dsl = static_expression.class.dsl
|
92
|
-
static_expressions[keyword] ||= {}
|
93
|
-
static_expressions[keyword][static_expression_dsl] = static_expression
|
94
|
-
Glimmer.send(:define_method, keyword) do |*args, &block|
|
95
|
-
begin
|
96
|
-
retrieved_static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
|
97
|
-
static_expression_dsl = (Glimmer::DSL::Engine.static_expressions[keyword].keys - Glimmer::DSL::Engine.disabled_dsls).last if retrieved_static_expression.nil?
|
98
|
-
interpretation = nil
|
99
|
-
if retrieved_static_expression.nil? && Glimmer::DSL::Engine.dsl && (static_expression_dsl.nil? || !Glimmer::DSL::Engine.static_expressions[keyword][static_expression_dsl].is_a?(TopLevelExpression))
|
100
|
-
begin
|
101
|
-
interpretation = Glimmer::DSL::Engine.interpret(keyword, *args, &block)
|
102
|
-
rescue => e
|
103
|
-
Glimmer::DSL::Engine.reset
|
104
|
-
raise e if static_expression_dsl.nil? || !Glimmer::DSL::Engine.static_expressions[keyword][static_expression_dsl].is_a?(TopLevelExpression)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
if interpretation
|
108
|
-
interpretation
|
109
|
-
else
|
110
|
-
raise Glimmer::Error, "Unsupported keyword: #{keyword}" unless static_expression_dsl || retrieved_static_expression
|
111
|
-
Glimmer::DSL::Engine.dsl_stack.push(static_expression_dsl || Glimmer::DSL::Engine.dsl)
|
112
|
-
static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
|
113
|
-
if !static_expression.can_interpret?(Glimmer::DSL::Engine.parent, keyword, *args, &block)
|
114
|
-
raise Error, "Invalid use of Glimmer keyword #{keyword} with args #{args} under parent #{Glimmer::DSL::Engine.parent}"
|
115
|
-
else
|
116
|
-
Glimmer::Config.logger&.debug "#{static_expression.class.name} will handle expression keyword #{keyword}"
|
117
|
-
static_expression.interpret(Glimmer::DSL::Engine.parent, keyword, *args, &block).tap do |ui_object|
|
118
|
-
Glimmer::DSL::Engine.add_content(ui_object, static_expression, &block) unless block.nil?
|
119
|
-
Glimmer::DSL::Engine.dsl_stack.pop
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
rescue StandardError => e
|
124
|
-
# Glimmer::DSL::Engine.dsl_stack.pop
|
125
|
-
Glimmer::DSL::Engine.reset
|
126
|
-
raise e
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def expression_class(dsl_namespace, expression_name)
|
132
|
-
dsl_namespace.const_get(expression_class_name(expression_name).to_sym)
|
133
|
-
end
|
134
|
-
|
135
|
-
def expression_class_name(expression_name)
|
136
|
-
"#{expression_name}_expression".camelcase(:upper)
|
137
|
-
end
|
138
|
-
|
139
|
-
# Interprets Glimmer dynamic DSL expression consisting of keyword, args, and block (e.g. shell(:no_resize) { ... })
|
140
|
-
def interpret(keyword, *args, &block)
|
141
|
-
keyword = keyword.to_s
|
142
|
-
dynamic_expression_dsl = (dynamic_expression_chains_of_responsibility.keys - disabled_dsls).last if dsl.nil?
|
143
|
-
dsl_stack.push(dynamic_expression_dsl || dsl)
|
144
|
-
expression = dynamic_expression_chains_of_responsibility[dsl].handle(parent, keyword, *args, &block)
|
145
|
-
expression.interpret(parent, keyword, *args, &block).tap do |ui_object|
|
146
|
-
add_content(ui_object, expression, &block)
|
147
|
-
dsl_stack.pop
|
148
|
-
end
|
149
|
-
rescue StandardError => e
|
150
|
-
# dsl_stack.pop
|
151
|
-
reset
|
152
|
-
raise e
|
153
|
-
end
|
154
|
-
|
155
|
-
# Adds content block to parent UI object
|
156
|
-
#
|
157
|
-
# This allows evaluating parent UI object properties and children
|
158
|
-
#
|
159
|
-
# For example, a shell widget would get properties set and children added
|
160
|
-
def add_content(parent, expression, &block)
|
161
|
-
if block_given? && expression.is_a?(ParentExpression)
|
162
|
-
dsl_stack.push(expression.class.dsl)
|
163
|
-
parent_stack.push(parent)
|
164
|
-
expression.add_content(parent, &block)
|
165
|
-
parent_stack.pop
|
166
|
-
dsl_stack.pop
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
# Current parent while evaluating Glimmer DSL (nil if just started or done evaluatiing)
|
171
|
-
#
|
172
|
-
# Parents are maintained in a stack while evaluating Glimmer DSL
|
173
|
-
# to ensure properly ordered interpretation of DSL syntax
|
174
|
-
def parent
|
175
|
-
parent_stack.last
|
176
|
-
end
|
177
|
-
|
178
|
-
def parent_stack
|
179
|
-
parent_stacks[dsl] ||= []
|
180
|
-
end
|
181
|
-
|
182
|
-
def parent_stacks
|
183
|
-
@parent_stacks ||= {}
|
184
|
-
end
|
185
|
-
|
186
|
-
# Enables multiple DSLs to play well with each other when mixing together
|
187
|
-
def dsl_stack
|
188
|
-
@dsl_stack ||= []
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|