glimmer-dsl-opal 0.0.9 → 0.5.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 +50 -0
- data/README.md +999 -177
- data/VERSION +1 -1
- data/lib/glimmer-dsl-opal.rb +49 -10
- data/lib/glimmer-dsl-opal/ext/date.rb +13 -0
- data/lib/glimmer-dsl-opal/ext/exception.rb +5 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager.rb +1 -1
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_manager_presenter.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_repository.rb +24 -99
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/login.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/board.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/cell.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_browser.rb +0 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +85 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +68 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +63 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed.rb +19 -19
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed/contact.rb +0 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +155 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +86 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +104 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_multi_selection.rb +0 -0
- data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_single_selection.rb +0 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +108 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +84 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +50 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_world.rb +29 -0
- data/lib/glimmer-dsl-opal/vendor/jquery.js +2 -0
- data/lib/glimmer-dsl-swt.rb +37 -0
- data/lib/glimmer/data_binding/element_binding.rb +1 -0
- data/lib/glimmer/data_binding/ext/observable_model.rb +5 -5
- data/lib/glimmer/data_binding/list_selection_binding.rb +1 -1
- data/lib/glimmer/data_binding/table_items_binding.rb +3 -3
- data/lib/glimmer/dsl/opal/async_exec_expression.rb +23 -7
- data/lib/glimmer/dsl/opal/checkbox_group_selection_data_binding_expression.rb +61 -0
- data/lib/glimmer/dsl/opal/color_expression.rb +38 -0
- data/lib/glimmer/dsl/opal/column_properties_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/custom_widget_expression.rb +94 -0
- data/lib/glimmer/dsl/opal/display_expression.rb +40 -0
- data/lib/glimmer/dsl/opal/dsl.rb +18 -16
- data/lib/glimmer/dsl/opal/exec_expression.rb +55 -0
- data/lib/glimmer/dsl/opal/font_expression.rb +47 -0
- data/lib/glimmer/dsl/opal/layout_data_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/layout_expression.rb +22 -0
- data/lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb +2 -3
- data/lib/glimmer/dsl/opal/message_box_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/property_expression.rb +6 -2
- data/lib/glimmer/dsl/opal/radio_group_selection_data_binding_expression.rb +61 -0
- data/lib/glimmer/dsl/opal/rgb_expression.rb +32 -0
- data/lib/glimmer/dsl/opal/rgba_expression.rb +32 -0
- data/lib/glimmer/dsl/opal/shell_expression.rb +20 -3
- data/lib/glimmer/dsl/opal/swt_expression.rb +46 -0
- data/lib/glimmer/dsl/opal/sync_exec_expression.rb +33 -0
- data/lib/glimmer/dsl/opal/table_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/widget_expression.rb +24 -0
- data/lib/glimmer/dsl/opal/widget_listener_expression.rb +16 -3
- data/lib/glimmer/swt.rb +499 -0
- data/lib/glimmer/swt/browser_proxy.rb +27 -0
- data/lib/glimmer/swt/button_proxy.rb +54 -0
- data/lib/glimmer/swt/checkbox_proxy.rb +80 -0
- data/lib/glimmer/swt/color_proxy.rb +119 -0
- data/lib/glimmer/{opal/select_proxy.rb → swt/combo_proxy.rb} +23 -18
- data/lib/glimmer/swt/composite_proxy.rb +31 -0
- data/lib/glimmer/swt/custom/checkbox_group.rb +142 -0
- data/lib/glimmer/swt/custom/radio_group.rb +143 -0
- data/lib/glimmer/swt/display_proxy.rb +79 -0
- data/lib/glimmer/{opal → swt}/event_listener_proxy.rb +1 -1
- data/lib/glimmer/swt/fill_layout_proxy.rb +84 -0
- data/lib/glimmer/swt/font_proxy.rb +79 -0
- data/lib/glimmer/swt/grid_layout_proxy.rb +82 -0
- data/lib/glimmer/swt/group_proxy.rb +38 -0
- data/lib/glimmer/swt/label_proxy.rb +54 -0
- data/lib/glimmer/swt/layout_data_proxy.rb +105 -0
- data/lib/glimmer/swt/layout_proxy.rb +63 -0
- data/lib/glimmer/{opal → swt}/list_proxy.rb +30 -22
- data/lib/glimmer/swt/make_shift_shell_proxy.rb +38 -0
- data/lib/glimmer/swt/message_box_proxy.rb +143 -0
- data/lib/glimmer/{opal → swt}/point.rb +1 -1
- data/lib/glimmer/{opal → swt}/property_owner.rb +1 -1
- data/lib/glimmer/swt/radio_proxy.rb +81 -0
- data/lib/glimmer/swt/row_layout_proxy.rb +128 -0
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -0
- data/lib/glimmer/swt/shell_proxy.rb +260 -0
- data/lib/glimmer/swt/style_constantizable.rb +154 -0
- data/lib/glimmer/swt/styled_text_proxy.rb +44 -0
- data/lib/glimmer/swt/swt_proxy.rb +53 -0
- data/lib/glimmer/{opal/tab_folder.rb → swt/tab_folder_proxy.rb} +20 -21
- data/lib/glimmer/swt/tab_item_proxy.rb +84 -0
- data/lib/glimmer/{opal/table_column.rb → swt/table_column_proxy.rb} +13 -7
- data/lib/glimmer/{opal/table_item.rb → swt/table_item_proxy.rb} +59 -48
- data/lib/glimmer/{opal → swt}/table_proxy.rb +66 -56
- data/lib/glimmer/swt/text_proxy.rb +46 -0
- data/lib/glimmer/swt/widget_proxy.rb +511 -0
- data/lib/glimmer/ui/custom_shell.rb +92 -0
- data/lib/glimmer/ui/custom_widget.rb +292 -0
- data/lib/glimmer/util/proc_tracker.rb +39 -0
- data/lib/net/http.rb +17 -0
- data/lib/uri.rb +64 -0
- metadata +142 -67
- 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/composite_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/opal/list_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/tab_folder_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/tab_item_expression.rb +0 -17
- data/lib/glimmer/dsl/opal/text_expression.rb +0 -22
- data/lib/glimmer/opal/display_proxy.rb +0 -23
- data/lib/glimmer/opal/div_proxy.rb +0 -29
- data/lib/glimmer/opal/document_proxy.rb +0 -187
- data/lib/glimmer/opal/element_proxy.rb +0 -304
- data/lib/glimmer/opal/grid_layout_proxy.rb +0 -54
- data/lib/glimmer/opal/iframe_proxy.rb +0 -23
- data/lib/glimmer/opal/input_proxy.rb +0 -45
- data/lib/glimmer/opal/label_proxy.rb +0 -25
- data/lib/glimmer/opal/layout_data_proxy.rb +0 -52
- data/lib/glimmer/opal/modal.rb +0 -94
- data/lib/glimmer/opal/tab_item.rb +0 -98
- data/lib/samples/elaborate/launch +0 -6
- data/lib/samples/hello/hello_combo.rb +0 -34
- data/lib/samples/hello/hello_tab.rb +0 -24
- data/lib/samples/hello/hello_world.rb +0 -8
- data/lib/samples/hello/launch +0 -10
- data/lib/samples/launch +0 -4
@@ -0,0 +1,92 @@
|
|
1
|
+
# Copyright (c) 2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/ui/custom_widget'
|
23
|
+
require 'glimmer/swt/display_proxy'
|
24
|
+
require 'glimmer/error'
|
25
|
+
|
26
|
+
module Glimmer
|
27
|
+
module UI
|
28
|
+
module CustomShell
|
29
|
+
include Glimmer::UI::CustomWidget
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def included(klass)
|
33
|
+
klass.extend(CustomWidget::ClassMethods)
|
34
|
+
klass.include(Glimmer)
|
35
|
+
Glimmer::UI::CustomWidget.add_custom_widget_namespaces_for(klass)
|
36
|
+
end
|
37
|
+
|
38
|
+
def request_parameter_string
|
39
|
+
URI.decode_www_form_component(`document.location.href`.match(/\?(.*)$/).to_a[1].to_s)
|
40
|
+
end
|
41
|
+
|
42
|
+
def encoded_request_parameter_string
|
43
|
+
`document.location.href`.match(/\?(.*)$/).to_a[1].to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def requested_and_not_handled?
|
47
|
+
requested? && !request_parameter_string.include?('custom_shell_handled=true')
|
48
|
+
end
|
49
|
+
|
50
|
+
def requested?
|
51
|
+
request_parameter_string.include?('custom_shell=')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(parent, args, options, &content)
|
56
|
+
super(parent, args, options, &content)
|
57
|
+
raise Error, 'Invalid custom shell body root! Must be a shell or another custom shell.' unless body_root.is_a?(Glimmer::SWT::ShellProxy) || body_root.is_a?(Glimmer::UI::CustomShell)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Classes may override
|
61
|
+
def open
|
62
|
+
# TODO consider the idea of delaying rendering till the open method
|
63
|
+
body_root.open
|
64
|
+
end
|
65
|
+
|
66
|
+
# DO NOT OVERRIDE. JUST AN ALIAS FOR `#open`. OVERRIDE `#open` INSTEAD.
|
67
|
+
def show
|
68
|
+
open
|
69
|
+
end
|
70
|
+
|
71
|
+
def close
|
72
|
+
body_root.close
|
73
|
+
end
|
74
|
+
|
75
|
+
def hide
|
76
|
+
body_root.hide
|
77
|
+
end
|
78
|
+
|
79
|
+
def visible?
|
80
|
+
body_root.visible?
|
81
|
+
end
|
82
|
+
|
83
|
+
def center
|
84
|
+
body_root.center
|
85
|
+
end
|
86
|
+
|
87
|
+
def start_event_loop
|
88
|
+
body_root.start_event_loop
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,292 @@
|
|
1
|
+
# Copyright (c) 2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer'
|
23
|
+
require 'glimmer/error'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/util/proc_tracker'
|
26
|
+
require 'glimmer/data_binding/observer'
|
27
|
+
require 'glimmer/data_binding/observable_model'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module UI
|
31
|
+
module CustomWidget
|
32
|
+
include DataBinding::ObservableModel
|
33
|
+
|
34
|
+
module ClassMethods
|
35
|
+
# Allows defining convenience option accessors for an array of option names
|
36
|
+
# Example: `options :color1, :color2` defines `#color1` and `#color2`
|
37
|
+
# where they return the instance values `options[:color1]` and `options[:color2]`
|
38
|
+
# respectively.
|
39
|
+
# Can be called multiple times to set more options additively.
|
40
|
+
# When passed no arguments, it returns list of all option names captured so far
|
41
|
+
def options(*new_options)
|
42
|
+
new_options = new_options.compact.map(&:to_s).map(&:to_sym)
|
43
|
+
if new_options.empty?
|
44
|
+
@options ||= {} # maps options to defaults
|
45
|
+
else
|
46
|
+
new_options = new_options.reduce({}) {|new_options_hash, new_option| new_options_hash.merge(new_option => nil)}
|
47
|
+
@options = options.merge(new_options)
|
48
|
+
def_option_attr_accessors(new_options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def option(new_option, default: nil)
|
53
|
+
new_option = new_option.to_s.to_sym
|
54
|
+
new_options = {new_option => default}
|
55
|
+
'@options = options.merge(new_options)'
|
56
|
+
@options = options.merge(new_options)
|
57
|
+
'def_option_attr_accessors(new_options)'
|
58
|
+
def_option_attr_accessors(new_options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def def_option_attr_accessors(new_options)
|
62
|
+
new_options.each do |option, default|
|
63
|
+
# TODO fix this in Opal by switching to define_method
|
64
|
+
define_method(option) do
|
65
|
+
options[:"#{option}"]
|
66
|
+
end
|
67
|
+
define_method("#{option}=") do |option_value|
|
68
|
+
self.options[:"#{option}"] = option_value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def before_body(&block)
|
74
|
+
@before_body_blocks ||= []
|
75
|
+
@before_body_blocks << block
|
76
|
+
end
|
77
|
+
|
78
|
+
def body(&block)
|
79
|
+
@body_block = block
|
80
|
+
end
|
81
|
+
|
82
|
+
def after_body(&block)
|
83
|
+
@after_body_blocks ||= []
|
84
|
+
@after_body_blocks << block
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class << self
|
89
|
+
def included(klass)
|
90
|
+
klass.extend(ClassMethods)
|
91
|
+
unless klass.name.include?('Glimmer::UI::CustomShell')
|
92
|
+
klass.include(Glimmer)
|
93
|
+
Glimmer::UI::CustomWidget.add_custom_widget_namespaces_for(klass)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def for(underscored_custom_widget_name)
|
98
|
+
extracted_namespaces = underscored_custom_widget_name.
|
99
|
+
to_s.
|
100
|
+
split(/__/).map do |namespace|
|
101
|
+
namespace.camelcase(:upper)
|
102
|
+
end
|
103
|
+
custom_widget_namespaces.each do |base|
|
104
|
+
extracted_namespaces.reduce(base) do |result, namespace|
|
105
|
+
if !result.constants.include?(namespace)
|
106
|
+
namespace = result.constants.detect {|c| c.to_s.upcase == namespace.to_s.upcase } || namespace
|
107
|
+
end
|
108
|
+
begin
|
109
|
+
constant = result.const_get(namespace)
|
110
|
+
return constant if constant.ancestors.include?(Glimmer::UI::CustomWidget)
|
111
|
+
constant
|
112
|
+
rescue => e
|
113
|
+
# Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
|
114
|
+
result
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
raise "#{underscored_custom_widget_name} has no custom widget class!"
|
119
|
+
rescue => e
|
120
|
+
Glimmer::Config.logger.debug {e.message}
|
121
|
+
Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
|
122
|
+
nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def add_custom_widget_namespaces_for(klass)
|
126
|
+
Glimmer::UI::CustomWidget.namespaces_for_class(klass).drop(1).each do |namespace|
|
127
|
+
Glimmer::UI::CustomWidget.custom_widget_namespaces << namespace
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def namespaces_for_class(m)
|
132
|
+
return [m] if m.name.nil?
|
133
|
+
namespace_constants = m.name.split(/::/).map(&:to_sym)
|
134
|
+
namespace_constants.reduce([Object]) do |output, namespace_constant|
|
135
|
+
output += [output.last.const_get(namespace_constant)]
|
136
|
+
end[1..-1].uniq.reverse
|
137
|
+
end
|
138
|
+
|
139
|
+
def custom_widget_namespaces
|
140
|
+
@custom_widget_namespaces ||= reset_custom_widget_namespaces
|
141
|
+
end
|
142
|
+
|
143
|
+
def reset_custom_widget_namespaces
|
144
|
+
@custom_widget_namespaces = Set[Object, Glimmer::UI]
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
# <- end of class methods
|
149
|
+
|
150
|
+
|
151
|
+
attr_reader :body_root, :parent, :options, :swt_style
|
152
|
+
|
153
|
+
def initialize(parent, args, options, &content)
|
154
|
+
@parent = parent
|
155
|
+
options = args.delete_at(-1) if args.is_a?(Array) && args.last.is_a?(Hash)
|
156
|
+
if args.is_a?(Hash)
|
157
|
+
options = args
|
158
|
+
args = []
|
159
|
+
end
|
160
|
+
options ||= {}
|
161
|
+
args = options.delete('swt_style').split(',').map(&:to_sym) if options['swt_style']
|
162
|
+
@args = args
|
163
|
+
@swt_style = SWT::SWTProxy[*@args]
|
164
|
+
options ||= {}
|
165
|
+
@options = self.class.options.merge(options)
|
166
|
+
@content = Util::ProcTracker.new(content) if content
|
167
|
+
execute_hooks('before_body')
|
168
|
+
body_block = self.class.instance_variable_get("@body_block")
|
169
|
+
raise Glimmer::Error, 'Invalid custom widget for having no body! Please define body block!' if body_block.nil?
|
170
|
+
@body_root = instance_exec(&body_block)
|
171
|
+
raise Glimmer::Error, 'Invalid custom widget for having an empty body! Please fill body block!' if @body_root.nil?
|
172
|
+
execute_hooks('after_body')
|
173
|
+
end
|
174
|
+
|
175
|
+
# Subclasses may override to perform post initialization work on an added child
|
176
|
+
def post_initialize_child(child)
|
177
|
+
# No Op by default
|
178
|
+
end
|
179
|
+
|
180
|
+
def can_handle_observation_request?(observation_request)
|
181
|
+
observation_request = observation_request.to_s
|
182
|
+
result = false
|
183
|
+
if observation_request.start_with?('on_updated_')
|
184
|
+
property = observation_request.sub(/^on_updated_/, '')
|
185
|
+
result = can_add_observer?(property)
|
186
|
+
end
|
187
|
+
result || body_root&.can_handle_observation_request?(observation_request)
|
188
|
+
end
|
189
|
+
|
190
|
+
def handle_observation_request(observation_request, &block)
|
191
|
+
observation_request = observation_request.to_s
|
192
|
+
if observation_request.start_with?('on_updated_')
|
193
|
+
property = observation_request.sub(/^on_updated_/, '') # TODO look into eliminating duplication from above
|
194
|
+
add_observer(DataBinding::Observer.proc(&block), property) if can_add_observer?(property)
|
195
|
+
else
|
196
|
+
body_root.handle_observation_request(observation_request, &block)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def can_add_observer?(attribute_name)
|
201
|
+
has_instance_method?(attribute_name) || has_instance_method?("#{attribute_name}?") || @body_root.can_add_observer?(attribute_name)
|
202
|
+
end
|
203
|
+
|
204
|
+
def add_observer(observer, attribute_name)
|
205
|
+
if has_instance_method?(attribute_name)
|
206
|
+
super
|
207
|
+
else
|
208
|
+
@body_root.add_observer(observer, attribute_name)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def has_attribute?(attribute_name, *args)
|
213
|
+
has_instance_method?(attribute_setter(attribute_name)) ||
|
214
|
+
@body_root.has_attribute?(attribute_name, *args)
|
215
|
+
end
|
216
|
+
|
217
|
+
def set_attribute(attribute_name, *args)
|
218
|
+
if has_instance_method?(attribute_setter(attribute_name))
|
219
|
+
send(attribute_setter(attribute_name), *args)
|
220
|
+
else
|
221
|
+
@body_root.set_attribute(attribute_name, *args)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
# This method ensures it has an instance method not coming from Glimmer DSL
|
226
|
+
def has_instance_method?(method_name)
|
227
|
+
respond_to?(method_name) and
|
228
|
+
!body_root&.respond_to?(method_name) and
|
229
|
+
!method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') and
|
230
|
+
!method(method_name)&.source_location&.first&.include?('glimmer/swt/widget_proxy.rb')
|
231
|
+
end
|
232
|
+
|
233
|
+
def get_attribute(attribute_name)
|
234
|
+
if has_instance_method?(attribute_name)
|
235
|
+
send(attribute_name)
|
236
|
+
else
|
237
|
+
@body_root.get_attribute(attribute_name)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def attribute_setter(attribute_name)
|
242
|
+
"#{attribute_name}="
|
243
|
+
end
|
244
|
+
|
245
|
+
def has_style?(symbol)
|
246
|
+
@args.include?(symbol) # not a very solid implementation. Bring SWT constants eventually
|
247
|
+
end
|
248
|
+
|
249
|
+
def async_exec(&block)
|
250
|
+
SWT::DisplayProxy.instance.async_exec(&block)
|
251
|
+
end
|
252
|
+
|
253
|
+
# sync_exec kept for API compatibility reasons
|
254
|
+
def sync_exec(&block)
|
255
|
+
SWT::DisplayProxy.instance.async_exec(&block)
|
256
|
+
end
|
257
|
+
|
258
|
+
# Returns content block if used as an attribute reader (no args)
|
259
|
+
# Otherwise, if a block is passed, it adds it as content to this custom widget
|
260
|
+
def content(&block)
|
261
|
+
if block_given?
|
262
|
+
body_root.content(&block)
|
263
|
+
else
|
264
|
+
@content
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def method_missing(method, *args, &block)
|
269
|
+
if can_handle_observation_request?(method)
|
270
|
+
handle_observation_request(method, &block)
|
271
|
+
else
|
272
|
+
body_root.send(method, *args, &block)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
alias local_respond_to? respond_to?
|
277
|
+
def respond_to?(method, *args, &block)
|
278
|
+
super or
|
279
|
+
can_handle_observation_request?(method) or
|
280
|
+
body_root.respond_to?(method, *args, &block)
|
281
|
+
end
|
282
|
+
|
283
|
+
private
|
284
|
+
|
285
|
+
def execute_hooks(hook_name)
|
286
|
+
self.class.instance_variable_get("@#{hook_name}_blocks")&.each do |hook_block|
|
287
|
+
instance_exec(&hook_block)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'delegate'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module Util
|
26
|
+
class ProcTracker < DelegateClass(Proc)
|
27
|
+
def initialize(proc)
|
28
|
+
super(proc)
|
29
|
+
end
|
30
|
+
def call(*args)
|
31
|
+
__getobj__.call(*args)
|
32
|
+
@called = true
|
33
|
+
end
|
34
|
+
def called?
|
35
|
+
!!@called
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/net/http.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Missing Net module class methods TODO implement
|
2
|
+
|
3
|
+
require_relative '../uri'
|
4
|
+
|
5
|
+
module Net
|
6
|
+
# TODO Implement HTTP with jQuery for use in Glimmer DSL for Opal
|
7
|
+
# Note: ignore Protocol superclass for now
|
8
|
+
class HTTP
|
9
|
+
def post_form(uri, params)
|
10
|
+
# pd uri.scheme
|
11
|
+
# pd uri.host
|
12
|
+
# pd uri.path
|
13
|
+
# pd uri.query
|
14
|
+
# pd params
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/uri.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Missing URI module class features
|
2
|
+
|
3
|
+
module URI
|
4
|
+
class HTTP
|
5
|
+
REGEX = /([^:]+):\/\/([^\/])\/([^?]*)\??(.*)/
|
6
|
+
|
7
|
+
def initialize(url)
|
8
|
+
@url = url
|
9
|
+
uri_match = url.match(REGEX)
|
10
|
+
@scheme = uri_match[1]
|
11
|
+
@host = uri_match[2]
|
12
|
+
@path = uri_match[3]
|
13
|
+
@query = uri_match[4]
|
14
|
+
# TODO fragment
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
TBLENCWWWCOMP_ = {"\u0000"=>"%00", "\u0001"=>"%01", "\u0002"=>"%02", "\u0003"=>"%03", "\u0004"=>"%04", "\u0005"=>"%05", "\u0006"=>"%06", "\a"=>"%07", "\b"=>"%08", "\t"=>"%09", "\n"=>"%0A", "\v"=>"%0B", "\f"=>"%0C", "\r"=>"%0D", "\u000E"=>"%0E", "\u000F"=>"%0F", "\u0010"=>"%10", "\u0011"=>"%11", "\u0012"=>"%12", "\u0013"=>"%13", "\u0014"=>"%14", "\u0015"=>"%15", "\u0016"=>"%16", "\u0017"=>"%17", "\u0018"=>"%18", "\u0019"=>"%19", "\u001A"=>"%1A", "\e"=>"%1B", "\u001C"=>"%1C", "\u001D"=>"%1D", "\u001E"=>"%1E", "\u001F"=>"%1F", " "=>"+", "!"=>"%21", "\""=>"%22", "#"=>"%23", "$"=>"%24", "%"=>"%25", "&"=>"%26", "'"=>"%27", "("=>"%28", ")"=>"%29", "*"=>"%2A", "+"=>"%2B", ","=>"%2C", "-"=>"%2D", "."=>"%2E", "/"=>"%2F", "0"=>"%30", "1"=>"%31", "2"=>"%32", "3"=>"%33", "4"=>"%34", "5"=>"%35", "6"=>"%36", "7"=>"%37", "8"=>"%38", "9"=>"%39", ":"=>"%3A", ";"=>"%3B", "<"=>"%3C", "="=>"%3D", ">"=>"%3E", "?"=>"%3F", "@"=>"%40", "A"=>"%41", "B"=>"%42", "C"=>"%43", "D"=>"%44", "E"=>"%45", "F"=>"%46", "G"=>"%47", "H"=>"%48", "I"=>"%49", "J"=>"%4A", "K"=>"%4B", "L"=>"%4C", "M"=>"%4D", "N"=>"%4E", "O"=>"%4F", "P"=>"%50", "Q"=>"%51", "R"=>"%52", "S"=>"%53", "T"=>"%54", "U"=>"%55", "V"=>"%56", "W"=>"%57", "X"=>"%58", "Y"=>"%59", "Z"=>"%5A", "["=>"%5B", "\\"=>"%5C", "]"=>"%5D", "^"=>"%5E", "_"=>"%5F", "`"=>"%60", "a"=>"%61", "b"=>"%62", "c"=>"%63", "d"=>"%64", "e"=>"%65", "f"=>"%66", "g"=>"%67", "h"=>"%68", "i"=>"%69", "j"=>"%6A", "k"=>"%6B", "l"=>"%6C", "m"=>"%6D", "n"=>"%6E", "o"=>"%6F", "p"=>"%70", "q"=>"%71", "r"=>"%72", "s"=>"%73", "t"=>"%74", "u"=>"%75", "v"=>"%76", "w"=>"%77", "x"=>"%78", "y"=>"%79", "z"=>"%7A", "{"=>"%7B", "|"=>"%7C", "}"=>"%7D", "~"=>"%7E", "\u007F"=>"%7F", "\u0080"=>"%80", "\u0081"=>"%81", "\u0082"=>"%82", "\u0083"=>"%83", "\u0084"=>"%84", "\u0085"=>"%85", "\u0086"=>"%86", "\u0087"=>"%87", "\u0088"=>"%88", "\u0089"=>"%89", "\u008A"=>"%8A", "\u008B"=>"%8B", "\u008C"=>"%8C", "\u008D"=>"%8D", "\u008E"=>"%8E", "\u008F"=>"%8F", "\u0090"=>"%90", "\u0091"=>"%91", "\u0092"=>"%92", "\u0093"=>"%93", "\u0094"=>"%94", "\u0095"=>"%95", "\u0096"=>"%96", "\u0097"=>"%97", "\u0098"=>"%98", "\u0099"=>"%99", "\u009A"=>"%9A", "\u009B"=>"%9B", "\u009C"=>"%9C", "\u009D"=>"%9D", "\u009E"=>"%9E", "\u009F"=>"%9F", "\u00A0"=>"%A0", "\u00A1"=>"%A1", "\u00A2"=>"%A2", "\u00A3"=>"%A3", "\u00A4"=>"%A4", "\u00A5"=>"%A5", "\u00A6"=>"%A6", "\u00A7"=>"%A7", "\u00A8"=>"%A8", "\u00A9"=>"%A9", "\u00AA"=>"%AA", "\u00AB"=>"%AB", "\u00AC"=>"%AC", "\u00AD"=>"%AD", "\u00AE"=>"%AE", "\u00AF"=>"%AF", "\u00B0"=>"%B0", "\u00B1"=>"%B1", "\u00B2"=>"%B2", "\u00B3"=>"%B3", "\u00B4"=>"%B4", "\u00B5"=>"%B5", "\u00B6"=>"%B6", "\u00B7"=>"%B7", "\u00B8"=>"%B8", "\u00B9"=>"%B9", "\u00BA"=>"%BA", "\u00BB"=>"%BB", "\u00BC"=>"%BC", "\u00BD"=>"%BD", "\u00BE"=>"%BE", "\u00BF"=>"%BF", "\u00C0"=>"%C0", "\u00C1"=>"%C1", "\u00C2"=>"%C2", "\u00C3"=>"%C3", "\u00C4"=>"%C4", "\u00C5"=>"%C5", "\u00C6"=>"%C6", "\u00C7"=>"%C7", "\u00C8"=>"%C8", "\u00C9"=>"%C9", "\u00CA"=>"%CA", "\u00CB"=>"%CB", "\u00CC"=>"%CC", "\u00CD"=>"%CD", "\u00CE"=>"%CE", "\u00CF"=>"%CF", "\u00D0"=>"%D0", "\u00D1"=>"%D1", "\u00D2"=>"%D2", "\u00D3"=>"%D3", "\u00D4"=>"%D4", "\u00D5"=>"%D5", "\u00D6"=>"%D6", "\u00D7"=>"%D7", "\u00D8"=>"%D8", "\u00D9"=>"%D9", "\u00DA"=>"%DA", "\u00DB"=>"%DB", "\u00DC"=>"%DC", "\u00DD"=>"%DD", "\u00DE"=>"%DE", "\u00DF"=>"%DF", "\u00E0"=>"%E0", "\u00E1"=>"%E1", "\u00E2"=>"%E2", "\u00E3"=>"%E3", "\u00E4"=>"%E4", "\u00E5"=>"%E5", "\u00E6"=>"%E6", "\u00E7"=>"%E7", "\u00E8"=>"%E8", "\u00E9"=>"%E9", "\u00EA"=>"%EA", "\u00EB"=>"%EB", "\u00EC"=>"%EC", "\u00ED"=>"%ED", "\u00EE"=>"%EE", "\u00EF"=>"%EF", "\u00F0"=>"%F0", "\u00F1"=>"%F1", "\u00F2"=>"%F2", "\u00F3"=>"%F3", "\u00F4"=>"%F4", "\u00F5"=>"%F5", "\u00F6"=>"%F6", "\u00F7"=>"%F7", "\u00F8"=>"%F8", "\u00F9"=>"%F9", "\u00FA"=>"%FA", "\u00FB"=>"%FB", "\u00FC"=>"%FC", "\u00FD"=>"%FD", "\u00FE"=>"%FE", "\u00FF"=>"%FF"}
|
23
|
+
TBLDECWWWCOMP_ = TBLENCWWWCOMP_.invert
|
24
|
+
|
25
|
+
# Encodes given +str+ to URL-encoded form data.
|
26
|
+
#
|
27
|
+
# This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
|
28
|
+
# (ASCII space) to + and converts others to %XX.
|
29
|
+
#
|
30
|
+
# If +enc+ is given, convert +str+ to the encoding before percent encoding.
|
31
|
+
#
|
32
|
+
# This is an implementation of
|
33
|
+
# https://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data.
|
34
|
+
#
|
35
|
+
# See URI.decode_www_form_component, URI.encode_www_form.
|
36
|
+
def self.encode_www_form_component(str, enc=nil)
|
37
|
+
str = str.to_s.dup
|
38
|
+
if str.encoding != Encoding::ASCII_8BIT
|
39
|
+
if enc && enc != Encoding::ASCII_8BIT
|
40
|
+
str.encode!(Encoding::UTF_8, invalid: :replace, undef: :replace)
|
41
|
+
str.encode!(enc, fallback: ->(x){"&##{x.ord};"})
|
42
|
+
end
|
43
|
+
str.force_encoding(Encoding::ASCII_8BIT)
|
44
|
+
end
|
45
|
+
str = str.gsub(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_)
|
46
|
+
str.force_encoding(Encoding::US_ASCII)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Decodes given +str+ of URL-encoded form data.
|
50
|
+
#
|
51
|
+
# This decodes + to SP.
|
52
|
+
#
|
53
|
+
# See URI.encode_www_form_component, URI.decode_www_form.
|
54
|
+
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
|
55
|
+
raise ArgumentError, "invalid %-encoding (#{str})" if /%(?![0-9a-fA-F][0-9a-fA-F])/ =~ str
|
56
|
+
str.b.gsub(/\+|%[0-9a-fA-F][0-9a-fA-F]/, TBLDECWWWCOMP_).force_encoding(enc)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module Kernel
|
61
|
+
def URI(url)
|
62
|
+
URI::HTTP.new(url)
|
63
|
+
end
|
64
|
+
end
|