glimmer-dsl-opal 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +195 -167
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal.rb +24 -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 +0 -0
  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 -0
  14. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe.rb +0 -0
  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 +0 -0
  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/{jquery.js → glimmer-dsl-opal/vendor/jquery.js} +0 -0
  28. data/lib/glimmer/data_binding/ext/observable_model.rb +1 -1
  29. data/lib/glimmer/dsl/opal/async_exec_expression.rb +2 -2
  30. data/lib/glimmer/dsl/opal/color_expression.rb +38 -0
  31. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +57 -0
  32. data/lib/glimmer/dsl/opal/dsl.rb +7 -0
  33. data/lib/glimmer/dsl/opal/font_expression.rb +47 -0
  34. data/lib/glimmer/dsl/opal/property_expression.rb +5 -2
  35. data/lib/glimmer/dsl/opal/rgb_expression.rb +32 -0
  36. data/lib/glimmer/dsl/opal/rgba_expression.rb +32 -0
  37. data/lib/glimmer/dsl/opal/swt_expression.rb +46 -0
  38. data/lib/glimmer/dsl/opal/widget_expression.rb +2 -1
  39. data/lib/glimmer/dsl/opal/widget_listener_expression.rb +16 -3
  40. data/lib/glimmer/swt.rb +499 -0
  41. data/lib/glimmer/swt/browser_proxy.rb +1 -1
  42. data/lib/glimmer/swt/button_proxy.rb +2 -2
  43. data/lib/glimmer/swt/color_proxy.rb +119 -0
  44. data/lib/glimmer/swt/combo_proxy.rb +10 -9
  45. data/lib/glimmer/swt/composite_proxy.rb +8 -8
  46. data/lib/glimmer/{opal → swt}/display_proxy.rb +3 -1
  47. data/lib/glimmer/swt/fill_layout_proxy.rb +84 -0
  48. data/lib/glimmer/swt/font_proxy.rb +79 -0
  49. data/lib/glimmer/swt/grid_layout_proxy.rb +34 -4
  50. data/lib/glimmer/swt/label_proxy.rb +7 -3
  51. data/lib/glimmer/swt/layout_proxy.rb +15 -13
  52. data/lib/glimmer/swt/list_proxy.rb +17 -12
  53. data/lib/glimmer/swt/message_box_proxy.rb +4 -7
  54. data/lib/glimmer/swt/row_layout_proxy.rb +105 -0
  55. data/lib/glimmer/swt/shell_proxy.rb +32 -22
  56. data/lib/glimmer/swt/style_constantizable.rb +154 -0
  57. data/lib/glimmer/swt/swt_proxy.rb +53 -0
  58. data/lib/glimmer/swt/tab_folder_proxy.rb +8 -8
  59. data/lib/glimmer/swt/tab_item_proxy.rb +15 -32
  60. data/lib/glimmer/swt/table_proxy.rb +0 -18
  61. data/lib/glimmer/swt/widget_proxy.rb +140 -39
  62. data/lib/glimmer/ui/custom_shell.rb +73 -0
  63. data/lib/glimmer/ui/custom_widget.rb +290 -0
  64. data/lib/glimmer/util/proc_tracker.rb +39 -0
  65. metadata +88 -57
  66. data/lib/glimmer/opal/element_proxy.rb +0 -312
  67. data/lib/samples/elaborate/launch +0 -6
  68. data/lib/samples/hello/hello_combo.rb +0 -34
  69. data/lib/samples/hello/hello_tab.rb +0 -24
  70. data/lib/samples/hello/hello_world.rb +0 -8
  71. data/lib/samples/hello/launch +0 -10
  72. data/lib/samples/launch +0 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,9 +1,21 @@
1
1
  require 'opal'
2
+
2
3
  if RUBY_PLATFORM == 'opal'
4
+ GLIMMER_DSL_OPAL_ROOT = File.expand_path('../..', __FILE__)
5
+ GLIMMER_DSL_OPAL_LIB = File.join(GLIMMER_DSL_OPAL_ROOT, 'lib')
6
+ GLIMMER_DSL_OPAL_MISSING = File.join(GLIMMER_DSL_OPAL_ROOT, 'lib', 'glimmer-dsl-opal', 'missing')
7
+
8
+ $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_LIB)
9
+ $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_MISSING) # missing Ruby classes/methods
10
+
11
+ require 'native' # move this to opal-async
3
12
  require 'opal-async'
4
- require 'jquery' # included in glimmer-dsl-opal
13
+ require 'async/ext'
14
+ require 'glimmer-dsl-opal/vendor/jquery'
5
15
  require 'opal-jquery'
6
16
  require 'glimmer'
17
+ require 'facets/hash/symbolize_keys'
18
+ require 'glimmer-dsl-opal/ext/exception'
7
19
 
8
20
  # Spiking async logging
9
21
  # logger = Glimmer::Config.logger
@@ -14,15 +26,20 @@ if RUBY_PLATFORM == 'opal'
14
26
  # __original_add(*args)
15
27
  # end
16
28
  # end
17
-
18
- GLIMMER_DSL_OPAL_ROOT = File.expand_path('../..', __FILE__)
19
- GLIMMER_DSL_OPAL_LIB = File.join(GLIMMER_DSL_OPAL_ROOT, 'lib')
20
-
21
- $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_LIB)
22
-
29
+
23
30
  require 'glimmer/dsl/opal/dsl'
24
31
  require 'glimmer/data_binding/ext/observable_model'
25
32
 
26
33
  require 'glimmer-dsl-xml'
34
+ require 'glimmer-dsl-css'
27
35
  Element.alias_native :replace_with, :replaceWith
36
+
37
+ # Glimmer::Config.loop_max_count = 20
38
+
39
+ Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
40
+ method = method_symbol.to_s
41
+ result = false
42
+ result ||= method == '<<'
43
+ end
44
+
28
45
  end
@@ -0,0 +1,5 @@
1
+ class Exception
2
+ def full_message
3
+ backtrace.join("\n")
4
+ end
5
+ end
@@ -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
@@ -0,0 +1,26 @@
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
+ end
22
+ module Kernel
23
+ def URI(url)
24
+ URI::HTTP.new(url)
25
+ end
26
+ end
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2007-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_relative "contact"
2
23
 
3
24
  class ContactManager
@@ -103,105 +124,8 @@ class ContactManager
103
124
  Jason
104
125
  Emma
105
126
  Olivia
106
- Ava
107
- Isabella
108
- Sophia
109
- Charlotte
110
- Mia
111
- Amelia
112
- Harper
113
- Evelyn
114
- Abigail
115
- Emily
116
- Elizabeth
117
- Mila
118
- Ella
119
- Avery
120
- Sofia
121
- Camila
122
- Aria
123
- Scarlett
124
- Victoria
125
- Madison
126
- Luna
127
- Grace
128
- Chloe
129
- Penelope
130
- Layla
131
- Riley
132
- Zoey
133
- Nora
134
- Lily
135
- Eleanor
136
- Hannah
137
- Lillian
138
- Addison
139
- Aubrey
140
- Ellie
141
- Stella
142
- Natalie
143
- Zoe
144
- Leah
145
- Hazel
146
- Violet
147
- Aurora
148
- Savannah
149
- Audrey
150
- Brooklyn
151
- Bella
152
- Claire
153
- Skylar
154
- Lucy
155
- Paisley
156
- Everly
157
- Anna
158
- Caroline
159
- Nova
160
- Genesis
161
- Emilia
162
- Kennedy
163
- Samantha
164
- Maya
165
- Willow
166
- Kinsley
167
- Naomi
168
- Aaliyah
169
- Elena
170
- Sarah
171
- Ariana
172
- Allison
173
- Gabriella
174
- Alice
175
- Madelyn
176
- Cora
177
- Ruby
178
- Eva
179
- Serenity
180
- Autumn
181
- Adeline
182
- Hailey
183
- Gianna
184
- Valentina
185
- Isla
186
- Eliana
187
- Quinn
188
- Nevaeh
189
- Ivy
190
- Sadie
191
- Piper
192
- Lydia
193
- Alexa
194
- Josephine
195
- Emery
196
- Julia
197
- Delilah
198
- Arianna
199
- Vivian
200
- Kaylee
201
- Sophie
202
- Brielle
203
- Madeline
204
127
  ]
128
+
205
129
  NAMES_LAST = %w[
206
130
  Smith
207
131
  Johnson
@@ -214,8 +138,9 @@ class ContactManager
214
138
  Anderson
215
139
  Taylor
216
140
  ]
141
+
217
142
  def initialize(contacts = nil)
218
- @contacts = contacts || 1000.times.map do |n|
143
+ @contacts = contacts || 100.times.map do |n|
219
144
  random_first_name_index = (rand*NAMES_FIRST.size).to_i
220
145
  random_last_name_index = (rand*NAMES_LAST.size).to_i
221
146
  first_name = NAMES_FIRST[random_first_name_index]
@@ -0,0 +1,63 @@
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 Person
23
+ attr_accessor :country, :country_options
24
+
25
+ def initialize
26
+ self.country_options = ['', 'Canada', 'US', 'Mexico']
27
+ reset_country
28
+ end
29
+
30
+ def reset_country
31
+ self.country = 'Canada'
32
+ end
33
+ end
34
+
35
+ class HelloCombo
36
+ include Glimmer
37
+
38
+ def launch
39
+ person = Person.new
40
+
41
+ shell {
42
+ row_layout(:vertical) {
43
+ pack false
44
+ }
45
+
46
+ text 'Hello, Combo!'
47
+
48
+ combo(:read_only) {
49
+ selection bind(person, :country)
50
+ }
51
+
52
+ button {
53
+ text 'Reset Selection'
54
+
55
+ on_widget_selected do
56
+ person.reset_country
57
+ end
58
+ }
59
+ }.open
60
+ end
61
+ end
62
+
63
+ HelloCombo.new.launch
@@ -0,0 +1,155 @@
1
+ # Copyright (c) 2007-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 'date'
23
+
24
+ # This class declares an `email_shell` custom shell, aka custom window (by convention)
25
+ # Used to view an email message
26
+ class EmailShell
27
+ include Glimmer::UI::CustomShell
28
+
29
+ # multiple options without default values
30
+ options :date, :subject, :from, :message
31
+
32
+ # single option with default value
33
+ option :to, default: '"John Irwin" <john.irwin@example.com>'
34
+
35
+ before_body {
36
+ @swt_style |= swt(:shell_trim, :modeless)
37
+ }
38
+
39
+ body {
40
+ # pass received swt_style through to shell to customize it (e.g. :dialog_trim for a blocking shell)
41
+ shell(swt_style) {
42
+ grid_layout(2, false)
43
+
44
+ text subject
45
+
46
+ label {
47
+ text 'Date:'
48
+ }
49
+ label {
50
+ text date
51
+ }
52
+
53
+ label {
54
+ text 'From:'
55
+ }
56
+ label {
57
+ text from
58
+ }
59
+
60
+ label {
61
+ text 'To:'
62
+ }
63
+ label {
64
+ text to
65
+ }
66
+
67
+ label {
68
+ text 'Subject:'
69
+ }
70
+ label {
71
+ text subject
72
+ }
73
+
74
+ label {
75
+ layout_data(:fill, :fill, true, true) {
76
+ horizontal_span 2
77
+ verticalIndent 10
78
+ }
79
+
80
+ background :white
81
+ text message
82
+ }
83
+ }
84
+ }
85
+
86
+ end
87
+
88
+ class HelloCustomShell
89
+ # including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `email_shell` custom widget
90
+ include Glimmer
91
+
92
+ Email = Struct.new(:date, :subject, :from, :message, keyword_init: true)
93
+ EmailSystem = Struct.new(:emails, keyword_init: true)
94
+
95
+ def initialize
96
+ @email_system = EmailSystem.new(
97
+ emails: [
98
+ Email.new(date: DateTime.new(2029, 10, 22, 11, 3, 0).strftime('%F %I:%M %p'), subject: '3rd Week Report', from: '"Dianne Tux" <dianne.tux@example.com>', message: "Hello,\n\nI was wondering if you'd like to go over the weekly report sometime this afternoon.\n\nDianne"),
99
+ Email.new(date: DateTime.new(2029, 10, 21, 8, 1, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v100.0', from: '"Robert McGabbins" <robert.mcgabbins@example.com>', message: "Team,\n\nWe are upgrading to Glimmer version 100.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
100
+ Email.new(date: DateTime.new(2029, 10, 19, 16, 58, 0).strftime('%F %I:%M %p'), subject: 'Christmas Party', from: '"Lisa Ferreira" <lisa.ferreira@example.com>', message: "Merry Christmas,\n\nAll office Christmas Party arrangements have been set\n\nMake sure to bring a Secret Santa gift\n\nBest regards,\n\nLisa Ferreira"),
101
+ Email.new(date: DateTime.new(2029, 10, 16, 9, 43, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v99.0', from: '"Robert McGabbins" <robert.mcgabbins@example.com>', message: "Team,\n\nWe are upgrading to Glimmer version 99.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
102
+ Email.new(date: DateTime.new(2029, 10, 15, 11, 2, 0).strftime('%F %I:%M %p'), subject: '2nd Week Report', from: '"Dianne Tux" <dianne.tux@example.com>', message: "Hello,\n\nI was wondering if you'd like to go over the weekly report sometime this afternoon.\n\nDianne"),
103
+ Email.new(date: DateTime.new(2029, 10, 2, 10, 34, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v98.0', from: '"Robert McGabbins" <robert.mcgabbins@example.com>', message: "Team,\n\nWe are upgrading to Glimmer version 98.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
104
+ ]
105
+ )
106
+ end
107
+
108
+ def launch
109
+ shell {
110
+ grid_layout
111
+
112
+ text 'Hello, Custom Shell!'
113
+
114
+ label {
115
+ font height: 24, style: :bold
116
+ text 'Emails:'
117
+ }
118
+
119
+ label {
120
+ font height: 18
121
+ text 'Click an email to view its message'
122
+ }
123
+
124
+ table {
125
+ layout_data :fill, :fill, true, true
126
+
127
+ table_column {
128
+ text 'Date:'
129
+ width 180
130
+ }
131
+ table_column {
132
+ text 'Subject:'
133
+ width 180
134
+ }
135
+ table_column {
136
+ text 'From:'
137
+ width 360
138
+ }
139
+
140
+ items bind(@email_system, :emails), column_properties(:date, :subject, :from)
141
+
142
+ on_mouse_up { |event|
143
+ email = event.table_item.get_data
144
+ Thread.new do
145
+ async_exec {
146
+ email_shell(date: email.date, subject: email.subject, from: email.from, message: email.message).open
147
+ }
148
+ end
149
+ }
150
+ }
151
+ }.open
152
+ end
153
+ end
154
+
155
+ HelloCustomShell.new.launch