glimmer-dsl-opal 0.0.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +995 -74
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal.rb +42 -7
  6. data/lib/glimmer-dsl-opal/ext/exception.rb +5 -0
  7. data/lib/glimmer-dsl-opal/missing/net/http.rb +17 -0
  8. data/lib/glimmer-dsl-opal/missing/uri.rb +26 -0
  9. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager.rb +2 -3
  10. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact.rb +0 -0
  11. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_manager_presenter.rb +0 -0
  12. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_repository.rb +24 -99
  13. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/login.rb +0 -1
  14. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe.rb +5 -5
  15. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/board.rb +0 -0
  16. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/cell.rb +0 -0
  17. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_browser.rb +0 -0
  18. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +63 -0
  19. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed.rb +19 -19
  20. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed/contact.rb +0 -0
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +155 -0
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +86 -0
  23. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_multi_selection.rb +0 -0
  24. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_single_selection.rb +0 -0
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +50 -0
  26. data/lib/glimmer-dsl-opal/samples/hello/hello_world.rb +29 -0
  27. data/lib/glimmer-dsl-opal/vendor/jquery.js +2 -0
  28. data/lib/glimmer/data_binding/element_binding.rb +1 -1
  29. data/lib/glimmer/data_binding/ext/observable_model.rb +40 -0
  30. data/lib/glimmer/data_binding/list_selection_binding.rb +1 -1
  31. data/lib/glimmer/data_binding/table_items_binding.rb +70 -0
  32. data/lib/glimmer/dsl/opal/async_exec_expression.rb +17 -0
  33. data/lib/glimmer/dsl/opal/color_expression.rb +38 -0
  34. data/lib/glimmer/dsl/opal/column_properties_expression.rb +22 -0
  35. data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +2 -2
  36. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +57 -0
  37. data/lib/glimmer/dsl/opal/dsl.rb +17 -14
  38. data/lib/glimmer/dsl/opal/font_expression.rb +47 -0
  39. data/lib/glimmer/dsl/opal/layout_data_expression.rb +2 -2
  40. data/lib/glimmer/dsl/opal/{text_expression.rb → layout_expression.rb} +5 -5
  41. data/lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb +2 -3
  42. data/lib/glimmer/dsl/opal/message_box_expression.rb +20 -0
  43. data/lib/glimmer/dsl/opal/observe_expression.rb +32 -0
  44. data/lib/glimmer/dsl/opal/property_expression.rb +5 -2
  45. data/lib/glimmer/dsl/opal/rgb_expression.rb +32 -0
  46. data/lib/glimmer/dsl/opal/rgba_expression.rb +32 -0
  47. data/lib/glimmer/dsl/opal/shell_expression.rb +2 -2
  48. data/lib/glimmer/dsl/opal/swt_expression.rb +46 -0
  49. data/lib/glimmer/dsl/opal/{composite_expression.rb → table_column_expression.rb} +3 -3
  50. data/lib/glimmer/dsl/opal/{list_expression.rb → table_expression.rb} +3 -3
  51. data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +29 -0
  52. data/lib/glimmer/dsl/opal/widget_expression.rb +24 -0
  53. data/lib/glimmer/dsl/opal/widget_listener_expression.rb +16 -3
  54. data/lib/glimmer/swt.rb +499 -0
  55. data/lib/glimmer/swt/browser_proxy.rb +27 -0
  56. data/lib/glimmer/swt/button_proxy.rb +40 -0
  57. data/lib/glimmer/swt/color_proxy.rb +119 -0
  58. data/lib/glimmer/{opal/select_proxy.rb → swt/combo_proxy.rb} +24 -19
  59. data/lib/glimmer/swt/composite_proxy.rb +31 -0
  60. data/lib/glimmer/swt/display_proxy.rb +25 -0
  61. data/lib/glimmer/{opal → swt}/event_listener_proxy.rb +1 -1
  62. data/lib/glimmer/swt/fill_layout_proxy.rb +84 -0
  63. data/lib/glimmer/swt/font_proxy.rb +79 -0
  64. data/lib/glimmer/swt/grid_layout_proxy.rb +71 -0
  65. data/lib/glimmer/swt/label_proxy.rb +34 -0
  66. data/lib/glimmer/swt/layout_data_proxy.rb +52 -0
  67. data/lib/glimmer/swt/layout_proxy.rb +62 -0
  68. data/lib/glimmer/{opal → swt}/list_proxy.rb +31 -23
  69. data/lib/glimmer/swt/message_box_proxy.rb +143 -0
  70. data/lib/glimmer/{opal → swt}/point.rb +1 -1
  71. data/lib/glimmer/{opal → swt}/property_owner.rb +1 -1
  72. data/lib/glimmer/swt/row_layout_proxy.rb +105 -0
  73. data/lib/glimmer/swt/shell_proxy.rb +245 -0
  74. data/lib/glimmer/swt/style_constantizable.rb +154 -0
  75. data/lib/glimmer/swt/swt_proxy.rb +53 -0
  76. data/lib/glimmer/{opal/tab_folder.rb → swt/tab_folder_proxy.rb} +21 -15
  77. data/lib/glimmer/swt/tab_item_proxy.rb +84 -0
  78. data/lib/glimmer/swt/table_column_proxy.rb +56 -0
  79. data/lib/glimmer/swt/table_item_proxy.rb +147 -0
  80. data/lib/glimmer/swt/table_proxy.rb +159 -0
  81. data/lib/glimmer/swt/text_proxy.rb +46 -0
  82. data/lib/glimmer/swt/widget_proxy.rb +490 -0
  83. data/lib/glimmer/ui/custom_shell.rb +73 -0
  84. data/lib/glimmer/ui/custom_widget.rb +290 -0
  85. data/lib/glimmer/util/proc_tracker.rb +39 -0
  86. metadata +134 -74
  87. data/lib/glimmer/config.rb +0 -22
  88. data/lib/glimmer/dsl/engine.rb +0 -193
  89. data/lib/glimmer/dsl/expression.rb +0 -42
  90. data/lib/glimmer/dsl/expression_handler.rb +0 -48
  91. data/lib/glimmer/dsl/opal/browser_expression.rb +0 -17
  92. data/lib/glimmer/dsl/opal/button_expression.rb +0 -18
  93. data/lib/glimmer/dsl/opal/combo_expression.rb +0 -17
  94. data/lib/glimmer/dsl/opal/grid_layout_expression.rb +0 -17
  95. data/lib/glimmer/dsl/opal/label_expression.rb +0 -17
  96. data/lib/glimmer/dsl/opal/tab_folder_expression.rb +0 -17
  97. data/lib/glimmer/dsl/opal/tab_item_expression.rb +0 -17
  98. data/lib/glimmer/dsl/parent_expression.rb +0 -12
  99. data/lib/glimmer/dsl/static_expression.rb +0 -36
  100. data/lib/glimmer/dsl/top_level_expression.rb +0 -7
  101. data/lib/glimmer/error.rb +0 -6
  102. data/lib/glimmer/invalid_keyword_error.rb +0 -6
  103. data/lib/glimmer/opal/div_proxy.rb +0 -22
  104. data/lib/glimmer/opal/document_proxy.rb +0 -128
  105. data/lib/glimmer/opal/element_proxy.rb +0 -281
  106. data/lib/glimmer/opal/grid_layout_proxy.rb +0 -53
  107. data/lib/glimmer/opal/iframe_proxy.rb +0 -23
  108. data/lib/glimmer/opal/input_proxy.rb +0 -41
  109. data/lib/glimmer/opal/label_proxy.rb +0 -25
  110. data/lib/glimmer/opal/layout_data_proxy.rb +0 -31
  111. data/lib/glimmer/opal/tab_item.rb +0 -98
  112. data/lib/samples/elaborate/launch +0 -6
  113. data/lib/samples/hello/hello_combo.rb +0 -34
  114. data/lib/samples/hello/hello_tab.rb +0 -24
  115. data/lib/samples/hello/hello_world.rb +0 -8
  116. data/lib/samples/hello/launch +0 -10
  117. data/lib/samples/launch +0 -4
@@ -1,36 +0,0 @@
1
- require 'glimmer/error'
2
- require 'glimmer/dsl/engine'
3
- require 'glimmer/dsl/expression'
4
-
5
- module Glimmer
6
- module DSL
7
- # Represents a StaticExpression for expressions where
8
- # the keyword does not vary dynamically. These static keywords are then
9
- # predefined as methods in Glimmer instead of needing method_missing
10
- #
11
- # StaticExpression subclasses may optionally implement `#can_interpret?`
12
- # (not needed if it only checks for keyword)
13
- #
14
- # StaticExpression subclasses must define `#interpret`.
15
- #
16
- # The direct parent namespace of a StaticExpression subclass must match the DSL name (case-insensitive)
17
- # (e.g. Glimmer::DSL::SWT::WidgetExpression has a DSL of :swt)
18
- class StaticExpression < Expression
19
- class << self
20
- def inherited(base)
21
- Glimmer::DSL::Engine.add_static_expression(base.new)
22
- super
23
- end
24
-
25
- def keyword
26
- @keyword ||= name.split(/::/).last.sub(/Expression$/, '').underscore
27
- end
28
- end
29
-
30
- # Subclasses may optionally implement
31
- def can_interpret?(parent, keyword, *args, &block)
32
- true
33
- end
34
- end
35
- end
36
- end
@@ -1,7 +0,0 @@
1
- module Glimmer
2
- module DSL
3
- # Mixin that represents expressions that are always at the top with parent nil
4
- module TopLevelExpression
5
- end
6
- end
7
- end
@@ -1,6 +0,0 @@
1
- module Glimmer
2
- # Represents Glimmer errors that occur due to invalid use of Glimmer
3
- # without handing control flow back to original method_missing
4
- class Error < RuntimeError
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module Glimmer
2
- # Represents Glimmer errors that occur due to invalid use of Glimmer
3
- # without handing control flow back to original method_missing
4
- class InvalidKeywordError < RuntimeError
5
- end
6
- end
@@ -1,22 +0,0 @@
1
- require 'glimmer/opal/element_proxy'
2
-
3
- module Glimmer
4
- module Opal
5
- class DivProxy < ElementProxy
6
- attr_reader :layout
7
-
8
- def initialize(parent, args)
9
- super(parent, args)
10
- @layout = GridLayoutProxy.new(self, [])
11
- end
12
-
13
- def dom
14
- div_id = id
15
- div_style = css
16
- @dom ||= DOM {
17
- div(id: div_id, class: 'grid-layout', style: div_style)
18
- }
19
- end
20
- end
21
- end
22
- end
@@ -1,128 +0,0 @@
1
- require 'glimmer/opal/element_proxy'
2
- require 'glimmer/opal/point'
3
-
4
- module Glimmer
5
- module Opal
6
- class DocumentProxy < ElementProxy
7
- # TODO consider renaming to ShellProxy to match SWT API
8
- attr_reader :minimum_size
9
-
10
- def initialize(args)
11
- @args = args
12
- @children = []
13
- $document.ready do
14
- $document.head.replace(head_dom)
15
- $document.body.replace(dom)
16
- end
17
- end
18
-
19
- def text
20
- $document.title
21
- end
22
-
23
- def text=(value)
24
- $document.ready do
25
- $document.title = value
26
- end
27
- end
28
-
29
- def minimum_size=(width_or_minimum_size, height = nil)
30
- @minimum_size = height.nil? ? width_or_minimum_size : Point.new(width_or_minimum_size, height)
31
- redraw
32
- end
33
-
34
- def head_dom
35
- # TODO make grid-layout support grab excess space false
36
- @head_dom ||= DOM {
37
- head {
38
- <<~CSS
39
- <style>
40
- html {
41
- width: 100%;
42
- height: 100%;
43
- }
44
- body {
45
- width: 100%;
46
- height: 100%;
47
- margin: 0;
48
- }
49
- body > iframe {
50
- width: 100%;
51
- height: 100%;
52
- }
53
- ul {
54
- list-style: none;
55
- padding: 0;
56
- }
57
- li {
58
- cursor: default;
59
- padding-left: 10px;
60
- padding-right: 10px;
61
- }
62
- li.selected-list-item {
63
- background: rgb(80, 116, 211);
64
- color: white;
65
- }
66
- li.empty-list-item {
67
- color: transparent;
68
- }
69
- .tabs {
70
- overflow: hidden;
71
- border: 1px solid #ccc;
72
- background-color: #f1f1f1;
73
- }
74
-
75
- /* Style the buttons inside the tab */
76
- .tabs .tab {
77
- background-color: inherit;
78
- float: left;
79
- border: none;
80
- outline: none;
81
- cursor: pointer;
82
- padding: 14px 16px;
83
- transition: 0.3s;
84
- font-size: 17px;
85
- }
86
-
87
- /* Change background color of buttons on hover */
88
- .tabs .tab:hover {
89
- background-color: #ddd;
90
- }
91
-
92
- /* Create an active/current tablink class */
93
- .tabs .tab.active {
94
- background-color: #ccc;
95
- }
96
-
97
- /* Style the tab content */
98
- .tab-item {
99
- padding: 6px 12px;
100
- border: 1px solid #ccc;
101
- border-top: none;
102
- }
103
-
104
- .hide {
105
- display: none !important;
106
- }
107
- </style>
108
- CSS
109
- }
110
- }
111
- end
112
-
113
- def dom
114
- i = 0
115
- body_style = ''
116
- body_style += "min-width: #{@minimum_size.x}px; min-height: #{@minimum_size.y}px;" if @minimum_size
117
- @dom ||= DOM {
118
- body(style: body_style) {
119
- }
120
- }
121
- end
122
-
123
- def open
124
- # No Op (just a placeholder since it is not needed on the web)
125
- end
126
- end
127
- end
128
- end
@@ -1,281 +0,0 @@
1
- require 'glimmer/opal/property_owner'
2
-
3
- module Glimmer
4
- module Opal
5
- class ElementProxy
6
- include Glimmer
7
- include PropertyOwner
8
- attr_reader :parent, :args, :css_classes, :css, :children
9
-
10
- def initialize(parent, args)
11
- @parent = parent
12
- @args = args
13
- @children = Set.new
14
- @css_classes = Set.new
15
- @css = ''
16
- @parent.add_child(self)
17
- end
18
-
19
- def add_child(child)
20
- # return if @children.include?(child)
21
- @children << child
22
- dom << child.dom
23
- end
24
-
25
- def redraw
26
- if @dom
27
- old_dom = @dom
28
- @dom = nil
29
- old_dom.replace dom
30
- else
31
- dom
32
- end
33
- @children.each do |child|
34
- child.redraw
35
- add_child(child)
36
- end
37
- end
38
-
39
- # Subclasses must override with their own mappings
40
- def observation_request_to_event_mapping
41
- {}
42
- end
43
-
44
- def name
45
- self.class.name.split('::').last.underscore.sub(/_proxy$/, '')
46
- end
47
-
48
- def id
49
- # TODO replace hash with autoincrement per name
50
- "#{name}-#{hash}"
51
- end
52
-
53
- # Subclasses can override with their own selector
54
- def selector
55
- "#{name}##{id}"
56
- end
57
-
58
- def add_css_class(css_class)
59
- @css_classes << css_class
60
- redraw
61
- end
62
-
63
- def add_css_classes(css_classes)
64
- @css_classes += css_classes
65
- redraw
66
- end
67
-
68
- def remove_css_class(css_class)
69
- @css_classes.delete(css_class)
70
- redraw
71
- end
72
-
73
- def remove_css_classes(css_classes)
74
- @css_classes -= css_classes
75
- redraw
76
- end
77
-
78
- def clear_css_classes(css_class)
79
- @css_classes.clear
80
- redraw
81
- end
82
-
83
- def css=(css)
84
- @css = css
85
- redraw
86
- end
87
-
88
- def has_style?(symbol)
89
- @args.include?(symbol) # not a very solid implementation. Bring SWT constants eventually
90
- end
91
-
92
- def handle_observation_request(keyword, &event_listener)
93
- return unless observation_request_to_event_mapping.keys.include?(keyword)
94
- event = nil
95
- delegate = nil
96
- [observation_request_to_event_mapping[keyword]].flatten.each do |mapping|
97
- event = mapping[:event]
98
- event_handler = mapping[:event_handler]
99
- potential_event_listener = event_handler&.call(event_listener)
100
- event_listener = event_handler&.call(event_listener) || event_listener
101
- delegate = $document.on(event, selector, &event_listener)
102
- end
103
- EventListenerProxy.new(element_proxy: self, event: event, selector: selector, delegate: delegate)
104
- end
105
-
106
- def add_observer(observer, property_name)
107
- property_listener_installers = self.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
108
- widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
109
- widget_listener_installers.to_a.each do |widget_listener_installer|
110
- widget_listener_installer.call(observer)
111
- end
112
- end
113
-
114
- def set_attribute(attribute_name, *args)
115
- apply_property_type_converters(attribute_name, args)
116
- super(attribute_name, *args)
117
- end
118
-
119
- def apply_property_type_converters(attribute_name, args)
120
- if args.count == 1
121
- value = args.first
122
- converter = property_type_converters[attribute_name.to_sym]
123
- args[0] = converter.call(value) if converter
124
- end
125
- # if args.count == 1 && args.first.is_a?(ColorProxy)
126
- # g_color = args.first
127
- # args[0] = g_color.swt_color
128
- # end
129
- end
130
-
131
- def property_type_converters
132
- @property_type_converters ||= {
133
- # :background => color_converter,
134
- # :background_image => lambda do |value|
135
- # if value.is_a?(String)
136
- # if value.start_with?('uri:classloader')
137
- # value = value.sub(/^uri\:classloader\:\//, '')
138
- # object = java.lang.Object.new
139
- # value = object.java_class.resource_as_stream(value)
140
- # value = java.io.BufferedInputStream.new(value)
141
- # end
142
- # image_data = ImageData.new(value)
143
- # on_event_Resize do |resize_event|
144
- # new_image_data = image_data.scaledTo(@swt_widget.getSize.x, @swt_widget.getSize.y)
145
- # @swt_widget.getBackgroundImage&.dispose
146
- # @swt_widget.setBackgroundImage(Image.new(@swt_widget.getDisplay, new_image_data))
147
- # end
148
- # Image.new(@swt_widget.getDisplay, image_data)
149
- # else
150
- # value
151
- # end
152
- # end,
153
- # :foreground => color_converter,
154
- # :font => lambda do |value|
155
- # if value.is_a?(Hash)
156
- # font_properties = value
157
- # FontProxy.new(self, font_properties).swt_font
158
- # else
159
- # value
160
- # end
161
- # end,
162
- # :items => lambda do |value|
163
- # value.to_java :string
164
- # end,
165
- :text => lambda do |value|
166
- # if swt_widget.is_a?(Browser)
167
- # value.to_s
168
- # else
169
- value.to_s
170
- # end
171
- end,
172
- # :visible => lambda do |value|
173
- # !!value
174
- # end,
175
- }
176
- end
177
-
178
- def widget_property_listener_installers
179
- @swt_widget_property_listener_installers ||= {
180
- # ElementProxy => {
181
- # :focus => lambda do |observer|
182
- # on_focus_gained { |focus_event|
183
- # observer.call(true)
184
- # }
185
- # on_focus_lost { |focus_event|
186
- # observer.call(false)
187
- # }
188
- # end,
189
- # },
190
- InputProxy => {
191
- :text => lambda do |observer|
192
- on_modify_text { |modify_event|
193
- observer.call(text)
194
- }
195
- end,
196
- # :caret_position => lambda do |observer|
197
- # on_event_keydown { |event|
198
- # observer.call(getCaretPosition)
199
- # }
200
- # on_event_keyup { |event|
201
- # observer.call(getCaretPosition)
202
- # }
203
- # on_event_mousedown { |event|
204
- # observer.call(getCaretPosition)
205
- # }
206
- # on_event_mouseup { |event|
207
- # observer.call(getCaretPosition)
208
- # }
209
- # end,
210
- # :selection => lambda do |observer|
211
- # on_event_keydown { |event|
212
- # observer.call(getSelection)
213
- # }
214
- # on_event_keyup { |event|
215
- # observer.call(getSelection)
216
- # }
217
- # on_event_mousedown { |event|
218
- # observer.call(getSelection)
219
- # }
220
- # on_event_mouseup { |event|
221
- # observer.call(getSelection)
222
- # }
223
- # end,
224
- # :selection_count => lambda do |observer|
225
- # on_event_keydown { |event|
226
- # observer.call(getSelectionCount)
227
- # }
228
- # on_event_keyup { |event|
229
- # observer.call(getSelectionCount)
230
- # }
231
- # on_event_mousedown { |event|
232
- # observer.call(getSelectionCount)
233
- # }
234
- # on_event_mouseup { |event|
235
- # observer.call(getSelectionCount)
236
- # }
237
- # end,
238
- # :top_index => lambda do |observer|
239
- # @last_top_index = getTopIndex
240
- # on_paint_control { |event|
241
- # if getTopIndex != @last_top_index
242
- # @last_top_index = getTopIndex
243
- # observer.call(@last_top_index)
244
- # end
245
- # }
246
- # end,
247
- },
248
- # Java::OrgEclipseSwtCustom::StyledText => {
249
- # :text => lambda do |observer|
250
- # on_modify_text { |modify_event|
251
- # observer.call(getText)
252
- # }
253
- # end,
254
- # },
255
- # InputProxy => {
256
- # :selection => lambda do |observer|
257
- # on_widget_selected { |selection_event|
258
- # observer.call(getSelection)
259
- # }
260
- # end
261
- # },
262
- # Java::OrgEclipseSwtWidgets::MenuItem => {
263
- # :selection => lambda do |observer|
264
- # on_widget_selected { |selection_event|
265
- # observer.call(getSelection)
266
- # }
267
- # end
268
- # },
269
- # Java::OrgEclipseSwtWidgets::Spinner => {
270
- # :selection => lambda do |observer|
271
- # on_widget_selected { |selection_event|
272
- # observer.call(getSelection)
273
- # }
274
- # end
275
- # },
276
- }
277
- end
278
-
279
- end
280
- end
281
- end