glimmer-dsl-opal 0.0.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +56 -0
  3. data/README.md +815 -76
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal.rb +45 -8
  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/glimmer-dsl-opal/missing/net/http.rb +17 -0
  9. data/lib/glimmer-dsl-opal/missing/uri.rb +64 -0
  10. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager.rb +2 -3
  11. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact.rb +0 -0
  12. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_manager_presenter.rb +0 -0
  13. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/contact_manager/contact_repository.rb +24 -99
  14. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/login.rb +0 -0
  15. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe.rb +0 -0
  16. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/board.rb +0 -0
  17. data/lib/{samples → glimmer-dsl-opal/samples}/elaborate/tic_tac_toe/cell.rb +0 -0
  18. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_browser.rb +0 -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 +19 -19
  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/{samples → glimmer-dsl-opal/samples}/hello/hello_list_multi_selection.rb +0 -0
  25. data/lib/{samples → glimmer-dsl-opal/samples}/hello/hello_list_single_selection.rb +0 -0
  26. data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +50 -0
  27. data/lib/glimmer-dsl-opal/samples/hello/hello_world.rb +29 -0
  28. data/lib/glimmer-dsl-opal/vendor/jquery.js +2 -0
  29. data/lib/glimmer/data_binding/element_binding.rb +1 -1
  30. data/lib/glimmer/data_binding/ext/observable_model.rb +6 -6
  31. data/lib/glimmer/data_binding/list_selection_binding.rb +1 -1
  32. data/lib/glimmer/data_binding/table_items_binding.rb +70 -0
  33. data/lib/glimmer/dsl/opal/async_exec_expression.rb +2 -2
  34. data/lib/glimmer/dsl/opal/color_expression.rb +38 -0
  35. data/lib/glimmer/dsl/opal/column_properties_expression.rb +22 -0
  36. data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +2 -2
  37. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +77 -0
  38. data/lib/glimmer/dsl/opal/dsl.rb +15 -14
  39. data/lib/glimmer/dsl/opal/font_expression.rb +47 -0
  40. data/lib/glimmer/dsl/opal/layout_data_expression.rb +2 -2
  41. data/lib/glimmer/dsl/opal/layout_expression.rb +22 -0
  42. data/lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb +2 -3
  43. data/lib/glimmer/dsl/opal/message_box_expression.rb +2 -2
  44. data/lib/glimmer/dsl/opal/property_expression.rb +5 -2
  45. data/lib/glimmer/dsl/opal/rgb_expression.rb +32 -0
  46. data/lib/glimmer/dsl/opal/rgba_expression.rb +32 -0
  47. data/lib/glimmer/dsl/opal/shell_expression.rb +18 -2
  48. data/lib/glimmer/dsl/opal/swt_expression.rb +46 -0
  49. data/lib/glimmer/dsl/opal/{composite_expression.rb → table_column_expression.rb} +3 -3
  50. data/lib/glimmer/dsl/opal/{list_expression.rb → table_expression.rb} +3 -3
  51. data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +29 -0
  52. data/lib/glimmer/dsl/opal/widget_expression.rb +24 -0
  53. data/lib/glimmer/dsl/opal/widget_listener_expression.rb +16 -3
  54. data/lib/glimmer/swt.rb +499 -0
  55. data/lib/glimmer/swt/browser_proxy.rb +27 -0
  56. data/lib/glimmer/swt/button_proxy.rb +40 -0
  57. data/lib/glimmer/swt/color_proxy.rb +119 -0
  58. data/lib/glimmer/{opal/select_proxy.rb → swt/combo_proxy.rb} +24 -19
  59. data/lib/glimmer/swt/composite_proxy.rb +31 -0
  60. data/lib/glimmer/{opal → swt}/display_proxy.rb +6 -4
  61. data/lib/glimmer/{opal → swt}/event_listener_proxy.rb +1 -1
  62. data/lib/glimmer/swt/fill_layout_proxy.rb +84 -0
  63. data/lib/glimmer/swt/font_proxy.rb +79 -0
  64. data/lib/glimmer/swt/grid_layout_proxy.rb +71 -0
  65. data/lib/glimmer/swt/label_proxy.rb +34 -0
  66. data/lib/glimmer/swt/layout_data_proxy.rb +87 -0
  67. data/lib/glimmer/swt/layout_proxy.rb +63 -0
  68. data/lib/glimmer/{opal → swt}/list_proxy.rb +31 -23
  69. data/lib/glimmer/swt/message_box_proxy.rb +143 -0
  70. data/lib/glimmer/{opal → swt}/point.rb +1 -1
  71. data/lib/glimmer/{opal → swt}/property_owner.rb +1 -1
  72. data/lib/glimmer/swt/row_layout_proxy.rb +105 -0
  73. data/lib/glimmer/swt/shell_proxy.rb +246 -0
  74. data/lib/glimmer/swt/style_constantizable.rb +154 -0
  75. data/lib/glimmer/swt/swt_proxy.rb +53 -0
  76. data/lib/glimmer/{opal/tab_folder.rb → swt/tab_folder_proxy.rb} +21 -15
  77. data/lib/glimmer/swt/tab_item_proxy.rb +84 -0
  78. data/lib/glimmer/swt/table_column_proxy.rb +56 -0
  79. data/lib/glimmer/swt/table_item_proxy.rb +147 -0
  80. data/lib/glimmer/swt/table_proxy.rb +159 -0
  81. data/lib/glimmer/swt/text_proxy.rb +46 -0
  82. data/lib/glimmer/swt/widget_proxy.rb +490 -0
  83. data/lib/glimmer/ui/custom_shell.rb +91 -0
  84. data/lib/glimmer/ui/custom_widget.rb +291 -0
  85. data/lib/glimmer/util/proc_tracker.rb +39 -0
  86. metadata +131 -76
  87. data/lib/glimmer/config.rb +0 -22
  88. data/lib/glimmer/dsl/engine.rb +0 -193
  89. data/lib/glimmer/dsl/expression.rb +0 -42
  90. data/lib/glimmer/dsl/expression_handler.rb +0 -48
  91. data/lib/glimmer/dsl/opal/browser_expression.rb +0 -17
  92. data/lib/glimmer/dsl/opal/button_expression.rb +0 -18
  93. data/lib/glimmer/dsl/opal/combo_expression.rb +0 -17
  94. data/lib/glimmer/dsl/opal/grid_layout_expression.rb +0 -17
  95. data/lib/glimmer/dsl/opal/label_expression.rb +0 -17
  96. data/lib/glimmer/dsl/opal/tab_folder_expression.rb +0 -17
  97. data/lib/glimmer/dsl/opal/tab_item_expression.rb +0 -17
  98. data/lib/glimmer/dsl/opal/text_expression.rb +0 -22
  99. data/lib/glimmer/dsl/parent_expression.rb +0 -12
  100. data/lib/glimmer/dsl/static_expression.rb +0 -36
  101. data/lib/glimmer/dsl/top_level_expression.rb +0 -7
  102. data/lib/glimmer/error.rb +0 -6
  103. data/lib/glimmer/invalid_keyword_error.rb +0 -6
  104. data/lib/glimmer/opal/div_proxy.rb +0 -22
  105. data/lib/glimmer/opal/document_proxy.rb +0 -178
  106. data/lib/glimmer/opal/element_proxy.rb +0 -287
  107. data/lib/glimmer/opal/grid_layout_proxy.rb +0 -54
  108. data/lib/glimmer/opal/iframe_proxy.rb +0 -23
  109. data/lib/glimmer/opal/input_proxy.rb +0 -45
  110. data/lib/glimmer/opal/label_proxy.rb +0 -25
  111. data/lib/glimmer/opal/layout_data_proxy.rb +0 -31
  112. data/lib/glimmer/opal/modal.rb +0 -94
  113. data/lib/glimmer/opal/tab_item.rb +0 -98
  114. data/lib/samples/elaborate/launch +0 -6
  115. data/lib/samples/hello/hello_combo.rb +0 -34
  116. data/lib/samples/hello/hello_tab.rb +0 -24
  117. data/lib/samples/hello/hello_world.rb +0 -8
  118. data/lib/samples/hello/launch +0 -10
  119. data/lib/samples/launch +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1e27d44e69248f9febb6c2b8ce6d58d5f6a876d451b09d293769e3296e8c1ff
4
- data.tar.gz: 30f77e89b509c325d8e609a2b6cda35425acb2b3e6f48ed8113c724208a1c0e9
3
+ metadata.gz: 321f0f4121858de374edacf81772b65ff3bd0ee1e155531b5a04681c1e7f5fa0
4
+ data.tar.gz: 5bfab859f5b96458ca452444253a8fb1fefe5274e2bdbc892e574ab6fcd74ed0
5
5
  SHA512:
6
- metadata.gz: 6ee6ca73fef3795d270cf4980fd4392beb39bc2a4f240f5a0fe10014772206aa5da1ca502559a13da2abb3191f681d5f76041003d207736c4469be2709476d73
7
- data.tar.gz: 381fde33081fca87a978babb4e3048acfacf70a56de249eb5ea44be9dd0c6f60139b278601d929110eb6f687f3dd65c31287458d8c98c0fc1e31c59c3b842d71
6
+ metadata.gz: 58ee88fda2ed5729f1c3b58035d6aa252fbb23ac2a12b120e88040aa485d7e34bf9f337c1a8e6f289c73c23528aec4dd735a00c0542c4c120c9499141815cc38
7
+ data.tar.gz: d70d728a4beb4ff5bff63c68b823155ab39b014163698fe875ffacbba09c2e18b91fc3b11fd529876857187fe7aae5e331ecf32b06f4d417a0615bd38d64877a
@@ -1,5 +1,61 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.3.0
4
+
5
+ - Support opening a custom shell in a browser tab/window by passing in query parameters to URL (e.g. ?custom_shell=keyword+option1=value1 etc...)
6
+ - Make custom shells automatically open in a new tab/window (while standard shells continue to open in the same window by replacing its content)
7
+ - Hello, Custom Shell! Sample
8
+
9
+ ## 0.2.0
10
+
11
+ - Color support
12
+ - Font support
13
+ - Custom Widget Support
14
+ - Hello, Custom Widget! sample
15
+ - Updated Hello, Combo! sample to match the latest changes in Glimmer DSL for SWT
16
+ - `SWT` full re-implementation in Opal as `Glimmer::SWT` with all the `SWT` style constants
17
+
18
+ ## 0.1.0
19
+
20
+ - Code redesign to better match the glimmer-dsl-swt APIs
21
+ - opal-jquery refactoring
22
+ - opal-rspec test coverage
23
+
24
+ ## 0.0.9
25
+
26
+ - Upgraded to glimmer gem v0.9.3
27
+ - Fixed issue with missing Glimmer::Opal::ElementProxy#id=(value) method breaking Contact Manager sample Find feature
28
+
29
+ ## 0.0.8
30
+
31
+ - Contact Manager sample support
32
+
33
+ ## 0.0.7
34
+
35
+ - Tic Tac Toe sample support
36
+ - Login sample support
37
+
38
+ ## 0.0.6
39
+
40
+ - Hello, Tab! sample support
41
+
42
+ ## 0.0.5
43
+
44
+ - Hello, Browser! sample support
45
+
46
+ ## 0.0.4
47
+
48
+ - Hello, List Single Selection! sample support
49
+ - Hello, List Multi Selection! sample support
50
+
51
+ ## 0.0.3
52
+
53
+ - Hello, Computed! sample support
54
+
55
+ ## 0.0.2
56
+
57
+ - Hello, Combo! sample support
58
+
3
59
  ## 0.0.1
4
60
 
5
61
  - Initial support for webifying Glimmer SWT apps
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
- # <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=65 /> Glimmer DSL for Opal 0.0.7 (Web GUI for Desktop Apps)
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.3.0 (Webify Desktop Apps)
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
 
5
- [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for Opal is a web GUI adaptor for desktop apps built with [Glimmer](https://github.com/AndyObtiva/glimmer) & [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt).
5
+ ### You can finally live in pure Ruby land on the web!
6
6
 
7
- It enables running [Glimmer](https://github.com/AndyObtiva/glimmer) desktop apps on the web via [Rails](https://rubyonrails.org/) 5 and [Opal](https://opalrb.com/) 1.
7
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [Opal](https://opalrb.com/) is an experimental proof-of-concept web GUI adapter for [Glimmer](https://github.com/AndyObtiva/glimmer) desktop apps (i.e. apps built with [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt)). It webifies them via [Rails](https://rubyonrails.org/), allowing Ruby desktop apps to run on the web via [Opal Ruby](https://opalrb.com/) without changing a line of code. Apps may then be custom-styled for the web with standard CSS by web designers.
8
8
 
9
- NOTE: Alpha Version 0.0.7 only supports capabilities for the following [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) [samples](https://github.com/AndyObtiva/glimmer#samples):
9
+ Glimmer DSL for Opal successfully reuses the entire [Glimmer](https://github.com/AndyObtiva/glimmer) core DSL engine in [Opal Ruby](https://opalrb.com/) inside a web browser, and as such inherits the full range of powerful Glimmer desktop [data-binding](https://github.com/AndyObtiva/glimmer#data-binding) capabilities for the web.
10
10
 
11
- Hello Samples:
11
+ NOTE: Alpha Version 0.3.0 only supports bare-minimum capabilities for the following [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) [samples](https://github.com/AndyObtiva/glimmer#samples):
12
12
  - [Hello, World!](#hello-world)
13
13
  - [Hello, Combo!](#hello-combo)
14
14
  - [Hello, Computed!](#hello-computed)
@@ -16,13 +16,15 @@ Hello Samples:
16
16
  - [Hello, List Multi Selection!](#hello-list-multi-selection)
17
17
  - [Hello, Browser!](#hello-browser)
18
18
  - [Hello, Tab!](#hello-tab)
19
-
20
- Elaborate Samples:
19
+ - [Hello, Custom Widget!](#hello-custom-widget)
20
+ - [Hello, Custom Shell!](#hello-custom-shell)
21
21
  - [Login](#login)
22
22
  - [Tic Tac Toe](#tic-tac-toe)
23
+ - [Contact Manager](#contact-manager)
23
24
 
24
- Other Glimmer DSL gems:
25
- - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (Desktop GUI)
25
+ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
26
+ - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Library)
27
+ - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (Ruby Desktop Development GUI Library)
26
28
  - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
27
29
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
28
30
 
@@ -30,6 +32,7 @@ Other Glimmer DSL gems:
30
32
 
31
33
  The following keywords from [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) have partial support in Opal:
32
34
 
35
+ Widgets:
33
36
  - `shell`
34
37
  - `label`
35
38
  - `combo`
@@ -39,54 +42,113 @@ The following keywords from [glimmer-dsl-swt](https://github.com/AndyObtiva/glim
39
42
  - `list` & `list(:multi)`
40
43
  - `tab_folder`
41
44
  - `tab_item`
42
- - `on_widget_selected`
43
- - `on_modify_text`
45
+ - `table`
46
+ - `table_column`
47
+ - `message_box`
48
+ - CustomWidget (ability to define any keyword as a custom widget)
49
+ - CustomShell (ability to define any keyword as a custom shell (aka custom window) that opens in a new browser window)
50
+
51
+ Layouts:
44
52
  - `grid_layout`
53
+ - `row_layout`
54
+ - `fill_layout`
45
55
  - `layout_data`
46
56
 
57
+ Graphics:
58
+ - `color`
59
+ - `font`
60
+
61
+ Data-Binding/Observers:
62
+ - `bind`
63
+ - `observe`
64
+ - `on_widget_selected`
65
+ - `on_modify_text`
66
+
67
+ Event loop:
68
+ - `async_exec`
69
+
47
70
  ## Pre-requisites
48
71
 
49
72
  - Rails 5: [https://github.com/rails/rails/tree/5-2-stable](https://github.com/rails/rails/tree/5-2-stable)
50
73
  - Opal 1: [https://github.com/opal/opal-rails](https://github.com/opal/opal-rails)
74
+ - 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)
51
75
 
52
76
  ## Setup
53
77
 
54
- Please follow these instructions to make Glimmer desktop apps work in Opal inside Rails 5
78
+ (NOTE: if you run into issues, keep in mind this is a very early experimental and incomplete alpha. Also, there is a slight chance issues you encounter are fixed in master or some other branch that you could check out instead)
79
+
80
+ Please install a Rails 5 gem (e.g. `gem install rails -v5.2.4.3` )
55
81
 
56
82
  Start a new Rails 5 app:
57
83
 
58
84
  ```
59
- rails new hello_world
85
+ rails new glimmer_app
60
86
  ```
61
87
 
62
- Follow instructions to setup opal with a rails application: config/initializers/assets.rb
88
+ Add the following to `Gemfile`:
63
89
 
64
- Add the following to `Gemfile` (NOTE: if you run into issues, they are probably fixed in master or development/wip branch, you may check out instead):
65
90
  ```
66
91
  gem 'opal-rails', '~> 1.1.2'
67
- gem 'opal-async', '~> 1.1.0'
68
- gem 'opal-browser', '~> 0.2.0'
69
- gem 'glimmer-dsl-opal', '~> 0.0.7', require: false
92
+ gem 'opal-async', '~> 1.2.0'
93
+ gem 'opal-jquery', '~> 0.4.4'
94
+ gem 'glimmer-dsl-opal', '~> 0.3.0', require: false
95
+ gem 'glimmer-dsl-xml', '~> 1.1.0', require: false
96
+ gem 'glimmer-dsl-css', '~> 1.1.0', require: false
97
+
70
98
  ```
71
99
 
72
- Edit `config/initializers/assets.rb` and add:
100
+ Follow (opal-rails)[https://github.com/opal/opal-rails] instructions, basically the configuration of: config/initializers/assets.rb
101
+
102
+ Edit `config/initializers/assets.rb` and add the following at the bottom:
73
103
  ```
74
104
  Opal.use_gem 'glimmer-dsl-opal'
75
105
  ```
76
106
 
77
- Add the following line to the top of an empty `app/assets/javascripts/application.js.rb`
107
+ Add the following line to the top of an empty `app/assets/javascripts/application.rb` (replacing `application.js`)
108
+
109
+ ```ruby
110
+ require 'glimmer-dsl-opal' # brings opal and other dependencies automatically
111
+ ```
112
+
113
+ Run:
114
+
115
+ ```
116
+ rails g scaffold welcome
117
+ ```
118
+
119
+ Modify `config/routes.rb`:
78
120
 
79
121
  ```ruby
80
- require 'glimmer-dsl-opal' # brings opal and opal browser too
122
+ root to: 'welcome#index'
123
+ ```
124
+
125
+ Add more code to `app/assets/javascripts/application.rb` inside a `Document.ready?` block from one of the samples below or a [Glimmer](https://github.com/AndyObtiva/glimmer) [app](https://github.com/AndyObtiva/glimmer#app)/[custom-shell gem](https://github.com/AndyObtiva/glimmer#custom-shell-gem).
126
+
127
+ ```ruby
128
+ Document.ready? do
129
+ # require-statement/code goes here.
130
+ end
81
131
  ```
82
132
 
83
133
  ## Samples
84
134
 
135
+ Follow the instructions below to try out [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) samples webified via [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal)
136
+
137
+ Also, this external sample app contains all the samples mentioned below configured inside a Rails 5 [Opal](https://opalrb.com/) app with all the pre-requisites ready to go for convenience:
138
+
139
+ [https://github.com/AndyObtiva/sample-glimmer-dsl-opal-rails5-app](https://github.com/AndyObtiva/sample-glimmer-dsl-opal-rails5-app)
140
+
85
141
  ### Hello Samples
86
142
 
87
143
  #### Hello, World!
88
144
 
89
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
145
+ Add the following require statement to `app/assets/javascripts/application.rb`
146
+
147
+ ```ruby
148
+ require 'glimmer-dsl-opal/samples/hello/hello_world'
149
+ ```
150
+
151
+ Or add the Glimmer code directly if you prefer to play around with it:
90
152
 
91
153
  ```ruby
92
154
  include Glimmer
@@ -96,7 +158,7 @@ shell {
96
158
  label {
97
159
  text 'Hello, World!'
98
160
  }
99
- }
161
+ }.open
100
162
  ```
101
163
 
102
164
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
@@ -118,37 +180,51 @@ You should see "Hello, World!"
118
180
 
119
181
  #### Hello, Combo!
120
182
 
121
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
183
+ Add the following require statement to `app/assets/javascripts/application.rb`
184
+
185
+ ```ruby
186
+ require 'glimmer-dsl-opal/samples/hello/hello_combo'
187
+ ```
188
+
189
+ Or add the Glimmer code directly if you prefer to play around with it:
122
190
 
123
191
  ```ruby
124
192
  class Person
125
193
  attr_accessor :country, :country_options
126
-
194
+
127
195
  def initialize
128
- self.country_options=["", "Canada", "US", "Mexico"]
129
- self.country = "Canada"
196
+ self.country_options = ['', 'Canada', 'US', 'Mexico']
197
+ reset_country
130
198
  end
131
199
 
132
200
  def reset_country
133
- self.country = "Canada"
201
+ self.country = 'Canada'
134
202
  end
135
203
  end
136
204
 
137
205
  class HelloCombo
138
206
  include Glimmer
207
+
139
208
  def launch
140
209
  person = Person.new
210
+
141
211
  shell {
142
- composite {
143
- combo(:read_only) {
144
- selection bind(person, :country)
145
- }
146
- button {
147
- text "Reset"
148
- on_widget_selected do
149
- person.reset_country
150
- end
151
- }
212
+ row_layout(:vertical) {
213
+ pack false
214
+ }
215
+
216
+ text 'Hello, Combo!'
217
+
218
+ combo(:read_only) {
219
+ selection bind(person, :country)
220
+ }
221
+
222
+ button {
223
+ text 'Reset Selection'
224
+
225
+ on_widget_selected do
226
+ person.reset_country
227
+ end
152
228
  }
153
229
  }.open
154
230
  end
@@ -175,7 +251,14 @@ You should see "Hello, Combo!"
175
251
 
176
252
  #### Hello, Computed!
177
253
 
178
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
254
+ Add the following require statement to `app/assets/javascripts/application.rb`
255
+
256
+
257
+ ```ruby
258
+ require 'glimmer-dsl-opal/samples/hello/hello_computed'
259
+ ```
260
+
261
+ Or add the Glimmer code directly if you prefer to play around with it:
179
262
 
180
263
  ```ruby
181
264
  class HelloComputed
@@ -205,15 +288,15 @@ class HelloComputed
205
288
 
206
289
  def initialize
207
290
  @contact = Contact.new(
208
- first_name: "Barry",
209
- last_name: "McKibbin",
291
+ first_name: 'Barry',
292
+ last_name: 'McKibbin',
210
293
  year_of_birth: 1985
211
294
  )
212
295
  end
213
296
 
214
297
  def launch
215
298
  shell {
216
- text "Hello Computed"
299
+ text 'Hello, Computed!'
217
300
  composite {
218
301
  grid_layout {
219
302
  num_columns 2
@@ -221,44 +304,44 @@ class HelloComputed
221
304
  horizontal_spacing 20
222
305
  vertical_spacing 10
223
306
  }
224
- label {text "First &Name: "}
307
+ label {text 'First &Name: '}
225
308
  text {
226
309
  text bind(@contact, :first_name)
227
310
  layout_data {
228
- horizontalAlignment :fill
229
- grabExcessHorizontalSpace true
311
+ horizontal_alignment :fill
312
+ grab_excess_horizontal_space true
230
313
  }
231
314
  }
232
- label {text "&Last Name: "}
315
+ label {text '&Last Name: '}
233
316
  text {
234
317
  text bind(@contact, :last_name)
235
318
  layout_data {
236
- horizontalAlignment :fill
237
- grabExcessHorizontalSpace true
319
+ horizontal_alignment :fill
320
+ grab_excess_horizontal_space true
238
321
  }
239
322
  }
240
- label {text "&Year of Birth: "}
323
+ label {text '&Year of Birth: '}
241
324
  text {
242
325
  text bind(@contact, :year_of_birth)
243
326
  layout_data {
244
- horizontalAlignment :fill
245
- grabExcessHorizontalSpace true
327
+ horizontal_alignment :fill
328
+ grab_excess_horizontal_space true
246
329
  }
247
330
  }
248
- label {text "Name: "}
331
+ label {text 'Name: '}
249
332
  label {
250
333
  text bind(@contact, :name, computed_by: [:first_name, :last_name])
251
334
  layout_data {
252
- horizontalAlignment :fill
253
- grabExcessHorizontalSpace true
335
+ horizontal_alignment :fill
336
+ grab_excess_horizontal_space true
254
337
  }
255
338
  }
256
- label {text "Age: "}
339
+ label {text 'Age: '}
257
340
  label {
258
341
  text bind(@contact, :age, on_write: :to_i, computed_by: [:year_of_birth])
259
342
  layout_data {
260
- horizontalAlignment :fill
261
- grabExcessHorizontalSpace true
343
+ horizontal_alignment :fill
344
+ grab_excess_horizontal_space true
262
345
  }
263
346
  }
264
347
  }
@@ -287,7 +370,14 @@ You should see "Hello, Computed!"
287
370
 
288
371
  #### Hello, List Single Selection!
289
372
 
290
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
373
+ Add the following require statement to `app/assets/javascripts/application.rb`
374
+
375
+
376
+ ```ruby
377
+ require 'glimmer-dsl-opal/samples/hello/hello_list_single_selection'
378
+ ```
379
+
380
+ Or add the Glimmer code directly if you prefer to play around with it:
291
381
 
292
382
  ```ruby
293
383
  class Person
@@ -327,7 +417,7 @@ HelloListSingleSelection.new.launch
327
417
  ```
328
418
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
329
419
 
330
- ![Glimmer DSL for SWT Hello List Single Selection](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-hello-list-single-selection.png)
420
+ ![Glimmer DSL for SWT Hello List Single Selection](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-list-single-selection.png)
331
421
 
332
422
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
333
423
 
@@ -344,7 +434,13 @@ You should see "Hello, List Single Selection!"
344
434
 
345
435
  #### Hello, List Multi Selection!
346
436
 
347
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
437
+ Add the following require statement to `app/assets/javascripts/application.rb`
438
+
439
+ ```ruby
440
+ require 'glimmer-dsl-opal/samples/hello/hello_list_multi_selection'
441
+ ```
442
+
443
+ Or add the Glimmer code directly if you prefer to play around with it:
348
444
 
349
445
  ```ruby
350
446
  class Person
@@ -394,7 +490,7 @@ HelloListMultiSelection.new.launch
394
490
  ```
395
491
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
396
492
 
397
- ![Glimmer DSL for SWT Hello List Multi Selection](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-hello-list-multi-selection.png)
493
+ ![Glimmer DSL for SWT Hello List Multi Selection](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-list-multi-selection.png)
398
494
 
399
495
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
400
496
 
@@ -411,7 +507,13 @@ You should see "Hello, List Multi Selection!"
411
507
 
412
508
  #### Hello, Browser!
413
509
 
414
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
510
+ Add the following require statement to `app/assets/javascripts/application.rb`
511
+
512
+ ```ruby
513
+ require 'glimmer-dsl-opal/samples/hello/hello_browser'
514
+ ```
515
+
516
+ Or add the Glimmer code directly if you prefer to play around with it:
415
517
 
416
518
  ```ruby
417
519
  include Glimmer
@@ -425,7 +527,7 @@ shell {
425
527
  ```
426
528
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
427
529
 
428
- ![Glimmer DSL for SWT Hello Browser](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-hello-browser.png)
530
+ ![Glimmer DSL for SWT Hello Browser](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-browser.png)
429
531
 
430
532
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
431
533
 
@@ -442,7 +544,13 @@ You should see "Hello, Browser!"
442
544
 
443
545
  #### Hello, Tab!
444
546
 
445
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
547
+ Add the following require statement to `app/assets/javascripts/application.rb`
548
+
549
+ ```ruby
550
+ require 'glimmer-dsl-opal/samples/hello/hello_tab'
551
+ ```
552
+
553
+ Or add the Glimmer code directly if you prefer to play around with it:
446
554
 
447
555
  ```ruby
448
556
  class HelloTab
@@ -472,8 +580,8 @@ HelloTab.new.launch
472
580
  ```
473
581
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
474
582
 
475
- ![Glimmer DSL for SWT Hello Tab English](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-hello-tab-english.png)
476
- ![Glimmer DSL for SWT Hello Tab French](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-hello-tab-french.png)
583
+ ![Glimmer DSL for SWT Hello Tab English](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-tab-english.png)
584
+ ![Glimmer DSL for SWT Hello Tab French](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-tab-french.png)
477
585
 
478
586
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
479
587
 
@@ -489,11 +597,280 @@ You should see "Hello, Tab!"
489
597
  ![Glimmer DSL for Opal Hello Tab English](images/glimmer-dsl-opal-hello-tab-english.png)
490
598
  ![Glimmer DSL for Opal Hello Tab French](images/glimmer-dsl-opal-hello-tab-french.png)
491
599
 
600
+ #### Hello, Custom Widget!
601
+
602
+ Add the following require statement to `app/assets/javascripts/application.rb`
603
+
604
+ ```ruby
605
+ require 'glimmer-dsl-opal/samples/hello/hello_custom_widget'
606
+ ```
607
+
608
+ Or add the Glimmer code directly if you prefer to play around with it:
609
+
610
+ ```ruby
611
+ # This class declares a `greeting_label` custom widget (by convention)
612
+ class GreetingLabel
613
+ include Glimmer::UI::CustomWidget
614
+
615
+ # multiple options without default values
616
+ options :name, :colors
617
+
618
+ # single option with default value
619
+ option :greeting, default: 'Hello'
620
+
621
+ # internal attribute (not a custom widget option)
622
+ attr_accessor :color
623
+
624
+ before_body {
625
+ @font = {height: 24, style: :bold}
626
+ @color = :black
627
+ }
628
+
629
+ after_body {
630
+ return if colors.nil?
631
+
632
+ Thread.new {
633
+ colors.cycle { |color|
634
+ async_exec {
635
+ self.color = color
636
+ }
637
+ sleep(1)
638
+ }
639
+ }
640
+ }
641
+
642
+ body {
643
+ # pass received swt_style through to label to customize (e.g. :center to center text)
644
+ label(swt_style) {
645
+ text "#{greeting}, #{name}!"
646
+ font @font
647
+ foreground bind(self, :color)
648
+ }
649
+ }
650
+
651
+ end
652
+
653
+ # including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `greeting_label` custom widget
654
+ include Glimmer
655
+
656
+ shell {
657
+ fill_layout :vertical
658
+
659
+ minimum_size 215, 215
660
+ text 'Hello, Custom Widget!'
661
+
662
+ # custom widget options are passed in a hash
663
+ greeting_label(name: 'Sean')
664
+
665
+ # pass :center SWT style followed by custom widget options hash
666
+ greeting_label(:center, name: 'Laura', greeting: 'Aloha') #
667
+
668
+ greeting_label(:right, name: 'Rick') {
669
+ # you can nest attributes under custom widgets just like any standard widget
670
+ foreground :red
671
+ }
672
+
673
+ # the colors option cycles between colors for the label foreground every second
674
+ greeting_label(:center, name: 'Mary', greeting: 'Aloha', colors: [:red, :dark_green, :blue])
675
+ }.open
676
+ ```
677
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
678
+
679
+ ![Glimmer DSL for SWT Hello Custom Widget](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-custom-widget.gif)
680
+
681
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
682
+
683
+ Start the Rails server:
684
+ ```
685
+ rails s
686
+ ```
687
+
688
+ Visit `http://localhost:3000`
689
+
690
+ You should see "Hello, Custom Widget!"
691
+
692
+ ![Glimmer DSL for Opal Hello Custom Widget](images/glimmer-dsl-opal-hello-custom-widget.gif)
693
+
694
+ #### Hello, Custom Shell!
695
+
696
+ Add the following require statement to `app/assets/javascripts/application.rb`
697
+
698
+ ```ruby
699
+ require 'glimmer-dsl-opal/samples/hello/hello_custom_shell'
700
+ ```
701
+
702
+ Or add the Glimmer code directly if you prefer to play around with it:
703
+
704
+ ```ruby
705
+ require 'date'
706
+
707
+ # This class declares an `email_shell` custom shell, aka custom window (by convention)
708
+ # Used to view an email message
709
+ class EmailShell
710
+ include Glimmer::UI::CustomShell
711
+
712
+ # multiple options without default values
713
+ options :date, :subject, :from, :message
714
+
715
+ # single option with default value
716
+ option :to, default: '"John Irwin" <john.irwin@example.com>'
717
+
718
+ before_body {
719
+ @swt_style |= swt(:shell_trim, :modeless)
720
+ }
721
+
722
+ body {
723
+ # pass received swt_style through to shell to customize it (e.g. :dialog_trim for a blocking shell)
724
+ shell(swt_style) {
725
+ grid_layout(2, false)
726
+
727
+ text subject
728
+
729
+ label {
730
+ text 'Date:'
731
+ }
732
+ label {
733
+ text date
734
+ }
735
+
736
+ label {
737
+ text 'From:'
738
+ }
739
+ label {
740
+ text from
741
+ }
742
+
743
+ label {
744
+ text 'To:'
745
+ }
746
+ label {
747
+ text to
748
+ }
749
+
750
+ label {
751
+ text 'Subject:'
752
+ }
753
+ label {
754
+ text subject
755
+ }
756
+
757
+ label {
758
+ layout_data(:fill, :fill, true, true) {
759
+ horizontal_span 2 #TODO implement
760
+ vertical_indent 10
761
+ }
762
+
763
+ background :white
764
+ text message
765
+ }
766
+ }
767
+ }
768
+
769
+ end
770
+
771
+ class HelloCustomShell
772
+ # including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `email_shell` custom widget
773
+ include Glimmer
774
+
775
+ Email = Struct.new(:date, :subject, :from, :message, keyword_init: true)
776
+ EmailSystem = Struct.new(:emails, keyword_init: true)
777
+
778
+ def initialize
779
+ @email_system = EmailSystem.new(
780
+ emails: [
781
+ 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"),
782
+ 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"),
783
+ 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"),
784
+ 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"),
785
+ 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"),
786
+ 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"),
787
+ ]
788
+ )
789
+ end
790
+
791
+ def launch
792
+ shell {
793
+ grid_layout
794
+
795
+ text 'Hello, Custom Shell!'
796
+
797
+ label {
798
+ font height: 24, style: :bold
799
+ text 'Emails:'
800
+ }
801
+
802
+ label {
803
+ font height: 18
804
+ text 'Click an email to view its message'
805
+ }
806
+
807
+ table {
808
+ layout_data :fill, :fill, true, true
809
+
810
+ table_column {
811
+ text 'Date:'
812
+ width 180
813
+ }
814
+ table_column {
815
+ text 'Subject:'
816
+ width 180
817
+ }
818
+ table_column {
819
+ text 'From:'
820
+ width 360
821
+ }
822
+
823
+ items bind(@email_system, :emails), column_properties(:date, :subject, :from)
824
+
825
+ on_mouse_up { |event|
826
+ email = event.table_item.get_data
827
+ Thread.new do
828
+ async_exec {
829
+ email_shell(date: email.date, subject: email.subject, from: email.from, message: email.message).open
830
+ }
831
+ end
832
+ }
833
+ }
834
+ }.open
835
+ end
836
+ end
837
+
838
+ HelloCustomShell.new.launch
839
+ ```
840
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
841
+
842
+ ![Glimmer DSL for SWT Hello Custom Shell](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-custom-shell.png)
843
+ ![Glimmer DSL for SWT Hello Custom Shell Email1](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-custom-shell-email1.png)
844
+ ![Glimmer DSL for SWT Hello Custom Shell Email2](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-custom-shell-email2.png)
845
+ ![Glimmer DSL for SWT Hello Custom Shell Email3](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-custom-shell-email3.png)
846
+
847
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
848
+
849
+ Start the Rails server:
850
+ ```
851
+ rails s
852
+ ```
853
+
854
+ Visit `http://localhost:3000`
855
+
856
+ You should see "Hello, Custom Widget!"
857
+
858
+ ![Glimmer DSL for Opal Hello Custom Shell](images/glimmer-dsl-opal-hello-custom-shell.png)
859
+ ![Glimmer DSL for Opal Hello Custom Shell Email1](images/glimmer-dsl-opal-hello-custom-shell-email1.png)
860
+ ![Glimmer DSL for Opal Hello Custom Shell Email2](images/glimmer-dsl-opal-hello-custom-shell-email2.png)
861
+ ![Glimmer DSL for Opal Hello Custom Shell Email3](images/glimmer-dsl-opal-hello-custom-shell-email3.png)
862
+
492
863
  ### Elaborate Samples
493
864
 
494
865
  #### Login
495
866
 
496
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
867
+ Add the following require statement to `app/assets/javascripts/application.rb`
868
+
869
+ ```ruby
870
+ require 'glimmer-dsl-opal/samples/elaborate/login'
871
+ ```
872
+
873
+ Or add the Glimmer code directly if you prefer to play around with it:
497
874
 
498
875
  ```ruby
499
876
  require "observer"
@@ -586,9 +963,9 @@ Login.new.launch
586
963
  ```
587
964
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
588
965
 
589
- ![Glimmer DSL for SWT Login](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-login.png)
590
- ![Glimmer DSL for SWT Login Filled In](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-login-filled-in.png)
591
- ![Glimmer DSL for SWT Login Logged In](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-login-logged-in.png)
966
+ ![Glimmer DSL for SWT Login](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-login.png)
967
+ ![Glimmer DSL for SWT Login Filled In](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-login-filled-in.png)
968
+ ![Glimmer DSL for SWT Login Logged In](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-login-logged-in.png)
592
969
 
593
970
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
594
971
 
@@ -607,7 +984,13 @@ You should see "Login" dialog
607
984
 
608
985
  #### Tic Tac Toe
609
986
 
610
- Add the following Glimmer code to `app/assets/javascripts/application.js.rb`
987
+ Add the following require statement to `app/assets/javascripts/application.rb`
988
+
989
+ ```ruby
990
+ require 'glimmer-dsl-opal/samples/elaborate/tic_tac_toe'
991
+ ```
992
+
993
+ Or add the Glimmer code directly if you prefer to play around with it:
611
994
 
612
995
  ```ruby
613
996
  class TicTacToe
@@ -815,9 +1198,9 @@ TicTacToe.new.open
815
1198
  ```
816
1199
  Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
817
1200
 
818
- ![Glimmer DSL for SWT Tic Tac Toe](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-tic-tac-toe.png)
819
- ![Glimmer DSL for SWT Tic Tac Toe In Progress](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-tic-tac-toe-in-progress.png)
820
- ![Glimmer DSL for SWT Tic Tac Toe Game Over](https://github.com/AndyObtiva/glimmer/raw/master/images/glimmer-tic-tac-toe-game-over.png)
1201
+ ![Glimmer DSL for SWT Tic Tac Toe](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-tic-tac-toe.png)
1202
+ ![Glimmer DSL for SWT Tic Tac Toe In Progress](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-tic-tac-toe-in-progress.png)
1203
+ ![Glimmer DSL for SWT Tic Tac Toe Game Over](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-tic-tac-toe-game-over.png)
821
1204
 
822
1205
  Glimmer app on the web (using `glimmer-dsl-opal` gem):
823
1206
 
@@ -834,6 +1217,356 @@ You should see "Tic Tac Toe"
834
1217
  ![Glimmer DSL for Opal Tic Tac Toe In Progress](images/glimmer-dsl-opal-tic-tac-toe-in-progress.png)
835
1218
  ![Glimmer DSL for Opal Tic Tac Toe Game Over](images/glimmer-dsl-opal-tic-tac-toe-game-over.png)
836
1219
 
1220
+ #### Contact Manager
1221
+
1222
+ Add the following require statement to `app/assets/javascripts/application.rb`
1223
+
1224
+ ```ruby
1225
+ require 'glimmer-dsl-opal/samples/elaborate/contact_manager'
1226
+ ```
1227
+
1228
+ Or add the Glimmer code directly if you prefer to play around with it:
1229
+
1230
+ ```ruby
1231
+ class ContactManager
1232
+ class Contact
1233
+ attr_accessor :first_name, :last_name, :email
1234
+
1235
+ def initialize(attribute_map)
1236
+ @first_name = attribute_map[:first_name]
1237
+ @last_name = attribute_map[:last_name]
1238
+ @email = attribute_map[:email]
1239
+ end
1240
+ end
1241
+ end
1242
+
1243
+ class ContactManager
1244
+ class ContactRepository
1245
+ NAMES_FIRST = %w[
1246
+ Liam
1247
+ Noah
1248
+ William
1249
+ James
1250
+ Oliver
1251
+ Benjamin
1252
+ Elijah
1253
+ Lucas
1254
+ Mason
1255
+ Logan
1256
+ Alexander
1257
+ Ethan
1258
+ Jacob
1259
+ Michael
1260
+ Daniel
1261
+ Henry
1262
+ Jackson
1263
+ Sebastian
1264
+ Aiden
1265
+ Matthew
1266
+ Samuel
1267
+ David
1268
+ Joseph
1269
+ Carter
1270
+ Owen
1271
+ Wyatt
1272
+ John
1273
+ Jack
1274
+ Luke
1275
+ Jayden
1276
+ Dylan
1277
+ Grayson
1278
+ Levi
1279
+ Isaac
1280
+ Gabriel
1281
+ Julian
1282
+ Mateo
1283
+ Anthony
1284
+ Jaxon
1285
+ Lincoln
1286
+ Joshua
1287
+ Christopher
1288
+ Andrew
1289
+ Theodore
1290
+ Caleb
1291
+ Ryan
1292
+ Asher
1293
+ Nathan
1294
+ Thomas
1295
+ Leo
1296
+ Isaiah
1297
+ Charles
1298
+ Josiah
1299
+ Hudson
1300
+ Christian
1301
+ Hunter
1302
+ Connor
1303
+ Eli
1304
+ Ezra
1305
+ Aaron
1306
+ Landon
1307
+ Adrian
1308
+ Jonathan
1309
+ Nolan
1310
+ Jeremiah
1311
+ Easton
1312
+ Elias
1313
+ Colton
1314
+ Cameron
1315
+ Carson
1316
+ Robert
1317
+ Angel
1318
+ Maverick
1319
+ Nicholas
1320
+ Dominic
1321
+ Jaxson
1322
+ Greyson
1323
+ Adam
1324
+ Ian
1325
+ Austin
1326
+ Santiago
1327
+ Jordan
1328
+ Cooper
1329
+ Brayden
1330
+ Roman
1331
+ Evan
1332
+ Ezekiel
1333
+ Xaviar
1334
+ Jose
1335
+ Jace
1336
+ Jameson
1337
+ Leonardo
1338
+ Axel
1339
+ Everett
1340
+ Kayden
1341
+ Miles
1342
+ Sawyer
1343
+ Jason
1344
+ Emma
1345
+ Olivia
1346
+ ]
1347
+ NAMES_LAST = %w[
1348
+ Smith
1349
+ Johnson
1350
+ Williams
1351
+ Brown
1352
+ Jones
1353
+ Miller
1354
+ Davis
1355
+ Wilson
1356
+ Anderson
1357
+ Taylor
1358
+ ]
1359
+ def initialize(contacts = nil)
1360
+ @contacts = contacts || 100.times.map do |n|
1361
+ random_first_name_index = (rand*NAMES_FIRST.size).to_i
1362
+ random_last_name_index = (rand*NAMES_LAST.size).to_i
1363
+ first_name = NAMES_FIRST[random_first_name_index]
1364
+ last_name = NAMES_LAST[random_last_name_index]
1365
+ email = "#{first_name}@#{last_name}.com".downcase
1366
+ Contact.new(
1367
+ first_name: first_name,
1368
+ last_name: last_name,
1369
+ email: email
1370
+ )
1371
+ end
1372
+ end
1373
+
1374
+ def find(attribute_filter_map)
1375
+ @contacts.find_all do |contact|
1376
+ match = true
1377
+ attribute_filter_map.keys.each do |attribute_name|
1378
+ contact_value = contact.send(attribute_name).downcase
1379
+ filter_value = attribute_filter_map[attribute_name].downcase
1380
+ match = false unless contact_value.match(filter_value)
1381
+ end
1382
+ match
1383
+ end
1384
+ end
1385
+ end
1386
+ end
1387
+
1388
+ class ContactManager
1389
+ class ContactManagerPresenter
1390
+ attr_accessor :results
1391
+ @@contact_attributes = [:first_name, :last_name, :email]
1392
+ @@contact_attributes.each {|attribute_name| attr_accessor attribute_name}
1393
+
1394
+ def initialize(contact_repository = nil)
1395
+ @contact_repository = contact_repository || ContactRepository.new
1396
+ @results = []
1397
+ end
1398
+
1399
+ def list
1400
+ self.results = @contact_repository.find({})
1401
+ end
1402
+
1403
+ def find
1404
+ filter_map = {}
1405
+ @@contact_attributes.each do |attribute_name|
1406
+ filter_map[attribute_name] = self.send(attribute_name) if self.send(attribute_name)
1407
+ end
1408
+ self.results = @contact_repository.find(filter_map)
1409
+ @sort_attribute_name = nil
1410
+ @sort_direction_ascending = nil
1411
+ end
1412
+
1413
+ def toggle_sort(attribute_name)
1414
+ @sort_attribute_name = attribute_name
1415
+ @sort_direction_ascending = !@sort_direction_ascending
1416
+ sorted_results = self.results.sort_by {|contact| contact.send(attribute_name).downcase}
1417
+ sorted_results = sorted_results.reverse unless @sort_direction_ascending
1418
+ self.results = sorted_results
1419
+ end
1420
+ end
1421
+ end
1422
+
1423
+ class ContactManager
1424
+ include Glimmer
1425
+
1426
+ def initialize
1427
+ @contact_manager_presenter = ContactManagerPresenter.new
1428
+ @contact_manager_presenter.list
1429
+ end
1430
+
1431
+ def launch
1432
+ shell {
1433
+ text "Contact Manager"
1434
+ composite {
1435
+ composite {
1436
+ grid_layout 2, false
1437
+ label {text "First &Name: "}
1438
+ text {
1439
+ text bind(@contact_manager_presenter, :first_name)
1440
+ on_key_pressed {|key_event|
1441
+ @contact_manager_presenter.find if key_event.keyCode == Glimmer::SWT::SWTProxy[:cr]
1442
+ }
1443
+ }
1444
+ label {text "&Last Name: "}
1445
+ text {
1446
+ text bind(@contact_manager_presenter, :last_name)
1447
+ on_key_pressed {|key_event|
1448
+ @contact_manager_presenter.find if key_event.keyCode == Glimmer::SWT::SWTProxy[:cr]
1449
+ }
1450
+ }
1451
+ label {text "&Email: "}
1452
+ text {
1453
+ text bind(@contact_manager_presenter, :email)
1454
+ on_key_pressed {|key_event|
1455
+ @contact_manager_presenter.find if key_event.keyCode == Glimmer::SWT::SWTProxy[:cr]
1456
+ }
1457
+ }
1458
+ composite {
1459
+ grid_layout 2, false
1460
+ button {
1461
+ text "&Find"
1462
+ on_widget_selected {
1463
+ @contact_manager_presenter.find
1464
+ }
1465
+ }
1466
+ button {
1467
+ text "&List All"
1468
+ on_widget_selected {
1469
+ @contact_manager_presenter.list
1470
+ }
1471
+ }
1472
+ }
1473
+ }
1474
+
1475
+ table(:multi) { |table_proxy|
1476
+ layout_data {
1477
+ horizontal_alignment :fill
1478
+ vertical_alignment :fill
1479
+ grab_excess_horizontal_space true
1480
+ grab_excess_vertical_space true
1481
+ height_hint 200
1482
+ }
1483
+ table_column {
1484
+ text "First Name"
1485
+ width 80
1486
+ on_widget_selected {
1487
+ @contact_manager_presenter.toggle_sort(:first_name)
1488
+ }
1489
+ }
1490
+ table_column {
1491
+ text "Last Name"
1492
+ width 80
1493
+ on_widget_selected {
1494
+ @contact_manager_presenter.toggle_sort(:last_name)
1495
+ }
1496
+ }
1497
+ table_column {
1498
+ text "Email"
1499
+ width 200
1500
+ on_widget_selected {
1501
+ @contact_manager_presenter.toggle_sort(:email)
1502
+ }
1503
+ }
1504
+ items bind(@contact_manager_presenter, :results), column_properties(:first_name, :last_name, :email)
1505
+ on_mouse_down { |event|
1506
+ table_proxy.edit_table_item(event.table_item, event.column_index)
1507
+ }
1508
+ }
1509
+ }
1510
+ }.open
1511
+ end
1512
+ end
1513
+
1514
+ ContactManager.new.launch
1515
+
1516
+ ```
1517
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
1518
+
1519
+ Glimmer DSL for SWT Contact Manager
1520
+
1521
+ ![Glimmer DSL for SWT Contact Manager](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-contact-manager.png)
1522
+
1523
+ Glimmer DSL for SWT Contact Manager Find
1524
+
1525
+ ![Glimmer DSL for SWT Contact Manager Find](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-contact-manager-find.png)
1526
+
1527
+ Glimmer DSL for SWT Contact Manager Edit Started
1528
+
1529
+ ![Glimmer DSL for SWT Contact Manager Edit Started](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-contact-manager-edit-started.png)
1530
+
1531
+ Glimmer DSL for SWT Contact Manager Edit In Progress
1532
+
1533
+ ![Glimmer DSL for SWT Contact Manager Edit In Progress](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-contact-manager-edit-in-progress.png)
1534
+
1535
+ Glimmer DSL for SWT Contact Manager Edit Done
1536
+
1537
+ ![Glimmer DSL for SWT Contact Manager Edit Done](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-contact-manager-edit-done.png)
1538
+
1539
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
1540
+
1541
+ Start the Rails server:
1542
+ ```
1543
+ rails s
1544
+ ```
1545
+
1546
+ Visit `http://localhost:3000`
1547
+
1548
+ You should see "Tic Tac Toe"
1549
+
1550
+ Glimmer DSL for Opal Contact Manager
1551
+
1552
+ ![Glimmer DSL for Opal Contact Manager](images/glimmer-dsl-opal-contact-manager.png)
1553
+
1554
+ Glimmer DSL for Opal Contact Manager Find
1555
+
1556
+ ![Glimmer DSL for Opal Contact Manager Find](images/glimmer-dsl-opal-contact-manager-find.png)
1557
+
1558
+ Glimmer DSL for Opal Contact Manager Edit Started
1559
+
1560
+ ![Glimmer DSL for Opal Contact Manager Edit Started](images/glimmer-dsl-opal-contact-manager-edit-started.png)
1561
+
1562
+ Glimmer DSL for Opal Contact Manager Edit In Progress
1563
+
1564
+ ![Glimmer DSL for Opal Contact Manager Edit In Progress](images/glimmer-dsl-opal-contact-manager-edit-in-progress.png)
1565
+
1566
+ Glimmer DSL for Opal Contact Manager Edit Done
1567
+
1568
+ ![Glimmer DSL for Opal Contact Manager Edit Done](images/glimmer-dsl-opal-contact-manager-edit-done.png)
1569
+
837
1570
  ## Help
838
1571
 
839
1572
  ### Issues
@@ -868,5 +1601,11 @@ These features have been suggested. You might see them in a future version of Gl
868
1601
 
869
1602
  ## License
870
1603
 
871
- Copyright (c) 2020 Andy Maleh.
872
- See LICENSE.txt for further details.
1604
+ [MIT](https://opensource.org/licenses/MIT)
1605
+
1606
+ Copyright (c) 2020 - Andy Maleh.
1607
+ See [LICENSE.txt](LICENSE.txt) for further details.
1608
+
1609
+ --
1610
+
1611
+ [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 />](https://github.com/AndyObtiva/glimmer) Built for [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library).