glimmer 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +105 -22
- data/VERSION +1 -1
- data/lib/glimmer.rb +37 -4
- data/lib/glimmer/config.rb +8 -0
- data/lib/glimmer/dsl/engine.rb +41 -25
- data/lib/glimmer/excluded_keyword_error.rb +5 -0
- metadata +45 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6255c2aed0be3512fb9e8e1892232ee9f8ad35efb308ea2dc814f5ff86e69265
|
4
|
+
data.tar.gz: 1c6a024b3ddfed3e296644ec54ce57f38816feb2656a05f2c6daf557cde22b16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39bf5895a97510fe0e40b463b0e77224b7ff09bd695686cf1f38fecdf0e01c1ff86a23ab25a4dbcc3b297906b905be1ad6eb5e8e9fb3fe8e985b39fbda0f80e
|
7
|
+
data.tar.gz: 44068213c246dacc1763868175aba950a9bf78dc803dcb4b0269d3dd9b1ad76c9efd373cb35977b60d7bfcfbe03e8bd07b46ac32595cb89a796e6c9444ff6b0e
|
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
# <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=
|
1
|
+
# <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer (Ruby Desktop Development GUI Library)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/glimmer.svg)](http://badge.fury.io/rb/glimmer)
|
3
3
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer)
|
4
4
|
[![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)
|
5
5
|
|
6
|
+
**[Contributors Wanted!](#contributing)**
|
7
|
+
|
8
|
+
(The Original Glimmer Library Since 2007. Beware of Imitators!)
|
9
|
+
|
6
10
|
Glimmer is a native-GUI cross-platform desktop development library written in Ruby. Glimmer's main innovation is a JRuby DSL that enables productive and efficient authoring of desktop application user-interfaces while relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support to greatly facilitate synchronizing the GUI with domain models. As a result, that achieves true decoupling of object oriented components, enabling developers to solve business problems without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models test-first afterwards.
|
7
11
|
|
8
12
|
[<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
|
@@ -74,15 +78,13 @@ glimmer samples/elaborate/tic_tac_toe.rb
|
|
74
78
|
|
75
79
|
Glimmer app:
|
76
80
|
|
77
|
-
![Tic Tac Toe](images/glimmer-tic-tac-toe.png)
|
81
|
+
![Tic Tac Toe](images/glimmer-tic-tac-toe-in-progress.png)
|
78
82
|
|
79
83
|
NOTE: Glimmer is in beta mode. Please help make better by [contributing](#contributing), adopting for small or low risk projects, and providing feedback.
|
80
84
|
|
81
|
-
Ruby is a dynamically-typed object-oriented language, which provides great productivity gains due to its powerful expressive syntax and dynamic nature. While it is proven by the Ruby on Rails framework for web development, it currently lacks a robust platform-independent framework for building desktop applications. Given that Java libraries can now be utilized in Ruby code through JRuby, Eclipse technologies, such as SWT, JFace, and RCP can help fill the gap of desktop application development with Ruby.
|
82
|
-
|
83
85
|
## Table of contents
|
84
86
|
|
85
|
-
- [Glimmer - Ruby Desktop Development GUI Library](
|
87
|
+
- [Glimmer - Ruby Desktop Development GUI Library](#-glimmer---ruby-desktop-development-gui-library)
|
86
88
|
- [Examples](#examples)
|
87
89
|
- [Hello, World!](#hello-world)
|
88
90
|
- [Tic Tac Toe](#tic-tac-toe)
|
@@ -128,8 +130,10 @@ Ruby is a dynamically-typed object-oriented language, which provides great produ
|
|
128
130
|
- [Observing Models](#observing-models)
|
129
131
|
- [Custom Widgets](#custom-widgets)
|
130
132
|
- [Simple Example](#simple-example)
|
131
|
-
- [Hook Example](#hook-example)
|
133
|
+
- [Lifecycle Hook Example](#lifecycle-hook-example)
|
134
|
+
- [Custom Widget API](#custom-widget-api)
|
132
135
|
- [Content/Options Example](#contentoptions-example)
|
136
|
+
- [Custom Widget Lifecycle Hooks](#custom-widget-lifecycle-hooks)
|
133
137
|
- [Gotcha](#gotcha)
|
134
138
|
- [Custom Shells](#custom-shells)
|
135
139
|
- [Miscellaneous](#miscellaneous)
|
@@ -161,7 +165,7 @@ Ruby is a dynamically-typed object-oriented language, which provides great produ
|
|
161
165
|
- [Resources](#resources)
|
162
166
|
- [Help](#help)
|
163
167
|
- [Issues](#issues)
|
164
|
-
- [
|
168
|
+
- [Chat](#chat)
|
165
169
|
- [Feature Suggestions](#feature-suggestions)
|
166
170
|
- [Change Log](#change-log)
|
167
171
|
- [Contributing](#contributing)
|
@@ -212,7 +216,7 @@ Please follow these instructions to make the `glimmer` command available on your
|
|
212
216
|
|
213
217
|
Run this command to install directly:
|
214
218
|
```
|
215
|
-
jgem install glimmer-dsl-swt -v 0.1.
|
219
|
+
jgem install glimmer-dsl-swt -v 0.1.3
|
216
220
|
```
|
217
221
|
|
218
222
|
`jgem` is JRuby's version of `gem` command.
|
@@ -223,7 +227,7 @@ Otherwise, you may also run `jruby -S gem install ...`
|
|
223
227
|
|
224
228
|
Add the following to `Gemfile`:
|
225
229
|
```
|
226
|
-
gem 'glimmer-dsl-swt', '~> 0.1.
|
230
|
+
gem 'glimmer-dsl-swt', '~> 0.1.3'
|
227
231
|
```
|
228
232
|
|
229
233
|
And, then run:
|
@@ -428,7 +432,7 @@ Example: [https://github.com/AndyObtiva/glimmer-cw-video](https://github.com/And
|
|
428
432
|
|
429
433
|
## Girb (Glimmer irb) Command
|
430
434
|
|
431
|
-
With
|
435
|
+
With `glimmer-dsl-swt` installed, you may want to run `girb` instead of standard `irb` to have SWT preloaded and the Glimmer library required and included for quick Glimmer coding/testing.
|
432
436
|
|
433
437
|
```
|
434
438
|
girb
|
@@ -547,22 +551,22 @@ Check out the [samples](samples) directory for more examples.
|
|
547
551
|
|
548
552
|
Example from [hello_tab.rb](samples/hello/hello_tab.rb) sample (you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
|
549
553
|
|
550
|
-
![Hello Tab
|
554
|
+
![Hello Tab English](images/glimmer-hello-tab-english.png)
|
551
555
|
|
552
|
-
![Hello Tab
|
556
|
+
![Hello Tab French](images/glimmer-hello-tab-french.png)
|
553
557
|
|
554
558
|
```ruby
|
555
559
|
shell {
|
556
|
-
text "
|
560
|
+
text "Hello, Tab!"
|
557
561
|
tab_folder {
|
558
562
|
tab_item {
|
559
|
-
text "
|
563
|
+
text "English"
|
560
564
|
label {
|
561
565
|
text "Hello, World!"
|
562
566
|
}
|
563
567
|
}
|
564
568
|
tab_item {
|
565
|
-
text "
|
569
|
+
text "French"
|
566
570
|
label {
|
567
571
|
text "Bonjour Univers!"
|
568
572
|
}
|
@@ -999,6 +1003,9 @@ composite {
|
|
999
1003
|
```
|
1000
1004
|
|
1001
1005
|
Here is a more sophisticated example taken from [hello_computed.rb](samples/hello/hello_computed.rb) sample:
|
1006
|
+
|
1007
|
+
![Hello Computed](images/glimmer-hello-computed.png)
|
1008
|
+
|
1002
1009
|
```ruby
|
1003
1010
|
shell {
|
1004
1011
|
text "Hello Computed"
|
@@ -1612,7 +1619,7 @@ shell {
|
|
1612
1619
|
|
1613
1620
|
As you can see, `RedLabel` became Glimmer DSL keyword: `red_label`
|
1614
1621
|
|
1615
|
-
#### Hook Example
|
1622
|
+
#### Lifecycle Hook Example
|
1616
1623
|
|
1617
1624
|
(you may copy/paste in [`girb`](#girb-glimmer-irb-command))
|
1618
1625
|
|
@@ -1647,10 +1654,12 @@ shell {
|
|
1647
1654
|
}.open
|
1648
1655
|
```
|
1649
1656
|
|
1650
|
-
Notice how `Red::Composite` became `red__composite` with double-underscore, which is how Glimmer Custom Widgets signify namespaces by convention. Additionally, `before_body` hook was utilized to set a `@color` variable and use inside the `body`.
|
1657
|
+
Notice how `Red::Composite` became `red__composite` with double-underscore, which is how Glimmer Custom Widgets signify namespaces by convention. Additionally, the `before_body` lifecycle hook was utilized to set a `@color` variable and use inside the `body`.
|
1651
1658
|
|
1652
1659
|
Keep in mind that namespaces are not needed to be specified if the Custom Widget class has a unique name, not clashing with a basic SWT widget or another custom widget name.
|
1653
1660
|
|
1661
|
+
#### Custom Widget API
|
1662
|
+
|
1654
1663
|
Custom Widgets have the following attributes available to call from inside the `#body` method:
|
1655
1664
|
- `#parent`: Glimmer object parenting custom widget
|
1656
1665
|
- `#swt_style`: SWT style integer. Can be useful if you want to allow consumers to customize a widget inside the custom widget body
|
@@ -1705,7 +1714,9 @@ shell {
|
|
1705
1714
|
|
1706
1715
|
Notice how `:no_focus` was the `swt_style` value, followed by the `options` hash `{orientation: :horizontal, bg_color: :white}`, and finally the `content` block containing the label with `'SANDWICH CONTENT'`
|
1707
1716
|
|
1708
|
-
|
1717
|
+
#### Custom Widget Lifecycle Hooks
|
1718
|
+
|
1719
|
+
Last but not least, these are the available lifecycle hooks:
|
1709
1720
|
- `before_body`: takes a block that executes in the custom widget instance scope before calling `body`. Useful for initializing variables to later use in `body`
|
1710
1721
|
- `after_body`: takes a block that executes in the custom widget instance scope after calling `body`. Useful for setting up observers on widgets built in `body` (set in instance variables) and linking to other shells.
|
1711
1722
|
|
@@ -2036,6 +2047,8 @@ You may obtain via `glimmer-cw-video` gem.
|
|
2036
2047
|
|
2037
2048
|
#### Browser Widget
|
2038
2049
|
|
2050
|
+
![Hello Browser](images/glimmer-hello-browser.png)
|
2051
|
+
|
2039
2052
|
Glimmer supports SWT Browser widget, which can load URLs or render HTML. It can even be instrumented with JavaScript when needed (though highly discouraged in Glimmer except for rare cases when leveraging a pre-existing web codebase in a desktop app).
|
2040
2053
|
|
2041
2054
|
Example loading a URL (you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
|
@@ -2089,9 +2102,9 @@ This relies on Glimmer's [Multi-DSL Support](#multi-dsl-support) for building th
|
|
2089
2102
|
|
2090
2103
|
## Samples
|
2091
2104
|
|
2092
|
-
Check the [samples](samples) directory for examples on how to write Glimmer applications. To run a sample, make sure to install the `glimmer` gem first and then use the `glimmer` command to run it (alternatively, you may clone the repo, follow [CONTRIBUTING.md](CONTRIBUTING.md) instructions, and run samples locally with development glimmer command: `bin/glimmer`).
|
2105
|
+
Check the [samples](samples) directory in [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) for examples on how to write Glimmer applications. To run a sample, make sure to install the `glimmer` gem first and then use the `glimmer` command to run it (alternatively, you may clone the repo, follow [CONTRIBUTING.md](CONTRIBUTING.md) instructions, and run samples locally with development glimmer command: `bin/glimmer`).
|
2093
2106
|
|
2094
|
-
If you cloned the project and followed [CONTRIBUTING.md](CONTRIBUTING.md) instructions, you may run all samples at once via `samples/launch` command:
|
2107
|
+
If you cloned the project and followed [CONTRIBUTING.md](CONTRIBUTING.md) instructions, you may run all samples in [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) at once via `samples/launch` command:
|
2095
2108
|
|
2096
2109
|
```
|
2097
2110
|
samples/launch
|
@@ -2115,12 +2128,52 @@ glimmer samples/hello/hello_computed.rb # demonstrates computed data-binding
|
|
2115
2128
|
|
2116
2129
|
For more elaborate samples, check the following:
|
2117
2130
|
|
2131
|
+
#### Login
|
2132
|
+
|
2118
2133
|
```
|
2119
2134
|
glimmer samples/elaborate/login.rb # demonstrates basic data-binding
|
2120
|
-
|
2135
|
+
```
|
2136
|
+
|
2137
|
+
![Login](images/glimmer-login.png)
|
2138
|
+
![Login Filled In](images/glimmer-login-filled-in.png)
|
2139
|
+
![Login Logged In](images/glimmer-login-logged-in.png)
|
2140
|
+
|
2141
|
+
#### Tic Tac Toe
|
2142
|
+
|
2143
|
+
```
|
2121
2144
|
glimmer samples/elaborate/tic_tac_toe.rb # demonstrates a full MVC application
|
2122
2145
|
```
|
2123
2146
|
|
2147
|
+
![Tic Tac Toe](images/glimmer-tic-tac-toe.png)
|
2148
|
+
![Tic Tac Toe In Progress](images/glimmer-tic-tac-toe-in-progress.png)
|
2149
|
+
![Tic Tac Toe Game Over](images/glimmer-tic-tac-toe-game-over.png)
|
2150
|
+
|
2151
|
+
#### Contact Manager
|
2152
|
+
|
2153
|
+
```
|
2154
|
+
glimmer samples/elaborate/contact_manager.rb # demonstrates table data-binding
|
2155
|
+
```
|
2156
|
+
|
2157
|
+
Contact Manager
|
2158
|
+
|
2159
|
+
![Contact Manager](images/glimmer-contact-manager.png)
|
2160
|
+
|
2161
|
+
Contact Manager - Find
|
2162
|
+
|
2163
|
+
![Contact Manager](images/glimmer-contact-manager-find.png)
|
2164
|
+
|
2165
|
+
Contact Manager - Edit Started
|
2166
|
+
|
2167
|
+
![Contact Manager](images/glimmer-contact-manager-edit-started.png)
|
2168
|
+
|
2169
|
+
Contact Manager - Edit In Progress
|
2170
|
+
|
2171
|
+
![Contact Manager](images/glimmer-contact-manager-edit-in-progress.png)
|
2172
|
+
|
2173
|
+
Contact Manager - Edit Done
|
2174
|
+
|
2175
|
+
![Contact Manager](images/glimmer-contact-manager-edit-done.png)
|
2176
|
+
|
2124
2177
|
### External Samples
|
2125
2178
|
|
2126
2179
|
#### Glimmer Calculator
|
@@ -2136,12 +2189,24 @@ glimmer samples/elaborate/tic_tac_toe.rb # demonstrates a full MVC application
|
|
2136
2189
|
[Gladiator](https://github.com/AndyObtiva/glimmer-cs-gladiator) (short for Glimmer Editor) is a Glimmer sample project under on-going development.
|
2137
2190
|
You may check it out to learn how to build a Glimmer Custom Shell gem.
|
2138
2191
|
|
2192
|
+
Gladiator is a good demonstration of:
|
2193
|
+
- MVP Pattern
|
2194
|
+
- Tree data-binding
|
2195
|
+
- List data-binding
|
2196
|
+
- Text selection data-binding
|
2197
|
+
- Tabs
|
2198
|
+
- Context menus
|
2199
|
+
- Custom Shell
|
2200
|
+
- Custom widget
|
2201
|
+
|
2139
2202
|
## In Production
|
2140
2203
|
|
2141
2204
|
The following production apps have been built with Glimmer:
|
2142
2205
|
|
2143
2206
|
[<img alt="Math Bowling Logo" src="https://raw.githubusercontent.com/AndyObtiva/MathBowling/master/images/math-bowling-logo.png" width="40" />Math Bowling](https://github.com/AndyObtiva/MathBowling): an educational math game for elementary level kids
|
2144
2207
|
|
2208
|
+
If you have a Glimmer app you would like referenced here, please mention in a Pull Request.
|
2209
|
+
|
2145
2210
|
## SWT Reference
|
2146
2211
|
|
2147
2212
|
https://www.eclipse.org/swt/docs.php
|
@@ -2202,6 +2267,14 @@ You can learn more about importing Java packages into Ruby code at this JRuby WI
|
|
2202
2267
|
|
2203
2268
|
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
|
2204
2269
|
|
2270
|
+
## Infinite Loop Detection
|
2271
|
+
|
2272
|
+
Glimmer can detect if an infinite loop occurs with method_missing by ensuring it does not loop with the same keyword and args more than 100 times.
|
2273
|
+
|
2274
|
+
The max limit can be changed via the `Glimmer::Config::loop_max_count=(count)` method.
|
2275
|
+
|
2276
|
+
Infinite loop detection may be disabled by setting `Glimmer::Config::loop_max_count` to `-1`
|
2277
|
+
|
2205
2278
|
## Logging
|
2206
2279
|
|
2207
2280
|
Glimmer comes with a Ruby Logger accessible via `Glimmer::Config.logger`
|
@@ -2423,7 +2496,11 @@ If you need live help, try to [![Join the chat at https://gitter.im/AndyObtiva/g
|
|
2423
2496
|
|
2424
2497
|
These features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions.
|
2425
2498
|
|
2426
|
-
[TODO.md](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/TODO.md)
|
2499
|
+
[glimmer-dsl-swt/TODO.md](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/TODO.md)
|
2500
|
+
|
2501
|
+
Glimmer DSL Engine specific tasks are at:
|
2502
|
+
|
2503
|
+
[TODO.md](TODO.md)
|
2427
2504
|
|
2428
2505
|
## Change Log
|
2429
2506
|
|
@@ -2431,6 +2508,10 @@ These features have been suggested. You might see them in a future version of Gl
|
|
2431
2508
|
|
2432
2509
|
## Contributing
|
2433
2510
|
|
2511
|
+
**Contributors Wanted!**
|
2512
|
+
|
2513
|
+
If you would like to contribute to Glimmer, please study up on Glimmer and [SWT](#swt-reference), run all Glimmer [samples](#samples), and build a small sample app to add to [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) Hello or Elaborate samples via a Pull Request. Once done, contact me on [Chat](#chat).
|
2514
|
+
|
2434
2515
|
[CONTRIBUTING.md](CONTRIBUTING.md)
|
2435
2516
|
|
2436
2517
|
## Contributors
|
@@ -2444,3 +2525,5 @@ These features have been suggested. You might see them in a future version of Gl
|
|
2444
2525
|
|
2445
2526
|
Copyright (c) 2007-2020 Andy Maleh.
|
2446
2527
|
See LICENSE.txt for further details.
|
2528
|
+
|
2529
|
+
Glimmer logo was made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.3
|
data/lib/glimmer.rb
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
require 'logger'
|
6
6
|
require 'set'
|
7
7
|
|
8
|
+
$LOAD_PATH.unshift(File.expand_path('..', __FILE__))
|
9
|
+
|
10
|
+
require 'glimmer/config'
|
11
|
+
|
8
12
|
# Glimmer provides a JRuby Desktop UI DSL + Data-Binding functionality
|
9
13
|
#
|
10
14
|
# A desktop UI application class must include Glimmer to gain access to Glimmer DSL
|
@@ -14,14 +18,45 @@ require 'set'
|
|
14
18
|
module Glimmer
|
15
19
|
#TODO make it configurable to include or not include perhaps reverting to using included
|
16
20
|
REGEX_METHODS_EXCLUDED = /^(to_|\[)/
|
21
|
+
|
22
|
+
# TODO add loop detection support to avoid infinite loops (perhaps breaks after 3 repetitions and provides an option to allow it if intentional)
|
23
|
+
class << self
|
24
|
+
attr_accessor :loop_last_data
|
25
|
+
|
26
|
+
def loop_reset!(including_loop_last_data = false)
|
27
|
+
@loop_last_data = nil if including_loop_last_data
|
28
|
+
@loop = 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def loop
|
32
|
+
@loop ||= loop_reset!
|
33
|
+
end
|
34
|
+
|
35
|
+
def loop_increment!
|
36
|
+
@loop = loop + 1
|
37
|
+
end
|
38
|
+
end
|
17
39
|
|
18
40
|
def method_missing(method_symbol, *args, &block)
|
41
|
+
new_loop_data = [method_symbol, args, block]
|
42
|
+
if new_loop_data == Glimmer.loop_last_data
|
43
|
+
Glimmer.loop_increment!
|
44
|
+
if Glimmer.loop == Config.loop_max_count
|
45
|
+
raise "Glimmer looped #{Config.loop_max_count} times with keyword '#{new_loop_data[0]}'! Check code for errors."
|
46
|
+
end
|
47
|
+
else
|
48
|
+
Glimmer.loop_reset!
|
49
|
+
end
|
50
|
+
Glimmer.loop_last_data = new_loop_data
|
19
51
|
# This if statement speeds up Glimmer in girb or whenever directly including on main object
|
20
52
|
if method_symbol.to_s.match(REGEX_METHODS_EXCLUDED)
|
21
|
-
raise
|
53
|
+
raise ExcludedKeywordError, "Glimmer excluded keyword: #{method_symbol}"
|
22
54
|
end
|
23
55
|
Glimmer::Config.logger&.debug "Interpreting keyword: #{method_symbol}"
|
24
56
|
Glimmer::DSL::Engine.interpret(method_symbol, *args, &block)
|
57
|
+
rescue ExcludedKeywordError => e
|
58
|
+
# TODO add a feature to show excluded keywords optionally for debugging purposes
|
59
|
+
super(method_symbol, *args, &block)
|
25
60
|
rescue InvalidKeywordError => e
|
26
61
|
if !method_symbol.to_s.match(REGEX_METHODS_EXCLUDED)
|
27
62
|
Glimmer::Config.logger&.error e.message
|
@@ -31,9 +66,7 @@ module Glimmer
|
|
31
66
|
end
|
32
67
|
end
|
33
68
|
|
34
|
-
$LOAD_PATH.unshift(File.expand_path('..', __FILE__))
|
35
|
-
|
36
|
-
require 'glimmer/config'
|
37
69
|
require 'glimmer/error'
|
70
|
+
require 'glimmer/excluded_keyword_error'
|
38
71
|
require 'glimmer/invalid_keyword_error'
|
39
72
|
require 'glimmer/dsl/engine'
|
data/lib/glimmer/config.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module Glimmer
|
2
2
|
module Config
|
3
3
|
class << self
|
4
|
+
LOOP_MAX_COUNT_DEFAULT = 100
|
5
|
+
|
6
|
+
attr_writer :loop_max_count
|
7
|
+
|
8
|
+
def loop_max_count
|
9
|
+
@loop_max_count ||= LOOP_MAX_COUNT_DEFAULT
|
10
|
+
end
|
11
|
+
|
4
12
|
# Returns Glimmer logger (standard Ruby logger)
|
5
13
|
def logger
|
6
14
|
# unless defined? @@logger
|
data/lib/glimmer/dsl/engine.rb
CHANGED
@@ -11,6 +11,8 @@ module Glimmer
|
|
11
11
|
# When DSL engine interprets an expression, it attempts to handle
|
12
12
|
# with ordered expression array specified via `.expressions=` method.
|
13
13
|
class Engine
|
14
|
+
MESSAGE_NO_DSLS = "Glimmer has no DSLs configured. Add glimmer-dsl-swt gem or visit https://github.com/AndyObtiva/glimmer#multi-dsl-support for more details.\n"
|
15
|
+
|
14
16
|
class << self
|
15
17
|
def dsl=(dsl_name)
|
16
18
|
dsl_name = dsl_name&.to_sym
|
@@ -69,6 +71,16 @@ module Glimmer
|
|
69
71
|
# Static expressions indexed by keyword and dsl
|
70
72
|
def static_expressions
|
71
73
|
@static_expressions ||= {}
|
74
|
+
end
|
75
|
+
|
76
|
+
# Sets dynamic expression chains of responsibility. Useful for internal testing
|
77
|
+
def dynamic_expression_chains_of_responsibility=(chains)
|
78
|
+
@dynamic_expression_chains_of_responsibility = chains
|
79
|
+
end
|
80
|
+
|
81
|
+
# Sets static expressions. Useful for internal testing
|
82
|
+
def static_expressions=(expressions)
|
83
|
+
@static_expressions = expressions
|
72
84
|
end
|
73
85
|
|
74
86
|
# Sets an ordered array of DSL expressions to support
|
@@ -99,33 +111,37 @@ module Glimmer
|
|
99
111
|
static_expressions[keyword][static_expression_dsl] = static_expression
|
100
112
|
Glimmer.send(:define_method, keyword) do |*args, &block|
|
101
113
|
begin
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
114
|
+
if Glimmer::DSL::Engine.no_dsls?
|
115
|
+
puts Glimmer::DSL::Engine::MESSAGE_NO_DSLS
|
116
|
+
else
|
117
|
+
retrieved_static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
|
118
|
+
static_expression_dsl = (Glimmer::DSL::Engine.static_expressions[keyword].keys - Glimmer::DSL::Engine.disabled_dsls).first if retrieved_static_expression.nil?
|
119
|
+
interpretation = nil
|
120
|
+
if retrieved_static_expression.nil? && Glimmer::DSL::Engine.dsl && (static_expression_dsl.nil? || !Glimmer::DSL::Engine.static_expressions[keyword][static_expression_dsl].is_a?(TopLevelExpression))
|
121
|
+
begin
|
122
|
+
interpretation = Glimmer::DSL::Engine.interpret(keyword, *args, &block)
|
123
|
+
rescue => e
|
124
|
+
Glimmer::DSL::Engine.reset
|
125
|
+
raise e if static_expression_dsl.nil? || !Glimmer::DSL::Engine.static_expressions[keyword][static_expression_dsl].is_a?(TopLevelExpression)
|
126
|
+
end
|
111
127
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
128
|
+
if interpretation
|
129
|
+
interpretation
|
130
|
+
else
|
131
|
+
raise Glimmer::Error, "Unsupported keyword: #{keyword}" unless static_expression_dsl || retrieved_static_expression
|
132
|
+
Glimmer::DSL::Engine.dsl_stack.push(static_expression_dsl || Glimmer::DSL::Engine.dsl)
|
133
|
+
static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
|
134
|
+
if !static_expression.can_interpret?(Glimmer::DSL::Engine.parent, keyword, *args, &block)
|
135
|
+
raise Error, "Invalid use of Glimmer keyword #{keyword} with args #{args} under parent #{Glimmer::DSL::Engine.parent}"
|
136
|
+
else
|
137
|
+
Glimmer::Config.logger&.debug "#{static_expression.class.name} will handle expression keyword #{keyword}"
|
138
|
+
static_expression.interpret(Glimmer::DSL::Engine.parent, keyword, *args, &block).tap do |ui_object|
|
139
|
+
Glimmer::DSL::Engine.add_content(ui_object, static_expression, &block) unless block.nil?
|
140
|
+
Glimmer::DSL::Engine.dsl_stack.pop
|
141
|
+
end
|
126
142
|
end
|
127
143
|
end
|
128
|
-
end
|
144
|
+
end
|
129
145
|
rescue StandardError => e
|
130
146
|
# Glimmer::DSL::Engine.dsl_stack.pop
|
131
147
|
Glimmer::DSL::Engine.reset
|
@@ -145,7 +161,7 @@ module Glimmer
|
|
145
161
|
# Interprets Glimmer dynamic DSL expression consisting of keyword, args, and block (e.g. shell(:no_resize) { ... })
|
146
162
|
def interpret(keyword, *args, &block)
|
147
163
|
if no_dsls?
|
148
|
-
puts
|
164
|
+
puts MESSAGE_NO_DSLS
|
149
165
|
return
|
150
166
|
end
|
151
167
|
keyword = keyword.to_s
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,6 +132,48 @@ dependencies:
|
|
132
132
|
- - "<"
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: 7.0.0
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
requirement: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - '='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 0.8.23
|
141
|
+
name: coveralls
|
142
|
+
type: :development
|
143
|
+
prerelease: false
|
144
|
+
version_requirements: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - '='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 0.8.23
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
requirement: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - "~>"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 0.16.1
|
155
|
+
name: simplecov
|
156
|
+
type: :development
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - "~>"
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 0.16.1
|
163
|
+
- !ruby/object:Gem::Dependency
|
164
|
+
requirement: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - "~>"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 0.7.0
|
169
|
+
name: simplecov-lcov
|
170
|
+
type: :development
|
171
|
+
prerelease: false
|
172
|
+
version_requirements: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - "~>"
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: 0.7.0
|
135
177
|
description: Ruby Desktop Development GUI Library (JRuby on SWT)
|
136
178
|
email: andy.am@gmail.com
|
137
179
|
executables: []
|
@@ -157,6 +199,7 @@ files:
|
|
157
199
|
- lib/glimmer/dsl/static_expression.rb
|
158
200
|
- lib/glimmer/dsl/top_level_expression.rb
|
159
201
|
- lib/glimmer/error.rb
|
202
|
+
- lib/glimmer/excluded_keyword_error.rb
|
160
203
|
- lib/glimmer/invalid_keyword_error.rb
|
161
204
|
homepage: http://github.com/AndyObtiva/glimmer
|
162
205
|
licenses:
|