glimmer-dsl-opal 0.1.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -0
  3. data/README.md +948 -169
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal.rb +31 -7
  6. data/lib/glimmer-dsl-opal/ext/date.rb +13 -0
  7. data/lib/glimmer-dsl-opal/ext/exception.rb +5 -0
  8. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager.rb +0 -0
  9. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact.rb +0 -0
  10. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_manager_presenter.rb +0 -0
  11. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_repository.rb +24 -99
  12. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/login.rb +0 -0
  13. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe.rb +0 -0
  14. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/board.rb +0 -0
  15. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/cell.rb +0 -0
  16. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_browser.rb +0 -0
  17. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +85 -0
  18. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +68 -0
  19. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +63 -0
  20. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed.rb +0 -0
  21. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_computed/contact.rb +0 -0
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +155 -0
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +86 -0
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +104 -0
  25. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_multi_selection.rb +0 -0
  26. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_single_selection.rb +1 -1
  27. data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +108 -0
  28. data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +84 -0
  29. data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +50 -0
  30. data/lib/glimmer-dsl-opal/samples/hello/hello_world.rb +29 -0
  31. data/lib/{jquery.js → glimmer-dsl-opal/vendor/jquery.js} +0 -0
  32. data/lib/glimmer-dsl-swt.rb +37 -0
  33. data/lib/glimmer/data_binding/element_binding.rb +2 -1
  34. data/lib/glimmer/data_binding/ext/observable_model.rb +1 -1
  35. data/lib/glimmer/dsl/opal/async_exec_expression.rb +23 -7
  36. data/lib/glimmer/dsl/opal/checkbox_group_selection_data_binding_expression.rb +61 -0
  37. data/lib/glimmer/dsl/opal/color_expression.rb +38 -0
  38. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +94 -0
  39. data/lib/glimmer/dsl/opal/display_expression.rb +40 -0
  40. data/lib/glimmer/dsl/opal/dsl.rb +14 -0
  41. data/lib/glimmer/dsl/opal/exec_expression.rb +55 -0
  42. data/lib/glimmer/dsl/opal/font_expression.rb +47 -0
  43. data/lib/glimmer/dsl/opal/layout_expression.rb +1 -1
  44. data/lib/glimmer/dsl/opal/property_expression.rb +6 -2
  45. data/lib/glimmer/dsl/opal/radio_group_selection_data_binding_expression.rb +61 -0
  46. data/lib/glimmer/dsl/opal/rgb_expression.rb +32 -0
  47. data/lib/glimmer/dsl/opal/rgba_expression.rb +32 -0
  48. data/lib/glimmer/dsl/opal/shell_expression.rb +19 -2
  49. data/lib/glimmer/dsl/opal/swt_expression.rb +46 -0
  50. data/lib/glimmer/dsl/opal/sync_exec_expression.rb +33 -0
  51. data/lib/glimmer/dsl/opal/widget_expression.rb +2 -1
  52. data/lib/glimmer/dsl/opal/widget_listener_expression.rb +16 -3
  53. data/lib/glimmer/swt.rb +499 -0
  54. data/lib/glimmer/swt/browser_proxy.rb +1 -1
  55. data/lib/glimmer/swt/button_proxy.rb +17 -3
  56. data/lib/glimmer/swt/checkbox_proxy.rb +80 -0
  57. data/lib/glimmer/swt/color_proxy.rb +119 -0
  58. data/lib/glimmer/swt/combo_proxy.rb +13 -12
  59. data/lib/glimmer/swt/composite_proxy.rb +8 -8
  60. data/lib/glimmer/swt/custom/checkbox_group.rb +142 -0
  61. data/lib/glimmer/swt/custom/radio_group.rb +143 -0
  62. data/lib/glimmer/swt/display_proxy.rb +79 -0
  63. data/lib/glimmer/swt/fill_layout_proxy.rb +84 -0
  64. data/lib/glimmer/swt/font_proxy.rb +79 -0
  65. data/lib/glimmer/swt/grid_layout_proxy.rb +45 -4
  66. data/lib/glimmer/swt/group_proxy.rb +38 -0
  67. data/lib/glimmer/swt/label_proxy.rb +28 -4
  68. data/lib/glimmer/swt/layout_data_proxy.rb +59 -6
  69. data/lib/glimmer/swt/layout_proxy.rb +17 -14
  70. data/lib/glimmer/swt/list_proxy.rb +19 -14
  71. data/lib/glimmer/swt/make_shift_shell_proxy.rb +38 -0
  72. data/lib/glimmer/swt/message_box_proxy.rb +5 -8
  73. data/lib/glimmer/swt/radio_proxy.rb +81 -0
  74. data/lib/glimmer/swt/row_layout_proxy.rb +128 -0
  75. data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -0
  76. data/lib/glimmer/swt/shell_proxy.rb +51 -26
  77. data/lib/glimmer/swt/style_constantizable.rb +154 -0
  78. data/lib/glimmer/swt/styled_text_proxy.rb +44 -0
  79. data/lib/glimmer/swt/swt_proxy.rb +53 -0
  80. data/lib/glimmer/swt/tab_folder_proxy.rb +8 -8
  81. data/lib/glimmer/swt/tab_item_proxy.rb +15 -32
  82. data/lib/glimmer/swt/table_proxy.rb +0 -18
  83. data/lib/glimmer/swt/widget_proxy.rb +173 -54
  84. data/lib/glimmer/ui/custom_shell.rb +92 -0
  85. data/lib/glimmer/ui/custom_widget.rb +292 -0
  86. data/lib/glimmer/util/proc_tracker.rb +39 -0
  87. data/lib/net/http.rb +17 -0
  88. data/lib/uri.rb +64 -0
  89. metadata +108 -57
  90. data/lib/glimmer/opal/display_proxy.rb +0 -23
  91. data/lib/glimmer/opal/element_proxy.rb +0 -312
  92. data/lib/samples/elaborate/launch +0 -6
  93. data/lib/samples/hello/hello_combo.rb +0 -34
  94. data/lib/samples/hello/hello_tab.rb +0 -24
  95. data/lib/samples/hello/hello_world.rb +0 -8
  96. data/lib/samples/hello/launch +0 -10
  97. data/lib/samples/launch +0 -4
@@ -0,0 +1,84 @@
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
+ class HelloRadioGroup
23
+ class Person
24
+ attr_accessor :gender, :age_group
25
+
26
+ def initialize
27
+ reset
28
+ end
29
+
30
+ def gender_options
31
+ ['Male', 'Female']
32
+ end
33
+
34
+ def age_group_options
35
+ ['Child', 'Teen', 'Adult', 'Senior']
36
+ end
37
+
38
+ def reset
39
+ self.gender = nil
40
+ self.age_group = 'Adult'
41
+ end
42
+ end
43
+
44
+ include Glimmer
45
+
46
+ def launch
47
+ person = Person.new
48
+
49
+ shell {
50
+ text 'Hello, Radio Group!'
51
+ row_layout :vertical
52
+
53
+ label {
54
+ text 'Gender:'
55
+ font style: :bold
56
+ }
57
+
58
+ radio_group {
59
+ row_layout :horizontal
60
+ selection bind(person, :gender)
61
+ }
62
+
63
+ label {
64
+ text 'Age Group:'
65
+ font style: :bold
66
+ }
67
+
68
+ radio_group {
69
+ row_layout :horizontal
70
+ selection bind(person, :age_group)
71
+ }
72
+
73
+ button {
74
+ text 'Reset'
75
+
76
+ on_widget_selected do
77
+ person.reset
78
+ end
79
+ }
80
+ }.open
81
+ end
82
+ end
83
+
84
+ HelloRadioGroup.new.launch
@@ -0,0 +1,50 @@
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
+ class HelloTab
23
+ include Glimmer
24
+
25
+ def launch
26
+ shell {
27
+ text 'Hello, Tab!'
28
+
29
+ tab_folder {
30
+ tab_item {
31
+ text 'English'
32
+
33
+ label {
34
+ text 'Hello, World!'
35
+ }
36
+ }
37
+
38
+ tab_item {
39
+ text 'French'
40
+
41
+ label {
42
+ text 'Bonjour, Univers!'
43
+ }
44
+ }
45
+ }
46
+ }.open
47
+ end
48
+ end
49
+
50
+ HelloTab.new.launch
@@ -0,0 +1,29 @@
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
+ include Glimmer
23
+
24
+ shell {
25
+ text 'Glimmer'
26
+ label {
27
+ text 'Hello, World!'
28
+ }
29
+ }.open
@@ -0,0 +1,37 @@
1
+ class OS
2
+ class << self
3
+ def windows?
4
+ # No Op in Opal
5
+ end
6
+
7
+ def mac?
8
+ # No Op in Opal
9
+ end
10
+
11
+ def linux?
12
+ # No Op in Opal
13
+ end
14
+ end
15
+ end
16
+
17
+ class File
18
+ class << self
19
+ def read(*args, &block)
20
+ # TODO implement via asset downloads in the future
21
+ # No Op in Opal
22
+ end
23
+ end
24
+ end
25
+
26
+ class Display
27
+ class << self
28
+ def setAppName(app_name)
29
+ # No Op in Opal
30
+ end
31
+ def setAppVersion(version)
32
+ # No Op in Opal
33
+ end
34
+ end
35
+ end
36
+
37
+ require 'glimmer-dsl-opal'
@@ -4,6 +4,7 @@ require 'glimmer/data_binding/observer'
4
4
  module Glimmer
5
5
  module DataBinding
6
6
  class ElementBinding
7
+ # TODO consider renaming to WidgetBinding since it's no longer dealing with elements directly yet widgets instead
7
8
  include Glimmer
8
9
  include Observable
9
10
  include Observer
@@ -27,7 +28,7 @@ module Glimmer
27
28
  @element.set_attribute(@property, converted_value) unless evaluate_property == converted_value
28
29
  end
29
30
 
30
- def evaluate_property
31
+ def evaluate_property
31
32
  @element.send(@property)
32
33
  end
33
34
  end
@@ -1,6 +1,6 @@
1
1
  require 'glimmer/data_binding/observable'
2
2
  require 'glimmer/data_binding/observer'
3
- require 'glimmer/opal/display_proxy'
3
+ require 'glimmer/swt/display_proxy'
4
4
 
5
5
  # This ensures all data-binding events happen async and block on modal display
6
6
 
@@ -1,16 +1,32 @@
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
+
1
22
  require 'glimmer/dsl/static_expression'
2
- require 'glimmer/dsl/top_level_expression'
3
- require 'glimmer/opal/display_proxy'
23
+ require 'glimmer/dsl/opal/exec_expression'
4
24
 
5
25
  module Glimmer
6
26
  module DSL
7
27
  module Opal
8
28
  class AsyncExecExpression < StaticExpression
9
- include TopLevelExpression
10
-
11
- def interpret(parent, keyword, *args, &block)
12
- Glimmer::Opal::DisplayProxy.instance.async_exec(&block)
13
- end
29
+ include ExecExpression
14
30
  end
15
31
  end
16
32
  end
@@ -0,0 +1,61 @@
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/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/data_binding/element_binding'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Opal
29
+ class CheckboxGroupSelectionDataBindingExpression < Expression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ keyword == 'selection' and
33
+ block.nil? and
34
+ (parent.is_a?(Glimmer::SWT::Custom::CheckboxGroup) or (parent.is_a?(Glimmer::UI::CustomWidget) and parent.body_root.is_a?(Glimmer::SWT::Custom::CheckboxGroup)) ) and
35
+ args.size == 1 and
36
+ args[0].is_a?(DataBinding::ModelBinding) and
37
+ args[0].evaluate_options_property.is_a?(Array)
38
+ end
39
+
40
+ def interpret(parent, keyword, *args, &block)
41
+ model_binding = args[0]
42
+
43
+ #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
44
+ # TODO consider delegating some of this work
45
+ widget_binding = DataBinding::ElementBinding.new(parent, 'items')
46
+ widget_binding.call(model_binding.evaluate_options_property)
47
+ model = model_binding.base_model
48
+ widget_binding.observe(model, model_binding.options_property_name)
49
+
50
+ widget_binding = DataBinding::ElementBinding.new(parent, 'selection')
51
+ widget_binding.call(model_binding.evaluate_property)
52
+ widget_binding.observe(model, model_binding.property_name_expression)
53
+
54
+ parent.on_widget_selected do
55
+ model_binding.call(widget_binding.evaluate_property)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,38 @@
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/dsl/static_expression'
23
+ require 'glimmer/dsl/top_level_expression'
24
+ require 'glimmer/swt/color_proxy'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Opal
29
+ class ColorExpression < StaticExpression
30
+ include TopLevelExpression
31
+
32
+ def interpret(parent, keyword, *args, &block)
33
+ Glimmer::SWT::ColorProxy.new(*args)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,94 @@
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/dsl/expression'
24
+ require 'glimmer/dsl/parent_expression'
25
+ require 'glimmer/dsl/top_level_expression'
26
+ require 'glimmer/ui/custom_widget'
27
+ require 'glimmer/ui/custom_shell'
28
+ require 'glimmer/swt/make_shift_shell_proxy'
29
+ require 'glimmer/swt/custom/radio_group'
30
+ require 'glimmer/swt/custom/checkbox_group'
31
+
32
+ module Glimmer
33
+ module DSL
34
+ module Opal
35
+ class CustomWidgetExpression < Expression
36
+ # TODO Make custom widgets automatically generate static expressions
37
+ include ParentExpression
38
+ include TopLevelExpression
39
+
40
+ def can_interpret?(parent, keyword, *args, &block)
41
+ !!UI::CustomWidget.for(keyword)
42
+ end
43
+
44
+ def interpret(parent, keyword, *args, &block)
45
+ custom_widget_class = UI::CustomWidget.for(keyword)
46
+ # TODO clean code by extracting methods into CustomShell
47
+ if !Glimmer::UI::CustomShell.requested? && custom_widget_class.ancestors.include?(Glimmer::UI::CustomShell)
48
+ if Glimmer::SWT::DisplayProxy.instance.shells.empty?
49
+ custom_widget_class.new(parent, *args, {}, &block)
50
+ else
51
+ options = args.last.is_a?(Hash) ? args.pop : {}
52
+ options = options.merge('swt_style' => args.join(',')) unless args.join(',').empty?
53
+ params = {
54
+ 'custom_shell' => keyword
55
+ }.merge(options)
56
+ param_string = params.to_a.map {|k, v| "#{k}=#{URI.encode_www_form_component(v)}"}.join('&')
57
+ url = "#{`document.location.href`}?#{param_string}"
58
+ `window.open(#{url})`
59
+ # just a placeholder that has an open method # TODO return an actual CustomShell in the future that does the work happening above in the #open method
60
+ Glimmer::SWT::MakeShiftShellProxy.new
61
+ end
62
+ else
63
+ if Glimmer::UI::CustomShell.requested_and_not_handled?
64
+ parameters = Glimmer::UI::CustomShell.request_parameter_string.split("&").map {|str| str.split("=")}.to_h
65
+ `history.pushState(#{parameters.merge('custom_shell_handled' => 'true')}, document.title, #{"?#{Glimmer::UI::CustomShell.encoded_request_parameter_string}&custom_shell_handled=true"})`
66
+ custom_shell_keyword = parameters.delete('custom_shell')
67
+ CustomWidgetExpression.new.interpret(nil, custom_shell_keyword, *[parameters])
68
+ `history.pushState(#{parameters.reject {|k,v| k == 'custom_shell_handled'}}, document.title, #{"?#{Glimmer::UI::CustomShell.encoded_request_parameter_string.sub('&custom_shell_handled=true', '')}"})`
69
+ # just a placeholder that has an open method # TODO return an actual CustomShell in the future that does the work happening above in the #open method
70
+ Glimmer::SWT::MakeShiftShellProxy.new
71
+ else
72
+ custom_widget_class&.new(parent, *args, {}, &block)
73
+ end
74
+ end
75
+ end
76
+
77
+ def add_content(parent, &content)
78
+ content.call(parent) if parent.is_a?(Glimmer::SWT::ShellProxy) || parent.is_a?(Glimmer::UI::CustomShell)
79
+ end
80
+
81
+
82
+ def add_content(parent, &block)
83
+ return unless parent.is_a?(Glimmer::UI::CustomWidget)
84
+ # TODO consider avoiding source_location
85
+ if block.source_location == parent.content&.__getobj__.source_location
86
+ parent.content.call(parent) unless parent.content.called?
87
+ else
88
+ super
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end