glimmer-dsl-opal 0.14.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '009ae1a27f92b9fe4ae8d28374761c84a8a46add536c37b49c67aba167a121b7'
4
- data.tar.gz: baf143fe8365b8a3164eaf74adc4a3df720521557003d0507f09580f0da9b6b3
3
+ metadata.gz: 73ea5888d9b6351e59225c868c98bf3c5f8d7bf20e1314bf2289be1528cd5d65
4
+ data.tar.gz: 0d5420f934e0d29a8fcdb15e68f2e30365f2d70d9d89e2dc19bbd24d14a91626
5
5
  SHA512:
6
- metadata.gz: 81014168a1822232725770564b6f8a4522f08a4e93db72c4986966deaeac28eaffe7674f9446d7abf2d5a3a6056eec38a7f12508c72f751734bd8dc6356fdc2c
7
- data.tar.gz: 800d13580d55f8c1255a68b7c07f6c4e7bdfb9308d3a41b14e44e94b50dd66056c9e437df38f73f2d04643633937cd0a99edba8a1ed174194cf8ce0be25328bf
6
+ metadata.gz: 79e7aae7f3b6e5342e2231f08330cf50e2c5574444b3f07c86b2166722e356e18ca6fb89a2ad21509951360432a42e8f6c449a19b5ff5737b08f521b8f473b79
7
+ data.tar.gz: 6f4be96f8c26c160b0d8d8d2dfc92d40cfa95fc79a76cfe886567cd2f55671861adf9b19cfdbc5d1f6fa78a1ce516f7ab46c330bdef2821a1a312b8b165c91cc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.16.2
4
+
5
+ - Support `grid_layout` `margin_top`, `margin_right`, `margin_bottom`, and `margin_left` attributes
6
+ - Support `row_layout` `wrap` and `justify` attributes
7
+ - Hello, Layout! sample
8
+ - Partial CGI implementation to have `escapeHTML` (alias: `escape_html`) method
9
+ - HTML Escape label text content
10
+ - Fix issue with `row_layout` `fill` attribute not working
11
+
12
+ ## 0.16.1
13
+
14
+ - Support `grid_layout` `make_columns_equal_width`, `horizontal_spacing`, and `vertical_spacing` attributes
15
+ - Hello, Composite! sample
16
+
17
+ ## 0.16.0
18
+
19
+ - Support label widget background_image attribute
20
+ - Have File.expand_path support expanding paths even if they did not base off of __dir__ or __FILE__
21
+ - Custom specification of gems having image paths via server-side configuration in Glimmer::Config.gems_having_image_paths
22
+
23
+ ## 0.15.1
24
+
25
+ - Auto-expose images of gems that depend on glimmer-dsl-opal as downloadable asset links providing `/glimmer/image_paths` server call to obtain them
26
+ - Update Hello, Table! to work with image background
27
+
3
28
  ## 0.14.0
4
29
 
5
30
  - Initial Net::HTTP support for get and post_form
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal 0.14.0 (Pure Ruby Web GUI)
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal 0.16.2 (Pure Ruby Web GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-opal.svg)](http://badge.fury.io/rb/glimmer-dsl-opal)
3
3
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
 
@@ -14,6 +14,8 @@ Glimmer DSL for Opal successfully reuses the entire [Glimmer](https://github.com
14
14
 
15
15
  #### Hello, Table! Sample
16
16
 
17
+ Code: [lib/glimmer-dsl-opal/samples/hello/hello_table.rb](lib/glimmer-dsl-opal/samples/hello/hello_table.rb)
18
+
17
19
  Glimmer GUI code from [glimmer-dsl-opal/samples/hello/hello_table.rb](lib/glimmer-dsl-opal/samples/hello/hello_table.rb):
18
20
 
19
21
  ```ruby
@@ -141,7 +143,7 @@ Hello, Table! Game Booked
141
143
 
142
144
  NOTE: Glimmer DSL for Opal is an alpha project. Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
143
145
 
144
- **Alpha Version** 0.14.0 only supports bare-minimum capabilities for the included [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written for [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt))
146
+ **Alpha Version** 0.16.2 only supports bare-minimum capabilities for the included [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written for [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt))
145
147
 
146
148
  Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
147
149
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
@@ -151,7 +153,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
151
153
 
152
154
  ## Table of Contents
153
155
 
154
- - [Glimmer DSL for Opal 0.14.0 (Pure Ruby Web GUI)](#-glimmer-dsl-for-opal-0140-pure-ruby-web-gui)
156
+ - [Glimmer DSL for Opal 0.16.2 (Pure Ruby Web GUI)](#-glimmer-dsl-for-opal-0162-pure-ruby-web-gui)
155
157
  - [Principles](#principles)
156
158
  - [Background](#background)
157
159
  - [Pre-requisites](#pre-requisites)
@@ -161,6 +163,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
161
163
  - [Hello Samples](#hello-samples)
162
164
  - [Hello, World!](#hello-world)
163
165
  - [Hello, Combo!](#hello-combo)
166
+ - [Hello, Composite!](#hello-composite)
164
167
  - [Hello, Computed!](#hello-computed)
165
168
  - [Hello, List Single Selection!](#hello-list-single-selection)
166
169
  - [Hello, List Multi Selection!](#hello-list-multi-selection)
@@ -221,7 +224,8 @@ Alternatively, web developers may directly use [Glimmer DSL for Opal](https://ru
221
224
  ## Pre-requisites
222
225
 
223
226
  - Rails 5: [https://github.com/rails/rails/tree/5-2-stable](https://github.com/rails/rails/tree/5-2-stable)
224
- - Opal 1: [https://github.com/opal/opal-rails](https://github.com/opal/opal-rails)
227
+ - Opal 1.0.4: [https://github.com/opal/opal](https://github.com/opal/opal)
228
+ - Opal-Rails 1.1.2: [https://github.com/opal/opal-rails](https://github.com/opal/opal-rails)
225
229
  - jQuery 3: [https://code.jquery.com/](https://code.jquery.com/) (jQuery 3.5.1 is included in the [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal) gem)
226
230
  - jQuery-UI 1.12: [https://code.jquery.com/](https://jqueryui.com/) (jQuery-UI 1.12.1 is included in the [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal) gem)
227
231
  - jQuery-UI Timepicker 0.3: [https://code.jquery.com/](https://fgelinas.com/code/timepicker/) (jQuery-UI Timepicker 0.3.3 is included in the [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal) gem)
@@ -249,10 +253,11 @@ rails new glimmer_app_server
249
253
  Add the following to `Gemfile`:
250
254
 
251
255
  ```
252
- gem 'opal-rails', '~> 1.1.2'
256
+ gem 'opal', '1.0.4'
257
+ gem 'opal-rails', '1.1.2'
253
258
  gem 'opal-async', '~> 1.2.0'
254
259
  gem 'opal-jquery', '~> 0.4.4'
255
- gem 'glimmer-dsl-opal', '~> 0.14.0'
260
+ gem 'glimmer-dsl-opal', '~> 0.16.2'
256
261
  gem 'glimmer-dsl-xml', '~> 1.2.0', require: false
257
262
  gem 'glimmer-dsl-css', '~> 1.2.0', require: false
258
263
 
@@ -488,7 +493,7 @@ HelloCombo.launch
488
493
  ```
489
494
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
490
495
 
491
- ![Glimmer DSL for SWT Hello Combo](https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-hello-combo.png)
496
+ ![Glimmer DSL for SWT Hello Combo](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/images/glimmer-hello-combo.png)
492
497
 
493
498
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
494
499
 
@@ -503,6 +508,31 @@ You should see "Hello, Combo!"
503
508
 
504
509
  ![Glimmer DSL for Opal Hello Combo](images/glimmer-dsl-opal-hello-combo.png)
505
510
 
511
+ #### Hello, Composite!
512
+
513
+ Add the following require statement to `app/assets/javascripts/application.rb`
514
+
515
+ ```ruby
516
+ require 'glimmer-dsl-opal/samples/hello/hello_composite'
517
+ ```
518
+
519
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
520
+
521
+ ![Glimmer DSL for SWT Hello Composite](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/images/glimmer-hello-composite.png)
522
+
523
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
524
+
525
+ Start the Rails server:
526
+ ```
527
+ rails s
528
+ ```
529
+
530
+ Visit `http://localhost:3000`
531
+
532
+ You should see "Hello, Composite!"
533
+
534
+ ![Glimmer DSL for Opal Hello Composite](images/glimmer-dsl-opal-hello-composite.png)
535
+
506
536
  #### Hello, Computed!
507
537
 
508
538
  Add the following require statement to `app/assets/javascripts/application.rb`
@@ -626,6 +656,58 @@ You should see "Hello, Computed!"
626
656
 
627
657
  ![Glimmer DSL for Opal Hello Computed](images/glimmer-dsl-opal-hello-computed.png)
628
658
 
659
+ #### Hello, Layout!
660
+
661
+ Add the following require statement to `app/assets/javascripts/application.rb`
662
+
663
+
664
+ ```ruby
665
+ require 'glimmer-dsl-opal/samples/hello/hello_layout'
666
+ ```
667
+
668
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
669
+
670
+ ![Glimmer DSL for SWT Hello Layout](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-layout-tab1.png)
671
+
672
+ ![Glimmer DSL for SWT Hello Layout](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-layout-tab2.png)
673
+
674
+ ![Glimmer DSL for SWT Hello Layout](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-layout-tab3.png)
675
+
676
+ ![Glimmer DSL for SWT Hello Layout](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-layout-tab4.png)
677
+
678
+ ![Glimmer DSL for SWT Hello Layout](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-layout-tab5.png)
679
+
680
+ ![Glimmer DSL for SWT Hello Layout](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-layout-tab6.png)
681
+
682
+ ![Glimmer DSL for SWT Hello Layout](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-layout-tab7.png)
683
+
684
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
685
+
686
+ Start the Rails server:
687
+ ```
688
+ rails s
689
+ ```
690
+
691
+ Visit `http://localhost:3000`
692
+
693
+ You should see "Hello, Layout!"
694
+
695
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab1.png)
696
+
697
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab2.png)
698
+
699
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab3.png)
700
+
701
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab4.png)
702
+
703
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab4-shrunk.png)
704
+
705
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab5.png)
706
+
707
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab6.png)
708
+
709
+ ![Glimmer DSL for Opal Hello Layout](images/glimmer-dsl-opal-hello-layout-tab7.png)
710
+
629
711
  #### Hello, List Single Selection!
630
712
 
631
713
  Add the following require statement to `app/assets/javascripts/application.rb`
@@ -2234,6 +2316,8 @@ Glimmer DSL for Opal Contact Manager Edit Done
2234
2316
 
2235
2317
  #### Weather
2236
2318
 
2319
+ Code: [lib/glimmer-dsl-opal/samples/elaborate/weather](lib/glimmer-dsl-opal/samples/elaborate/weather.rb)
2320
+
2237
2321
  Add the following require statement to `app/assets/javascripts/application.rb`
2238
2322
 
2239
2323
  ```ruby
@@ -2246,7 +2330,7 @@ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObt
2246
2330
 
2247
2331
  ![Weather Montreal F](https://github.com/AMaleh/glimmer-dsl-swt/raw/master/images/glimmer-weather-montreal-fahrenheit.png)
2248
2332
 
2249
- ![Weather Atlanta F](https://github.com/AMaleh /glimmer-dsl-swt/raw/master/images/glimmer-weather-atlanta-fahrenheit.png)
2333
+ ![Weather Atlanta F](https://github.com/AMaleh/glimmer-dsl-swt/raw/master/images/glimmer-weather-atlanta-fahrenheit.png)
2250
2334
 
2251
2335
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
2252
2336
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.0
1
+ 0.16.2
@@ -0,0 +1,4 @@
1
+ module Glimmer
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,46 @@
1
+ require 'fileutils'
2
+
3
+ module Glimmer
4
+ class ImagePathsController < ApplicationController
5
+ def index
6
+ # TODO apply caching in the future to avoid recopying files on every request
7
+ Gem.loaded_specs.map(&:last).select {|s| s.name == 'glimmer-dsl-opal' || s.dependencies.detect {|dep| dep.name == 'glimmer-dsl-opal'} }
8
+ full_gem_specs = Gem.loaded_specs.map(&:last).select do |s|
9
+ s.name == 'glimmer-dsl-opal' ||
10
+ Glimmer::Config.gems_having_image_paths.to_a.include?(s.name) || # consider turning into a Glimmer::Config server-side option
11
+ s.dependencies.detect {|dep| dep.name == 'glimmer-dsl-swt'}
12
+ end
13
+ full_gem_paths = full_gem_specs.map {|gem_spec| gem_spec.full_gem_path}
14
+ full_gem_names = full_gem_paths.map {|path| File.basename(path)}
15
+ full_gem_image_path_collections = full_gem_paths.map do |gem_path|
16
+ Dir[File.join(gem_path, '**', '*')].to_a.select {|f| !!f.match(/(png|jpg|jpeg|gif)$/) }
17
+ end
18
+ download_gem_image_path_collections = full_gem_names.size.times.map do |n|
19
+ full_gem_name = full_gem_names[n]
20
+ full_gem_image_paths = full_gem_image_path_collections[n]
21
+ full_gem_image_paths.map do |image_path|
22
+ File.join(full_gem_name, image_path.split(full_gem_name).last)
23
+ end
24
+ end
25
+ download_gem_image_paths = download_gem_image_path_collections.flatten
26
+ download_gem_image_dir_names = download_gem_image_paths.map {|p| File.dirname(p)}.uniq
27
+ download_gem_image_dir_names.each do |image_dir_name|
28
+ FileUtils.mkdir_p(Rails.root.join('app', 'assets', 'images', image_dir_name))
29
+ end
30
+ full_gem_names.size.times.each do |n|
31
+ full_image_paths = full_gem_image_path_collections[n]
32
+ download_image_paths = download_gem_image_path_collections[n]
33
+ full_image_paths.each_with_index do |image_path, i|
34
+ download_image_path = download_image_paths[i]
35
+ image_dir_name = File.dirname(image_path)
36
+ FileUtils.cp_r(image_path, Rails.root.join('app', 'assets', 'images', download_image_path)) # TODO check first if files match and avoid copying if so to save time
37
+ end
38
+ end
39
+ download_gem_image_paths = download_gem_image_paths.map {|p| "/assets/#{p}"}
40
+
41
+ # TODO apply a security white list
42
+ render json: download_gem_image_paths
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1 @@
1
+ NADA
data/config/routes.rb ADDED
@@ -0,0 +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
+
22
+ Glimmer::Engine.routes.draw do
23
+ resources :image_paths, only: [:index]
24
+ end
data/lib/cgi.rb ADDED
@@ -0,0 +1,14 @@
1
+ class CGI
2
+ class << self
3
+ def escapeHTML(string)
4
+ string.
5
+ gsub('&', '&amp;').
6
+ gsub('<', '&lt;').
7
+ gsub('>', '&gt;').
8
+ gsub("'", '&apos;').
9
+ gsub('"', '&quot;')
10
+ end
11
+ alias escape_html escapeHTML
12
+
13
+ end
14
+ end
@@ -37,6 +37,10 @@ if RUBY_ENGINE == 'opal'
37
37
  def include_package(package)
38
38
  # No Op (just a shim)
39
39
  end
40
+
41
+ def __dir__
42
+ '(dir)'
43
+ end
40
44
  end
41
45
 
42
46
  require 'opal-parser'
@@ -46,6 +50,7 @@ if RUBY_ENGINE == 'opal'
46
50
  require 'to_collection'
47
51
  require 'pure-struct'
48
52
  require 'os'
53
+ require 'cgi'
49
54
  require 'file'
50
55
  require 'display'
51
56
  require 'glimmer-dsl-opal/vendor/jquery'
@@ -81,10 +86,11 @@ if RUBY_ENGINE == 'opal'
81
86
  require 'glimmer/config/opal_logger'
82
87
  require 'glimmer-dsl-xml'
83
88
  require 'glimmer-dsl-css'
89
+
84
90
  Element.alias_native :replace_with, :replaceWith
85
91
  Element.alias_native :select
86
92
  Element.alias_native :dialog
87
-
93
+
88
94
  Glimmer::Config.loop_max_count = 250 # TODO disable
89
95
 
90
96
  original_logger_level = Glimmer::Config.logger.level
@@ -96,7 +102,7 @@ if RUBY_ENGINE == 'opal'
96
102
  result ||= method == '<<'
97
103
  result ||= method == 'handle'
98
104
  end
99
-
100
105
  else
106
+ require_relative 'glimmer/config'
101
107
  require_relative 'glimmer/engine'
102
108
  end
@@ -19,11 +19,36 @@
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 'net/http'
23
+
22
24
  class File
23
25
  class << self
26
+ REGEXP_DIR_FILE = /\(dir\)|\(file\)/
27
+
28
+ attr_accessor :image_paths
29
+
24
30
  def read(*args, &block)
25
31
  # TODO implement via asset downloads in the future
26
32
  # No Op in Opal
27
33
  end
34
+
35
+ # Include special processing for images that matches them against a list of available image paths from the server
36
+ # to convert to web paths.
37
+ alias expand_path_without_glimmer expand_path
38
+ def expand_path(path, base=nil)
39
+ get_image_paths unless image_paths
40
+ path = expand_path_without_glimmer(path, base) if base
41
+ path_include_dir_or_file = !!path.match(REGEXP_DIR_FILE)
42
+ essential_path = path.split('(dir)').last.split('(file)').last.split('../').last.split('./').last
43
+ image_paths.detect do |image_path|
44
+ image_path.include?(essential_path)
45
+ end
46
+ end
47
+
48
+ def get_image_paths
49
+ image_paths_json = Net::HTTP.get(`window.location.origin`, "/glimmer/image_paths.json")
50
+ self.image_paths = JSON.parse(image_paths_json)
51
+ end
52
+
28
53
  end
29
54
  end
@@ -0,0 +1,69 @@
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
+
22
+ class HelloComposite
23
+ include Glimmer::UI::CustomShell
24
+
25
+ body {
26
+ shell {
27
+ # shell (which is a composite) has fill_layout(:horizontal) by default with no margins
28
+ # we override below
29
+ fill_layout(:vertical)
30
+ text 'Hello, Composite!'
31
+
32
+ composite { # composite simply contains widgets for visual organization via a layout
33
+ # it has grid_layout(1, false) as its default layout
34
+ label {
35
+ text "Field is above its text widget"
36
+ }
37
+ text {
38
+ layout_data :fill, :center, true, false # fill horizontally, align center vertically, grab remaining horizontal space, but not vertical
39
+ }
40
+ }
41
+
42
+ composite { # composite simply contains widgets for visual organization via a layout
43
+ grid_layout 2, true
44
+
45
+ label {
46
+ text "Field has equal width to its text widget's"
47
+ }
48
+ text {
49
+ layout_data :fill, :center, true, false # fill horizontally, align center vertically, grab remaining horizontal space, but not vertical
50
+ }
51
+ }
52
+
53
+ composite { # composite simply contains widgets for visual organization via a layout
54
+ grid_layout 2, false
55
+
56
+ label {
57
+ text "Field has inequal width"
58
+ }
59
+
60
+ text {
61
+ layout_data :fill, :center, true, false # fill horizontally, align center vertically, grab remaining horizontal space, but not vertical
62
+ }
63
+ }
64
+ }
65
+
66
+ }
67
+ end
68
+
69
+ HelloComposite.launch
@@ -0,0 +1,241 @@
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
+
22
+ class HelloLayout
23
+ include Glimmer::UI::CustomShell
24
+
25
+ body {
26
+ shell {
27
+ # shell (which is a composite) has fill_layout(:horizontal) by default with no margins
28
+ text 'Hello, Layout!'
29
+ tab_folder {
30
+
31
+ # every tab item has its own composite, which can set a layout
32
+ tab_item {
33
+ text 'Fill Layout (horizontal)'
34
+
35
+ fill_layout(:horizontal) {
36
+ margin_width 30
37
+ margin_height 40
38
+ spacing 5
39
+ }
40
+
41
+ 10.times { |n|
42
+ label {
43
+ text "<label #{n+1}>"
44
+ }
45
+
46
+ }
47
+
48
+ }
49
+
50
+ tab_item {
51
+ text 'Fill Layout (vertical)'
52
+
53
+ fill_layout {
54
+ type :vertical # alternative way of specifying orientation
55
+ margin_width 40
56
+ margin_height 30
57
+ spacing 10
58
+ }
59
+
60
+ 10.times { |n|
61
+ label(:center) {
62
+ text "<label #{n+1}>"
63
+ }
64
+
65
+ }
66
+
67
+ }
68
+
69
+ tab_item {
70
+ text 'Row Layout (horizontal)'
71
+
72
+ row_layout(:horizontal) {
73
+ # row layout has margin attributes for top, left, right, and bottom
74
+ # in addition to width and height (and sets margin_width and margin_height to 5 by default)
75
+ margin_top 40
76
+ margin_left 30
77
+ spacing 5
78
+ wrap false
79
+ center true
80
+ justify true
81
+ }
82
+
83
+ 10.times { |n|
84
+ label {
85
+ text "<label #{n+1}>"
86
+ }
87
+
88
+ }
89
+
90
+ }
91
+
92
+ tab_item {
93
+ text 'Row Layout (wrap on shrink)'
94
+
95
+ row_layout { # :horizontal is the default type
96
+ margin_height 40
97
+ margin_width 30
98
+ spacing 35
99
+ # wrap true # is the default
100
+ }
101
+
102
+ 10.times { |n|
103
+ label {
104
+ text "<label #{n+1}>"
105
+ }
106
+
107
+ }
108
+
109
+ }
110
+
111
+ tab_item {
112
+ text 'Row Layout (vertical)'
113
+ background :yellow
114
+
115
+ row_layout(:vertical) { |l|
116
+ margin_height 0
117
+ margin_width 0
118
+ spacing 10
119
+ fill true # fills horizontally to match the widest child (opposite to row layout orientation)
120
+ center false # enable and disable fill to see what this does
121
+ }
122
+
123
+ 10.times { |n|
124
+ label {
125
+ # layout_data allows a widget to tweak its layout configuration (generating RowData object for RowLayout)
126
+ layout_data {
127
+ height 30
128
+ # width unspecified yet calculated
129
+ }
130
+ text "<this is a ver#{'r'*(rand*200).to_i}y wide label #{n+1}>"
131
+ background :green
132
+ }
133
+
134
+ }
135
+
136
+ }
137
+
138
+ tab_item {
139
+ text 'Grid Layout'
140
+
141
+ grid_layout {
142
+ num_columns 5
143
+ make_columns_equal_width true
144
+ horizontal_spacing 15
145
+ vertical_spacing 10
146
+
147
+ # grid layout has margin attributes for top, left, right, and bottom
148
+ # in addition to width and height (and sets margin_width and margin_height to 5 by default)
149
+ margin_height 0
150
+ margin_top 20
151
+ }
152
+
153
+ 10.times { |n|
154
+ label {
155
+ text "<this label is wide enough to fill #{n+1}>"
156
+ background :white
157
+ }
158
+ }
159
+
160
+ label {
161
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
162
+ layout_data {
163
+ width_hint 120
164
+ height_hint 40
165
+ }
166
+ text "<this label is clipped>"
167
+ background :cyan
168
+ }
169
+
170
+ label {
171
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
172
+ layout_data {
173
+ horizontal_span 2
174
+ }
175
+ text "<this label spans two columns, so it can contain more text than normal>"
176
+ background :green
177
+ }
178
+
179
+ label {
180
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
181
+ layout_data {
182
+ vertical_span 2
183
+ vertical_alignment :fill
184
+ }
185
+ text "<this label spans two rows, \nso it can contain new lines\n1\n2\n3\n4\n5\n6\n7>"
186
+ background :yellow
187
+ }
188
+
189
+ 5.times { label } # just filler
190
+
191
+ label {
192
+
193
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
194
+ layout_data {
195
+ horizontal_span 5
196
+ horizontal_alignment :fill # could be :beginning, :center or :end too
197
+ vertical_alignment :fill # could be :beginning, :center, or :end too
198
+ grab_excess_horizontal_space true
199
+ grab_excess_vertical_space true
200
+ }
201
+
202
+ # this is a short alternative for specifying what is above
203
+ # layout_data(:fill, :fill, true, true) {
204
+ # horizontal_span 5
205
+ # }
206
+
207
+ text "<this label fills all the space it can get\nhorizontally and vertically>"
208
+ background :magenta
209
+ }
210
+
211
+ }
212
+
213
+
214
+ tab_item {
215
+ text 'Grid Layout (non-equal columns)'
216
+
217
+ grid_layout(2, false) # alt syntax: (numColumns, make_columns_equal_width)
218
+
219
+ 10.times { |n|
220
+ label {
221
+ text "Field #{n+1}"
222
+ }
223
+ text {
224
+ layout_data {
225
+ width_hint 600
226
+ }
227
+
228
+ text "Please enter text"
229
+ }
230
+ }
231
+
232
+ }
233
+
234
+ }
235
+
236
+ }
237
+
238
+ }
239
+ end
240
+
241
+ HelloLayout.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
 
@@ -28,13 +28,11 @@ module Glimmer
28
28
 
29
29
  def initialize(parent, args)
30
30
  super(parent, args)
31
- @type = @args.first || :horizontal
31
+ self.type = @args.first || :horizontal
32
32
  self.margin_width = 15
33
33
  self.margin_height = 15
34
34
  @parent.css_classes << 'fill-layout'
35
- @parent.css_classes << (horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
36
35
  @parent.dom_element.add_class('fill-layout')
37
- @parent.dom_element.add_class(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
38
36
  end
39
37
 
40
38
  def horizontal?
@@ -44,6 +42,14 @@ module Glimmer
44
42
  def vertical?
45
43
  @type == :vertical
46
44
  end
45
+
46
+ def type=(value)
47
+ @parent.dom_element.remove_class(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
48
+ @parent.css_classes.delete(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
49
+ @type = value
50
+ @parent.dom_element.add_class(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
51
+ @parent.css_classes << horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical'
52
+ end
47
53
 
48
54
  def margin_width=(pixels)
49
55
  @margin_width = pixels
@@ -12,48 +12,31 @@ module Glimmer
12
12
  }
13
13
  CSS
14
14
 
15
- attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height
15
+ attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height, :margin_top, :margin_right, :margin_bottom, :margin_left
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)
@@ -72,6 +55,38 @@ module Glimmer
72
55
  @parent.dom_element.css('padding-top', effective_margin_height)
73
56
  @parent.dom_element.css('padding-bottom', effective_margin_height)
74
57
  end
58
+
59
+ def margin_top=(pixels)
60
+ @margin_top = pixels
61
+ # Using padding for width since margin-right isn't getting respected with width 100%
62
+ effective_margin_top = @margin_top
63
+ effective_margin_top += 9 if @parent.is_a?(GroupProxy)
64
+ @parent.dom_element.css('padding-top', effective_margin_top)
65
+ end
66
+
67
+ def margin_right=(pixels)
68
+ @margin_right = pixels
69
+ effective_margin_right = @margin_right
70
+ effective_margin_right += 6 if @parent.is_a?(GroupProxy)
71
+ @parent.dom_element.css('padding-right', effective_margin_right)
72
+ end
73
+
74
+ def margin_bottom=(pixels)
75
+ @margin_bottom = pixels
76
+ # Using padding for width since margin-right isn't getting respected with width 100%
77
+ effective_margin_bottom = @margin_bottom
78
+ effective_margin_bottom += 9 if @parent.is_a?(GroupProxy)
79
+ @parent.dom_element.css('padding-bottom', effective_margin_bottom)
80
+ end
81
+
82
+ def margin_left=(pixels)
83
+ @margin_left = pixels
84
+ effective_margin_left = @margin_left
85
+ effective_margin_left += 6 if @parent.is_a?(GroupProxy)
86
+ @parent.dom_element.css('padding-left', effective_margin_left)
87
+ end
88
+
89
+
75
90
 
76
91
  def initialize(parent, args)
77
92
  super(parent, args)
@@ -79,7 +94,8 @@ module Glimmer
79
94
  self.vertical_spacing = 10
80
95
  self.margin_width = 15
81
96
  self.margin_height = 15
82
- self.num_columns = @args.first || 1
97
+ self.num_columns = @args[0] || 1
98
+ self.make_columns_equal_width = @args[1] || false
83
99
  end
84
100
  end
85
101
  end
@@ -33,19 +33,19 @@ module Glimmer
33
33
 
34
34
  def text=(value)
35
35
  @text = value
36
- dom_element.html(html_text)
36
+ dom_element.html(html_text) # TODO deal with issue of handling lines and escaping at the same time
37
37
  end
38
38
 
39
39
  def html_text
40
- text&.gsub("\n", '<br />')
40
+ text && CGI.escape_html(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
 
@@ -24,6 +24,14 @@ module Glimmer
24
24
  margin-left: auto;
25
25
  margin-right: auto;
26
26
  }
27
+
28
+ .row-layout-wrap {
29
+ flex-wrap: wrap;
30
+ }
31
+
32
+ .row-layout-justify {
33
+ justify-content: space-around;
34
+ }
27
35
 
28
36
  .row-layout-horizontal {
29
37
  flex-direction: row;
@@ -42,13 +50,14 @@ module Glimmer
42
50
  }
43
51
  CSS
44
52
 
45
- attr_reader :type, :fill, :margin_width, :margin_height, :margin_top, :margin_right, :margin_bottom, :margin_left, :spacing, :pack, :center
53
+ attr_reader :type, :margin_width, :margin_height, :margin_top, :margin_right, :margin_bottom, :margin_left, :spacing, :pack, :center, :wrap, :justify
46
54
 
47
55
  def initialize(parent, args)
48
56
  super(parent, args)
49
57
  @parent.dom_element.add_class('row-layout')
50
58
  self.type = args.first || :horizontal
51
59
  self.pack = true
60
+ self.wrap = true
52
61
  end
53
62
 
54
63
  def type=(value)
@@ -79,9 +88,13 @@ module Glimmer
79
88
  end
80
89
  end
81
90
 
91
+ def fill
92
+ !pack
93
+ end
94
+
82
95
  def fill=(value)
83
96
  # TODO verify this is a correct implementation and interpretation of RowLayout in SWT
84
- self.pack(!value)
97
+ self.pack = !value
85
98
  end
86
99
 
87
100
  def center=(center_value)
@@ -94,6 +107,24 @@ module Glimmer
94
107
  end
95
108
  end
96
109
 
110
+ def wrap=(wrap_value)
111
+ @wrap = wrap_value
112
+ if @wrap
113
+ parent.dom_element.add_class("row-layout-wrap")
114
+ else
115
+ parent.dom_element.remove_class("row-layout-wrap")
116
+ end
117
+ end
118
+
119
+ def justify=(justify_value)
120
+ @justify = justify_value
121
+ if @justify
122
+ parent.dom_element.add_class("row-layout-justify")
123
+ else
124
+ parent.dom_element.remove_class("row-layout-justify")
125
+ end
126
+ end
127
+
97
128
  def margin_width=(pixels)
98
129
  @margin_width = pixels
99
130
  # Using padding for width since margin-right isn't getting respected with width 100%
@@ -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
@@ -37,7 +37,8 @@ module Net
37
37
  end
38
38
 
39
39
  def get(uri, path_and_params)
40
- uri = "#{`window.location.protocol`}//#{File.join(uri, path_and_params)}" unless uri.start_with?('http:') || uri.start_with?('https:') # TODO refactor repetitive code
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
41
42
  result = nil
42
43
  ::HTTP.get(uri, {async: false, dataType: 'text'}) do |response|
43
44
  result = response.body if response.ok?
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.14.0
4
+ version: 0.16.2
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-11 00:00:00.000000000 Z
11
+ date: 2021-08-13 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,11 @@ 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
270
+ - lib/cgi.rb
266
271
  - lib/display.rb
267
272
  - lib/glimmer-dsl-opal.rb
268
273
  - lib/glimmer-dsl-opal/ext/class.rb
@@ -284,12 +289,14 @@ files:
284
289
  - lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb
285
290
  - lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb
286
291
  - lib/glimmer-dsl-opal/samples/hello/hello_combo.rb
292
+ - lib/glimmer-dsl-opal/samples/hello/hello_composite.rb
287
293
  - lib/glimmer-dsl-opal/samples/hello/hello_computed.rb
288
294
  - lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb
289
295
  - lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb
290
296
  - lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb
291
297
  - lib/glimmer-dsl-opal/samples/hello/hello_dialog.rb
292
298
  - lib/glimmer-dsl-opal/samples/hello/hello_group.rb
299
+ - lib/glimmer-dsl-opal/samples/hello/hello_layout.rb
293
300
  - lib/glimmer-dsl-opal/samples/hello/hello_list_multi_selection.rb
294
301
  - lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb
295
302
  - lib/glimmer-dsl-opal/samples/hello/hello_menu_bar.rb
@@ -299,6 +306,7 @@ files:
299
306
  - lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb
300
307
  - lib/glimmer-dsl-opal/samples/hello/hello_tab.rb
301
308
  - lib/glimmer-dsl-opal/samples/hello/hello_table.rb
309
+ - lib/glimmer-dsl-opal/samples/hello/hello_table/baseball_park.png
302
310
  - lib/glimmer-dsl-opal/samples/hello/hello_world.rb
303
311
  - lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt
304
312
  - lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt
@@ -319,6 +327,7 @@ files:
319
327
  - lib/glimmer-dsl-opal/vendor/jquery-ui/package.json
320
328
  - lib/glimmer-dsl-opal/vendor/jquery.js
321
329
  - lib/glimmer-dsl-swt.rb
330
+ - lib/glimmer/config.rb
322
331
  - lib/glimmer/config/opal_logger.rb
323
332
  - lib/glimmer/data_binding/element_binding.rb
324
333
  - lib/glimmer/data_binding/list_selection_binding.rb
@@ -431,7 +440,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
431
440
  - !ruby/object:Gem::Version
432
441
  version: '0'
433
442
  requirements: []
434
- rubygems_version: 3.2.22
443
+ rubygems_version: 3.2.3
435
444
  signing_key:
436
445
  specification_version: 4
437
446
  summary: Glimmer DSL for Opal