glimmer-dsl-opal 0.13.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,20 +19,38 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require_relative 'hello_computed/contact'
23
-
24
22
  class HelloComputed
25
- include Glimmer
23
+ class Contact
24
+ attr_accessor :first_name, :last_name, :year_of_birth
25
+
26
+ def initialize(attribute_map)
27
+ @first_name = attribute_map[:first_name]
28
+ @last_name = attribute_map[:last_name]
29
+ @year_of_birth = attribute_map[:year_of_birth]
30
+ end
31
+
32
+ def name
33
+ "#{last_name}, #{first_name}"
34
+ end
35
+
36
+ def age
37
+ Time.now.year - year_of_birth.to_i
38
+ rescue
39
+ 0
40
+ end
41
+ end
42
+
43
+ include Glimmer::UI::CustomShell
26
44
 
27
- def initialize
45
+ before_body {
28
46
  @contact = Contact.new(
29
47
  first_name: 'Barry',
30
48
  last_name: 'McKibbin',
31
49
  year_of_birth: 1985
32
50
  )
33
- end
51
+ }
34
52
 
35
- def launch
53
+ body {
36
54
  shell {
37
55
  text 'Hello, Computed!'
38
56
 
@@ -89,8 +107,8 @@ class HelloComputed
89
107
  }
90
108
  }
91
109
  }
92
- }.open
93
- end
110
+ }
111
+ }
94
112
  end
95
113
 
96
- HelloComputed.new.launch
114
+ HelloComputed.launch
@@ -179,25 +179,33 @@ class HelloTable
179
179
  end
180
180
  end
181
181
 
182
- include Glimmer
183
-
184
- def launch
182
+ include Glimmer::UI::CustomShell
183
+
184
+ before_body {
185
+ Display.app_name = 'Hello, Table!'
186
+ }
187
+
188
+ body {
185
189
  shell {
186
190
  grid_layout
187
191
 
188
192
  text 'Hello, Table!'
193
+ background_image File.expand_path('hello_table/baseball_park.png', __dir__)
194
+ image File.expand_path('hello_table/baseball_park.png', __dir__)
189
195
 
190
196
  label {
191
197
  layout_data :center, :center, true, false
192
198
 
193
- text 'Baseball Playoff Schedule'
194
- font height: 30, style: :bold
199
+ text 'BASEBALL PLAYOFF SCHEDULE'
200
+ background :transparent if OS.windows?
201
+ foreground rgb(94, 107, 103)
202
+ font name: 'Optima', height: 38, style: :bold
195
203
  }
196
204
 
197
205
  combo(:read_only) {
198
206
  layout_data :center, :center, true, false
199
207
  selection <=> [BaseballGame, :playoff_type]
200
- font height: 16
208
+ font height: 14
201
209
  }
202
210
 
203
211
  table(:editable) { |table_proxy|
@@ -248,29 +256,29 @@ class HelloTable
248
256
  # Sort by these additional properties after handling sort by the column the user clicked
249
257
  additional_sort_properties :date, :time, :home_team, :away_team, :ballpark, :promotion
250
258
 
251
- # menu {
252
- # menu_item {
253
- # text 'Book'
254
- #
255
- # on_widget_selected {
256
- # book_selected_game
257
- # }
258
- # }
259
- # }
259
+ menu {
260
+ menu_item {
261
+ text 'Book'
262
+
263
+ on_widget_selected {
264
+ book_selected_game
265
+ }
266
+ }
267
+ }
260
268
  }
261
269
 
262
270
  button {
263
271
  text 'Book Selected Game'
264
272
  layout_data :center, :center, true, false
265
- font height: 16
266
- enabled <=> [BaseballGame, :selected_game]
273
+ font height: 14
274
+ enabled <= [BaseballGame, :selected_game]
267
275
 
268
276
  on_widget_selected {
269
277
  book_selected_game
270
278
  }
271
279
  }
272
- }.open
273
- end
280
+ }
281
+ }
274
282
 
275
283
  def book_selected_game
276
284
  message_box {
@@ -280,4 +288,4 @@ class HelloTable
280
288
  end
281
289
  end
282
290
 
283
- HelloTable.new.launch
291
+ HelloTable.launch
@@ -0,0 +1,11 @@
1
+ module Glimmer
2
+ # Consumer Rails apps can set these attributes in their assets.rb file
3
+ module Config
4
+ class << self
5
+ # (server-side option) used to collect image paths for copying to assets & matching in Opal to download and use in Glimmer GUI
6
+ def gems_having_image_paths
7
+ @gems_having_image_paths ||= []
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2020-2021 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
  module Glimmer
2
23
  class Engine < ::Rails::Engine
3
24
  isolate_namespace Glimmer
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2020-2021 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/swt/grid_layout_proxy'
2
23
  require 'glimmer/swt/widget_proxy'
3
24
 
@@ -41,6 +62,19 @@ module Glimmer
41
62
  # TODO implement layout(changed = nil, all = nil) just as per SWT API
42
63
  @layout&.layout(self, changed)
43
64
  end
65
+
66
+ # background image
67
+ def background_image
68
+ @background_image
69
+ end
70
+
71
+ # background image is stretched by default
72
+ def background_image=(value)
73
+ @background_image = value
74
+ dom_element.css('background-image', "url(#{background_image})")
75
+ dom_element.css('background-repeat', 'no-repeat')
76
+ dom_element.css('background-size', 'cover')
77
+ end
44
78
 
45
79
  end
46
80
 
@@ -16,44 +16,27 @@ module Glimmer
16
16
 
17
17
  def num_columns=(columns)
18
18
  @num_columns = columns
19
- # TODO do the following instead of reapply
20
- # @parent.add_css_class("num-columns-#{@num_columns}")
21
- # reinitialize # TODO reimplement without using reinitialize
22
- layout_css = <<~CSS
23
- grid-template-columns: #{'auto ' * @num_columns.to_i};
24
- grid-row-gap: #{@vertical_spacing}px;
25
- grid-column-gap: #{@horizontal_spacing}px;
26
- CSS
27
- if @parent.css_classes.include?('grid-layout')
28
- layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
29
- @parent.dom_element.css(key, value) unless key.nil?
30
- end
31
- if @parent.is_a?(GroupProxy)
32
- @parent.dom_element.find('legend').css('grid-column-start', "span #{@num_columns.to_i}")
33
- end
34
- else
35
- layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
36
- @parent.dom_element.css(key, 'initial') unless key.nil?
37
- end
38
- end
19
+ @parent.dom_element.css('grid-template-columns', 'auto ' * @num_columns.to_i)
20
+ @parent.dom_element.find('legend').css('grid-column-start', "span #{@num_columns.to_i}") if @parent.is_a?(GroupProxy)
39
21
  end
40
22
 
41
23
  def make_columns_equal_width=(equal_width)
42
24
  @make_columns_equal_width = equal_width
43
- # @parent.add_css_class('make_columns_equal_width') if @make_columns_equal_width
44
- # reinitialize # TODO reimplement without using reinitialize
25
+ if @make_columns_equal_width
26
+ @parent.dom_element.css('grid-template-columns', "#{100.0/@num_columns.to_f}% " * @num_columns.to_i)
27
+ else
28
+ @parent.dom_element.css('grid-template-columns', 'auto ' * @num_columns.to_i)
29
+ end
45
30
  end
46
31
 
47
32
  def horizontal_spacing=(spacing)
48
33
  @horizontal_spacing = spacing
49
- # @parent.add_css_class("horizontal-spacing-#{@horizontal_spacing}")
50
- # reinitialize # TODO reimplement without using reinitialize
34
+ @parent.dom_element.css('grid-column-gap', "#{@horizontal_spacing}px")
51
35
  end
52
36
 
53
37
  def vertical_spacing=(spacing)
54
38
  @vertical_spacing = spacing
55
- # @parent.add_css_class("vertical-spacing-#{@vertical_spacing}")
56
- # reinitialize # TODO reimplement without using reinitialize
39
+ @parent.dom_element.css('grid-row-gap', "#{@vertical_spacing}px")
57
40
  end
58
41
 
59
42
  def margin_width=(pixels)
@@ -79,7 +62,8 @@ module Glimmer
79
62
  self.vertical_spacing = 10
80
63
  self.margin_width = 15
81
64
  self.margin_height = 15
82
- self.num_columns = @args.first || 1
65
+ self.num_columns = @args[0] || 1
66
+ self.make_columns_equal_width = @args[1] || false
83
67
  end
84
68
  end
85
69
  end
@@ -40,12 +40,12 @@ module Glimmer
40
40
  text&.gsub("\n", '<br />')
41
41
  end
42
42
 
43
- def background_image=(*image_options)
43
+ # def background_image=(*image_options)
44
44
  # TODO consider if there is a difference between background_image and image in label and to have one reuse the other
45
45
  # TODO finish implementation
46
46
  # @background_image = Glimmer::SWT::ImageProxy.create(*image_options)
47
47
  # dom_element.css('background-image', @background_image.image_data.dom_element.src)
48
- end
48
+ # end
49
49
 
50
50
  def image=(*image_options)
51
51
  # TODO finish implementation
@@ -53,6 +53,19 @@ module Glimmer
53
53
  # dom_element.css('background-image', @image.image_data.dom_element.src)
54
54
  end
55
55
 
56
+ # background image
57
+ def background_image
58
+ @background_image
59
+ end
60
+
61
+ # background image is stretched by default
62
+ def background_image=(value)
63
+ @background_image = value
64
+ dom_element.css('background-image', "url(#{background_image})")
65
+ dom_element.css('background-repeat', 'no-repeat')
66
+ dom_element.css('background-size', 'cover')
67
+ end
68
+
56
69
  def element
57
70
  'label'
58
71
  end
@@ -92,7 +92,7 @@ module Glimmer
92
92
  def grab_excess_horizontal_space=(grab_excess_horizontal_space)
93
93
  @grab_excess_horizontal_space = grab_excess_horizontal_space
94
94
  @parent.dom_element.css('justify-self', @horizontal_alignment) if @grab_excess_horizontal_space && @horizontal_alignment != 'fill' && width_hint.nil?
95
- @parent.parent.dom_element.css('justify-content', "normal") if @grab_excess_horizontal_space
95
+ @parent.parent.dom_element.css('justify-content', 'stretch') if @grab_excess_horizontal_space
96
96
  # reapply
97
97
  end
98
98
 
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2020-2021 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/swt/widget_proxy'
2
23
  require 'glimmer/swt/layout_proxy'
3
24
  require 'glimmer/swt/display_proxy'
@@ -71,6 +92,28 @@ module Glimmer
71
92
  Document.title = value
72
93
  end
73
94
 
95
+ # favicon
96
+ def image
97
+ @image
98
+ end
99
+
100
+ def image=(value)
101
+ @image = value
102
+ # TODO consider moving this code to favicon_dom_element
103
+ if favicon_dom_element.empty?
104
+ favicon_element = Element.new(:link)
105
+ favicon_element.attr('rel', 'icon')
106
+ Document.find('head').append(favicon_element)
107
+ else
108
+ favicon_element = favicon_dom_element
109
+ end
110
+ favicon_element.attr('href', image)
111
+ end
112
+
113
+ def favicon_dom_element
114
+ Document.find('link[rel=icon]')
115
+ end
116
+
74
117
  def minimum_size=(width_or_minimum_size, height = nil)
75
118
  @minimum_size = height.nil? ? width_or_minimum_size : Point.new(width_or_minimum_size, height)
76
119
  return if @minimum_size.nil?
@@ -28,6 +28,9 @@ module Glimmer
28
28
  tr.table-item td {
29
29
  padding-bottom: 0;
30
30
  }
31
+ tr.table-item:nth-child(odd):not(.selected) {
32
+ background: white;
33
+ }
31
34
  tr.table-item:nth-child(even):not(.selected) {
32
35
  background: rgb(243, 244, 246);
33
36
  }
data/lib/net/http.rb CHANGED
@@ -19,8 +19,6 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- # Missing Net module class methods TODO implement
23
-
24
22
  require_relative '../uri'
25
23
 
26
24
  module Net
@@ -30,11 +28,22 @@ module Net
30
28
  class HTTP
31
29
  class << self
32
30
  def post_form(uri, params)
33
- response_body = nil
34
- result = ::HTTP.post(uri, payload: params) do |response|
35
- response_body = response.body
31
+ uri = "#{`window.location.protocol`}//#{File.join(uri)}" unless uri.start_with?('http:') || uri.start_with?('https:') # TODO refactor repetitive code
32
+ result = nil
33
+ ::HTTP.post(uri, {async: false, dataType: 'text', data: params}) do |response|
34
+ result = response.body if response.ok?
35
+ end
36
+ result
37
+ end
38
+
39
+ def get(uri, path_and_params)
40
+ uri = File.join(uri, path_and_params)
41
+ uri = "#{`window.location.protocol`}//#{uri}" unless uri.start_with?('http:') || uri.start_with?('https:') # TODO refactor repetitive code
42
+ result = nil
43
+ ::HTTP.get(uri, {async: false, dataType: 'text'}) do |response|
44
+ result = response.body if response.ok?
36
45
  end
37
- response_body
46
+ result
38
47
  end
39
48
  end
40
49
  end
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.13.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-10 00:00:00.000000000 Z
11
+ date: 2021-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 2.0.1
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: 2.0.0
26
+ version: 2.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: glimmer-dsl-xml
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -263,6 +263,10 @@ files:
263
263
  - app/assets/stylesheets/glimmer/jquery-ui.structure.css
264
264
  - app/assets/stylesheets/glimmer/jquery-ui.theme.css
265
265
  - app/assets/stylesheets/glimmer/jquery.ui.timepicker.css
266
+ - app/controllers/glimmer/application_controller.rb
267
+ - app/controllers/glimmer/image_paths_controller.rb
268
+ - app/views/glimmer/image_paths/index.html.erb
269
+ - config/routes.rb
266
270
  - lib/display.rb
267
271
  - lib/glimmer-dsl-opal.rb
268
272
  - lib/glimmer-dsl-opal/ext/class.rb
@@ -278,13 +282,14 @@ files:
278
282
  - lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb
279
283
  - lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe/board.rb
280
284
  - lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe/cell.rb
285
+ - lib/glimmer-dsl-opal/samples/elaborate/weather.rb
281
286
  - lib/glimmer-dsl-opal/samples/hello/hello_browser.rb
282
287
  - lib/glimmer-dsl-opal/samples/hello/hello_button.rb
283
288
  - lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb
284
289
  - lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb
285
290
  - lib/glimmer-dsl-opal/samples/hello/hello_combo.rb
291
+ - lib/glimmer-dsl-opal/samples/hello/hello_composite.rb
286
292
  - lib/glimmer-dsl-opal/samples/hello/hello_computed.rb
287
- - lib/glimmer-dsl-opal/samples/hello/hello_computed/contact.rb
288
293
  - lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb
289
294
  - lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb
290
295
  - lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb
@@ -299,6 +304,7 @@ files:
299
304
  - lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb
300
305
  - lib/glimmer-dsl-opal/samples/hello/hello_tab.rb
301
306
  - lib/glimmer-dsl-opal/samples/hello/hello_table.rb
307
+ - lib/glimmer-dsl-opal/samples/hello/hello_table/baseball_park.png
302
308
  - lib/glimmer-dsl-opal/samples/hello/hello_world.rb
303
309
  - lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt
304
310
  - lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt
@@ -319,6 +325,7 @@ files:
319
325
  - lib/glimmer-dsl-opal/vendor/jquery-ui/package.json
320
326
  - lib/glimmer-dsl-opal/vendor/jquery.js
321
327
  - lib/glimmer-dsl-swt.rb
328
+ - lib/glimmer/config.rb
322
329
  - lib/glimmer/config/opal_logger.rb
323
330
  - lib/glimmer/data_binding/element_binding.rb
324
331
  - lib/glimmer/data_binding/list_selection_binding.rb
@@ -431,7 +438,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
431
438
  - !ruby/object:Gem::Version
432
439
  version: '0'
433
440
  requirements: []
434
- rubygems_version: 3.2.22
441
+ rubygems_version: 3.2.3
435
442
  signing_key:
436
443
  specification_version: 4
437
444
  summary: Glimmer DSL for Opal