glimmer 2.4.0 → 2.4.1

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: f6a8921b091e770dd1acb0528bdf8dad0a63e79290ffb457325abf261b4ac8ca
4
- data.tar.gz: 4d530d648577640a25943fb55f61918d352f30e2007f7426b739b877cd6a44a0
3
+ metadata.gz: 374a048642d7ade3614c400b3ffefa627d3c40ca6976acf1a7969592865ecef8
4
+ data.tar.gz: 5653e8de7ff5ebe9258d872cb72a4067118217e06e698615c9276b95016fb233
5
5
  SHA512:
6
- metadata.gz: 68f5e3c05e2381a6f4855cec0832cc983fc74d0dcf27649efaf9e92dd8cf7aa69f9e171494ee1ab17a6a8d68ce0d71cb9ef61521290d999eaa70ad3915b989f2
7
- data.tar.gz: 6b3af9b3d411bed16cc9c9f2f227394675fd255098d64729424e31dfdbf1b7e75d8e3aac102016f31c8b729978e33b44fbca1b0dbecec1d1acffea3651dbc468
6
+ metadata.gz: 723e1b9231125f0d3f6507f5312b8a4a12c7bb7e4e3af35cf1f682da317c3a6374d814d0a28e5c2cd37d48255dc3cd7f8e70072b4c0f30bba751ce6730566f45
7
+ data.tar.gz: 2449d3783dc09bd4154c62df7ae1d954b0c8c411c98276bfa8ceb4f9d4ac0d1504618614fa33d88afa33b056ba1f04ce8b57050b526aa31ecac36b8954507461
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  Related Change Logs:
4
4
  - [glimmer-dsl-swt/CHANGELOG.md](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/CHANGELOG.md)
5
5
 
6
+ ### 2.4.1
7
+
8
+ - Support `recursive: [integer]` option for ObservableArray#add_observer for finite recursion
9
+
6
10
  ### 2.4.0
7
11
 
8
12
  - Support passing arbitrary options to `Observer` `#observe` (`#register`) method (not just properties, like `recursive: true` for example)
data/README.md CHANGED
@@ -16,7 +16,7 @@ Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) an
16
16
 
17
17
  [**Glimmer**](https://rubygems.org/gems/glimmer) is a DSL (Domain-Specific Language) Framework that consists of two things:
18
18
  - [DSL Engine](#dsl-engine): enables building internal DSLs embedded in Ruby (e.g. for GUI, XML, or CSS).
19
- - [Data-Binding Library](#data-binding-library): enables synchronizing GUI with Model Attributes bidirectionally **(now with Shine syntax support in v2)**.
19
+ - [Data-Binding Library](#data-binding-library): enables synchronizing GUI with Model Attributes bidirectionally **(now with [Shine](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax support in v2)**.
20
20
 
21
21
  [**Glimmer**](https://rubygems.org/gems/glimmer) is ***the cream of the crop*** when it comes to building DSLs in Ruby:
22
22
  - Supports building the tersest most concise domain specific language syntax in Ruby.
@@ -32,10 +32,10 @@ Start by checking out Glimmer's original GUI DSL, which got extracted into its o
32
32
  [**Glimmer**](https://rubygems.org/gems/glimmer) supports the following DSLs:
33
33
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
34
34
  - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)
35
- - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
36
- - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS
37
35
  - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
38
36
  - [glimmer-dsl-libui](https://github.com/AndyObtiva/glimmer-dsl-libui): Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)
37
+ - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
38
+ - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS
39
39
 
40
40
  ## Table of Contents
41
41
 
@@ -47,10 +47,10 @@ Start by checking out Glimmer's original GUI DSL, which got extracted into its o
47
47
  - [Official DSLs](#official-dsls)
48
48
  - [Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)](#glimmer-dsl-for-swt-jruby-desktop-development-gui-framework)
49
49
  - [Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)](#glimmer-dsl-for-opal-pure-ruby-web-gui-and-auto-webifier-of-desktop-apps)
50
- - [Glimmer DSL for XML (& HTML)](#glimmer-dsl-for-xml--html)
51
- - [Glimmer DSL for CSS](#glimmer-dsl-for-css)
52
50
  - [Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)](#glimmer-dsl-for-tk-mri-ruby-desktop-development-gui-library)
53
51
  - [Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)](#glimmer-dsl-for-libui-prerequisite-free-ruby-desktop-development-gui-library)
52
+ - [Glimmer DSL for XML (& HTML)](#glimmer-dsl-for-xml--html)
53
+ - [Glimmer DSL for CSS](#glimmer-dsl-for-css)
54
54
  - [Data-Binding Library](#data-binding-library)
55
55
  - [Glimmer Process](#glimmer-process)
56
56
  - [Resources](#resources)
@@ -71,13 +71,32 @@ Glimmer is fundamentally a DSL Engine that can support any number of DSLs like t
71
71
  Glimmer DSL syntax consists mainly of:
72
72
  - **keywords** (e.g. `table` for a table widget)
73
73
  - **style/args** (e.g. :multi as in `table(:multi)` for a multi-line selection table widget)
74
- - **content** (e.g. `{ table_column { text 'Name'} }` as in `table(:multi) { table_column { text 'Name'} }` for a multi-line selection table widget with a table column having header text property `'Name'` as content)
74
+ - **content (nested attributes/keywords)** (e.g. `{ table_column { text 'Name'} }` as in `table(:multi) { table_column { text 'Name'} }` for a multi-line selection table widget with a table column having header text property `'Name'` as content)
75
+
76
+ Here is a Hello, World! example from [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt):
77
+
78
+ ```ruby
79
+ include Glimmer
80
+
81
+ shell(:no_resize) { # keyword + style arg
82
+ text "Glimmer" # attribute content
83
+
84
+ label { # keyword content
85
+ text "Hello, World!" # attribute content
86
+ }
87
+ }.open
88
+ ```
89
+
90
+ That code renders the following GUI (Graphical User Interface):
91
+
92
+ ![Hello World](images/glimmer-hello-world.png)
75
93
 
76
94
  The Glimmer DSL Engine's architecture is based on the following Design Patterns and Data Structures:
77
95
  - **Interpreter Design Pattern**: to define interpretable expressions of DSL keywords
78
96
  - **Chain of Responsibility Design Pattern / Queue Data Structure**: to chain expression handlers in order of importance for processing DSL keywords
79
97
  - **Adapter Design Pattern**: to adapt expressions into handlers in a chain of responsibility
80
98
  - **Stack Data Structure**: to handle processing parent/child nesting of DSL keyword expressions in the correct order
99
+ - **Proxy Design Pattern**: to shield consumers of GUI libraries built with Glimmer from low-level GUI widget details
81
100
 
82
101
  Glimmer's use of the **Interpreter Design Pattern** in processing DSLs is also known as the **Virtual Machine Architectural Style**. After all, DSL expressions are virtual machine opcodes that process nested keywords stored in a stack. I built Glimmer's original DSL back in 2007 without knowing the **Virtual Machine Architectural Style** (except perhaps as an esoteric technology powering Java), but stumbled upon it anyways through following the Gang of Four Design Patterns mentioned above, chiefly the **Interpreter Design Pattern**.
83
102
 
@@ -210,7 +229,7 @@ end
210
229
  ### Setup
211
230
 
212
231
  Follow these steps to author a [Glimmer](https://rubygems.org/gems/glimmer) DSL:
213
- - Add `gem 'glimmer', '~> 2.4.0'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.4.0` and add `require 'glimmer'`
232
+ - Add `gem 'glimmer', '~> 2.4.1'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.4.1` and add `require 'glimmer'`
214
233
  - Create `glimmer/dsl/[dsl_name]/dsl.rb`, which requires and adds all dynamic expressions for the [dsl_name] Glimmer DSL module as per the code shown in the previous section (or [Official DSLs](#official-dsls) as examples)
215
234
  - Create `glimmer/dsl/[dsl_name]/[expresion_name]_expresion.rb` for every [expresion_name] expression needed, whether dynamic or static
216
235
 
@@ -734,83 +753,6 @@ You should see "Apple Calculator Theme"
734
753
 
735
754
  [![Glimmer Calculator Opal Apple Calculator Theme](https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-calculator/master/glimmer-cs-calculator-screenshot-opal-apple.png)](http://glimmer-cs-calculator-server.herokuapp.com/welcomes/apple)
736
755
 
737
- #### Glimmer DSL for XML (& HTML)
738
-
739
- [Glimmer DSL for XML](https://github.com/AndyObtiva/glimmer-dsl-xml) provides Ruby syntax for building XML (eXtensible Markup Language) documents.
740
-
741
- Within the context of desktop development, Glimmer DSL for XML is useful in providing XML data for the [SWT Browser widget](https://github.com/AndyObtiva/glimmer/tree/master#browser-widget).
742
-
743
- ##### XML DSL
744
-
745
- Simply start with `html` keyword and add HTML inside its block using Glimmer DSL syntax.
746
- Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted HTML output.
747
-
748
- Here are all the Glimmer XML DSL top-level keywords:
749
- - `html`
750
- - `tag`: enables custom tag creation for exceptional cases by passing tag name as '_name' attribute
751
- - `name_space`: enables namespacing html tags
752
-
753
- Element properties are typically passed as a key/value hash (e.g. `section(id: 'main', class: 'accordion')`) . However, for properties like "selected" or "checked", you must leave value `nil` or otherwise pass in front of the hash (e.g. `input(:checked, type: 'checkbox')` )
754
-
755
- Example (basic HTML):
756
-
757
- ```ruby
758
- @xml = html {
759
- head {
760
- meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
761
- }
762
- body {
763
- h1 { "Hello, World!" }
764
- }
765
- }
766
- puts @xml
767
- ```
768
-
769
- Output:
770
-
771
- ```
772
- <html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>
773
- ```
774
-
775
- #### Glimmer DSL for CSS
776
-
777
- [Glimmer DSL for CSS](https://github.com/AndyObtiva/glimmer-dsl-css) provides Ruby syntax for building CSS (Cascading Style Sheets).
778
-
779
- Within the context of [Glimmer](https://github.com/AndyObtiva/glimmer) app development, Glimmer DSL for CSS is useful in providing CSS for the [SWT Browser widget](https://github.com/AndyObtiva/glimmer/tree/master#browser-widget).
780
-
781
- ##### CSS DSL
782
-
783
- Simply start with `css` keyword and add stylesheet rule sets inside its block using Glimmer DSL syntax.
784
- Once done, you may call `to_s` or `to_css` to get the formatted CSS output.
785
-
786
- `css` is the only top-level keyword in the Glimmer CSS DSL
787
-
788
- Selectors may be specified by `s` keyword or HTML element keyword directly (e.g. `body`)
789
- Rule property values may be specified by `pv` keyword or underscored property name directly (e.g. `font_size`)
790
-
791
- Example:
792
-
793
- ```ruby
794
- @css = css {
795
- body {
796
- font_size '1.1em'
797
- pv 'background', 'white'
798
- }
799
-
800
- s('body > h1') {
801
- background_color :red
802
- pv 'font-size', '2em'
803
- }
804
- }
805
- puts @css
806
- ```
807
-
808
- Output:
809
-
810
- ```
811
- body{font-size:1.1em;background:white}body > h1{background-color:red;font-size:2em}
812
- ```
813
-
814
756
  #### Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
815
757
 
816
758
  [Tcl/Tk](https://www.tcl.tk/) has evolved into a practical desktop GUI toolkit due to gaining truely native looking widgets on Mac, Windows, and Linux in [Tk version 8.5](https://www.tcl.tk/software/tcltk/8.5.html#:~:text=Highlights%20of%20Tk%208.5&text=Font%20rendering%3A%20Now%20uses%20anti,and%20window%20layout%2C%20and%20more.).
@@ -893,28 +835,51 @@ Glimmer app:
893
835
  ![glimmer dsl tk screenshot sample hello notebook English](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-tk/master/images/glimmer-dsl-tk-screenshot-sample-hello-notebook-english.png)
894
836
  ![glimmer dsl tk screenshot sample hello notebook French](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-tk/master/images/glimmer-dsl-tk-screenshot-sample-hello-notebook-french.png)
895
837
 
896
- ###### Hello, Combo!
838
+ ###### Hello, Combobox!
897
839
 
898
- Glimmer code (from [samples/hello/hello_combo.rb](https://github.com/AndyObtiva/glimmer-dsl-tk/blob/master/samples/hello/hello_combo.rb)):
840
+ Glimmer code (from [samples/hello/hello_combobox.rb](https://github.com/AndyObtiva/glimmer-dsl-tk/blob/master/samples/hello/hello_combobox.rb)):
899
841
 
900
842
  ```ruby
901
- # ... more code precedes
902
- root {
903
- title 'Hello, Combobox!'
904
-
905
- combobox { |proxy|
906
- state 'readonly'
907
- text bind(person, :country)
908
- }
843
+ require 'glimmer-dsl-tk'
844
+
845
+ class Person
846
+ attr_accessor :country, :country_options
847
+
848
+ def initialize
849
+ self.country_options=["", "Canada", "US", "Mexico"]
850
+ self.country = "Canada"
851
+ end
852
+
853
+ def reset_country
854
+ self.country = "Canada"
855
+ end
856
+ end
857
+
858
+ class HelloCombobox
859
+ include Glimmer
909
860
 
910
- button { |proxy|
911
- text "Reset Selection"
912
- command {
913
- person.reset_country
914
- }
915
- }
916
- }.open
917
- # ... more code follows
861
+ def launch
862
+ person = Person.new
863
+
864
+ root {
865
+ title 'Hello, Combobox!'
866
+
867
+ combobox {
868
+ readonly true # this applies to text editing only (item selection still triggers a write to model)
869
+ text <=> [person, :country]
870
+ }
871
+
872
+ button {
873
+ text "Reset Selection"
874
+ command {
875
+ person.reset_country
876
+ }
877
+ }
878
+ }.open
879
+ end
880
+ end
881
+
882
+ HelloCombobox.new.launch
918
883
  ```
919
884
 
920
885
  Run (with the [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed):
@@ -925,8 +890,8 @@ ruby -r glimmer-dsl-tk -e "require '../samples/hello/hello_combobox.rb'"
925
890
 
926
891
  Glimmer app:
927
892
 
928
- ![glimmer dsl tk screenshot sample hello combo](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-tk/master/images/glimmer-dsl-tk-screenshot-sample-hello-combobox.png)
929
- ![glimmer dsl tk screenshot sample hello combo dropdown](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-tk/master/images/glimmer-dsl-tk-screenshot-sample-hello-combobox-dropdown.png)
893
+ ![glimmer dsl tk screenshot sample hello combobox](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-tk/master/images/glimmer-dsl-tk-screenshot-sample-hello-combobox.png)
894
+ ![glimmer dsl tk screenshot sample hello combobox dropdown](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-tk/master/images/glimmer-dsl-tk-screenshot-sample-hello-combobox-dropdown.png)
930
895
 
931
896
  #### Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)
932
897
 
@@ -961,39 +926,13 @@ Mac
961
926
 
962
927
  ![glimmer-dsl-libui-mac-basic-window.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-mac-basic-window.png)
963
928
 
964
- Linux
965
-
966
- ![glimmer-dsl-libui-linux-basic-window.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-linux-basic-window.png)
967
-
968
- ###### Basic Button
969
-
970
- ```ruby
971
- require 'glimmer-dsl-libui'
972
-
973
- include Glimmer
929
+ Windows
974
930
 
975
- window('hello world', 300, 200) {
976
- button('Button') {
977
- on_clicked do
978
- msg_box('Information', 'You clicked the button')
979
- end
980
- }
981
-
982
- on_closing do
983
- puts 'Bye Bye'
984
- end
985
- }.show
986
- ```
987
-
988
- Mac
989
-
990
- ![glimmer-dsl-libui-mac-basic-button.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-mac-basic-button.png)
991
- ![glimmer-dsl-libui-mac-basic-button-msg-box.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-mac-basic-button-msg-box.png)
931
+ ![glimmer-dsl-libui-windows-basic-window.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-windows-basic-window.png)
992
932
 
993
933
  Linux
994
934
 
995
- ![glimmer-dsl-libui-linux-basic-button.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-linux-basic-button.png)
996
- ![glimmer-dsl-libui-linux-basic-button-msg-box.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-linux-basic-button-msg-box.png)
935
+ ![glimmer-dsl-libui-linux-basic-window.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-linux-basic-window.png)
997
936
 
998
937
  ###### Basic Table Progress Bar
999
938
 
@@ -1036,6 +975,10 @@ Mac
1036
975
 
1037
976
  ![glimmer-dsl-libui-mac-basic-table-progress-bar.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-mac-basic-table-progress-bar.png)
1038
977
 
978
+ Windows
979
+
980
+ ![glimmer-dsl-libui-windows-basic-table-progress-bar.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-windows-basic-table-progress-bar.png)
981
+
1039
982
  Linux
1040
983
 
1041
984
  ![glimmer-dsl-libui-linux-basic-table-progress-bar.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-linux-basic-table-progress-bar.png)
@@ -1147,10 +1090,91 @@ Mac
1147
1090
 
1148
1091
  ![glimmer-dsl-libui-mac-area-gallery.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-mac-area-gallery.png)
1149
1092
 
1093
+ Windows
1094
+
1095
+ ![glimmer-dsl-libui-windows-area-gallery.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-windows-area-gallery.png)
1096
+
1150
1097
  Linux
1151
1098
 
1152
1099
  ![glimmer-dsl-libui-linux-area-gallery.png](https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/images/glimmer-dsl-libui-linux-area-gallery.png)
1153
1100
 
1101
+ #### Glimmer DSL for XML (& HTML)
1102
+
1103
+ [Glimmer DSL for XML](https://github.com/AndyObtiva/glimmer-dsl-xml) provides Ruby syntax for building XML (eXtensible Markup Language) documents.
1104
+
1105
+ Within the context of desktop development, Glimmer DSL for XML is useful in providing XML data for the [SWT Browser widget](https://github.com/AndyObtiva/glimmer/tree/master#browser-widget).
1106
+
1107
+ ##### XML DSL
1108
+
1109
+ Simply start with `html` keyword and add HTML inside its block using Glimmer DSL syntax.
1110
+ Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted HTML output.
1111
+
1112
+ Here are all the Glimmer XML DSL top-level keywords:
1113
+ - `html`
1114
+ - `tag`: enables custom tag creation for exceptional cases by passing tag name as '_name' attribute
1115
+ - `name_space`: enables namespacing html tags
1116
+
1117
+ Element properties are typically passed as a key/value hash (e.g. `section(id: 'main', class: 'accordion')`) . However, for properties like "selected" or "checked", you must leave value `nil` or otherwise pass in front of the hash (e.g. `input(:checked, type: 'checkbox')` )
1118
+
1119
+ Example (basic HTML):
1120
+
1121
+ ```ruby
1122
+ @xml = html {
1123
+ head {
1124
+ meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
1125
+ }
1126
+ body {
1127
+ h1 { "Hello, World!" }
1128
+ }
1129
+ }
1130
+ puts @xml
1131
+ ```
1132
+
1133
+ Output:
1134
+
1135
+ ```
1136
+ <html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>
1137
+ ```
1138
+
1139
+ #### Glimmer DSL for CSS
1140
+
1141
+ [Glimmer DSL for CSS](https://github.com/AndyObtiva/glimmer-dsl-css) provides Ruby syntax for building CSS (Cascading Style Sheets).
1142
+
1143
+ Within the context of [Glimmer](https://github.com/AndyObtiva/glimmer) app development, Glimmer DSL for CSS is useful in providing CSS for the [SWT Browser widget](https://github.com/AndyObtiva/glimmer/tree/master#browser-widget).
1144
+
1145
+ ##### CSS DSL
1146
+
1147
+ Simply start with `css` keyword and add stylesheet rule sets inside its block using Glimmer DSL syntax.
1148
+ Once done, you may call `to_s` or `to_css` to get the formatted CSS output.
1149
+
1150
+ `css` is the only top-level keyword in the Glimmer CSS DSL
1151
+
1152
+ Selectors may be specified by `s` keyword or HTML element keyword directly (e.g. `body`)
1153
+ Rule property values may be specified by `pv` keyword or underscored property name directly (e.g. `font_size`)
1154
+
1155
+ Example:
1156
+
1157
+ ```ruby
1158
+ @css = css {
1159
+ body {
1160
+ font_size '1.1em'
1161
+ pv 'background', 'white'
1162
+ }
1163
+
1164
+ s('body > h1') {
1165
+ background_color :red
1166
+ pv 'font-size', '2em'
1167
+ }
1168
+ }
1169
+ puts @css
1170
+ ```
1171
+
1172
+ Output:
1173
+
1174
+ ```
1175
+ body{font-size:1.1em;background:white}body > h1{background-color:red;font-size:2em}
1176
+ ```
1177
+
1154
1178
  ## Data-Binding Library
1155
1179
 
1156
1180
  Data-Binding enables mapping GUI properties (like text and color) to Model attributes (like name and age) for bidirectional or unidirectional synchronization and conversion as needed.
@@ -1163,12 +1187,76 @@ These are the main classes concerning data-binding:
1163
1187
  - `Glimmer::DataBinding::Observer`: Provides general observer support including unique registration and deregistration for cleanup and prevention of memory leaks. Main methods concerned are: `call`, `register` (alias: `observe`), and `unregister` (alias: `unobserve` or `deregister`)
1164
1188
  - `Glimmer::DataBinding::Observable`: General super-module for all observables. Main methods concerned are: `add_observer` and `remove_observer`
1165
1189
  - `Glimmer::DataBinding::ObservableModel`: Mixin module for any observable model with observable attributes. In addition to `Observable` methods, it has a `notify_observers` method to be called when changes occur. It automatically enhances all attribute setters (ending with `=`) to notify observers on changes. Also, it automatically handles observing array attributes using `ObservableArray` appropriately so they would notify observers upon array mutation changes.
1166
- - `Glimmer::DataBinding::ObservableArray`: Mixin module for any observable array collection that automatically handles notifying observers upon performing array mutation operations (e.g. `push`, `select!`, or `delete`) recursively (meaning if an array contained arrays and they changed, observers are notified). Accepts `recursive: true` option in `add_observer` method to recursively observe nested arrays all the way down.
1190
+ - `Glimmer::DataBinding::ObservableArray`: Mixin module for any observable array collection that automatically handles notifying observers upon performing array mutation operations (e.g. `push`, `select!`, or `delete`) recursively (meaning if an array contained arrays and they changed, observers are notified). Accepts `recursive: true` option in `add_observer` method to recursively observe nested arrays all the way down. Alternatively, pass `recursive: [integer]` to limit recursion in `Array` observation to a specific number of levels beyond the first level (which is always included).
1167
1191
  - `Glimmer::DataBinding::ObservableHash`: Mixin module for any observable hash that automatically handles notifying observers upon performing hash mutation operations (e.g. `hash[key]=value`, `select!`, `merge!`)
1168
1192
  - `Glimmer::DataBinding::ModelBinding`: a higher-level abstraction that relies on all the other observer/observable classes to support basic data-binding, nested data-binding, and computed data-binding
1169
1193
  - `Glimmer::DataBinding::Shine`: enables highly intuitive and visually expressive syntax to perform bidirectional (two-way) data-binding with `<=>` and unidirectional (one-way) data-binding with `<=`
1170
1194
 
1171
- You may learn more from [Data-Binding](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#data-binding) and [Observer](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#observer) usage in [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt)
1195
+ To do simple observation of models, arrays, or hashes, you can use the `Glimmer::DataBinding::Observer::proc` method, which builds an observer from a block. When invoking the `#observe` method on it, it automatically enhances the object argument being observed into an `Observable` (whether `ObservableModel`, `ObservableArray`, or `ObervableHash`).
1196
+
1197
+ Example of observing a model attribute:
1198
+
1199
+ ```ruby
1200
+ Glimmer::DataBinding::Observer.proc do |new_value|
1201
+ # Do some work with new value for model attribute
1202
+ end.observe(model, attribute)
1203
+ ```
1204
+
1205
+ Example of observing an array recursively (avoid recursion unless really needed since it fires on all fine-grained nested array changes):
1206
+
1207
+ ```ruby
1208
+ Glimmer::DataBinding::Observer.proc do |new_value|
1209
+ # Do some work with new array value
1210
+ end.observe(array, recursive: true)
1211
+ ```
1212
+
1213
+ Example of observing a hash key:
1214
+
1215
+ ```ruby
1216
+ Glimmer::DataBinding::Observer.proc do |new_value|
1217
+ # Do some work with new value for hash key
1218
+ end.observe(hash, :price)
1219
+ ```
1220
+
1221
+ Example of observing a hash for all key changes:
1222
+
1223
+ ```ruby
1224
+ Glimmer::DataBinding::Observer.proc do |new_value, changed_key|
1225
+ # Do some work with new value and changed key for hash
1226
+ end.observe(hash)
1227
+ ```
1228
+
1229
+ If you would like to observe nested model attribute changes and/or indexed array changes (specifying a nested array index/indices), you can use the more advanced `Glimmer::DataBinding::ModelBinding` class instead.
1230
+
1231
+ Example of observing nested model attributes:
1232
+
1233
+ ```ruby
1234
+ ModelBinding.new(model, "address1.street").add_observer do |new_address1_street_value|
1235
+ # Do some work with new address 1 street value
1236
+ end
1237
+ ```
1238
+
1239
+ Example of observing indexed array changes (combined with a nested model attribute):
1240
+
1241
+ ```ruby
1242
+ ModelBinding.new(model, "employees[5].name").add_observer do |new_employee_6_name|
1243
+ # Do some work with new employee 6 (index 5)'s name
1244
+ end
1245
+ ```
1246
+
1247
+ Example of observing double-indexed nested array changes:
1248
+
1249
+ ```ruby
1250
+ ModelBinding.new(model, "grid[5][7]").add_observer do |new_grid_cell_value|
1251
+ # Do some work with new grid cell value for row index 5 and column index 7
1252
+ end
1253
+ ```
1254
+
1255
+ Note that if an observed model attribute or hash key is an array, it is automatically observed for array changes, not just attribute/key-value changes.
1256
+
1257
+ All of the features above make Glimmer's data-binding library one of the most sophisticated and advanced in the industry since they automate everything instead of requiring endless manual configuration, thus resulting in some of the tersest most declarative syntax for using observers and data-binding.
1258
+
1259
+ You may learn more by looking into [data-binding specs](/Users/andy/code/glimmer/spec/lib/glimmer/data_binding) as well as [Data-Binding](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#data-binding) and [Observer](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#observer) usage in [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt)
1172
1260
 
1173
1261
  ## Glimmer Process
1174
1262
 
@@ -1221,8 +1309,9 @@ If you would like to contribute to Glimmer, please study up on Glimmer and [SWT]
1221
1309
 
1222
1310
  You may apply for contributing to any of these Glimmer DSL gems whether you prefer to focus on the desktop or web:
1223
1311
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
1224
- - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
1225
1312
  - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)
1313
+ - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
1314
+ - [glimmer-dsl-libui](https://github.com/AndyObtiva/glimmer-dsl-libui): Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)
1226
1315
  - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
1227
1316
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS
1228
1317
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.4.1
data/glimmer.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer 2.4.0 ruby lib
5
+ # stub: glimmer 2.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer".freeze
9
- s.version = "2.4.0"
9
+ s.version = "2.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["AndyMaleh".freeze]
14
- s.date = "2021-10-15"
14
+ s.date = "2021-11-01"
15
15
  s.description = "Glimmer is a Ruby DSL Framework for Ruby GUI and More, consisting of a DSL Engine and an Observable / Observer / Data-Binding Library (including Observable Model, Observable Array, and Observable Hash). Used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Tk (Ruby Desktop Development GUI Library), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library), Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -52,6 +52,10 @@ module Glimmer
52
52
  return observer if has_observer?(observer) && has_observer_element_properties?(observer, element_properties)
53
53
  property_observer_list << observer
54
54
  observer_element_properties[observer] = element_properties_for(observer) + Concurrent::Set.new(element_properties)
55
+ if !options.empty? && options[:recursive].is_a?(Integer)
56
+ options = options.clone
57
+ options[:recursive] = options[:recursive] - 1
58
+ end
55
59
  each { |element| add_element_observer(element, observer, options) }
56
60
  observer
57
61
  end
@@ -66,7 +70,9 @@ module Glimmer
66
70
  element_properties_for(observer).each do |property|
67
71
  observer.observe(element, property, options)
68
72
  end
69
- ensure_array_object_observer(element, options) if options[:recursive] && element.is_a?(Array)
73
+ if element.is_a?(Array) && (options[:recursive] == true || (options[:recursive].is_a?(Integer) && options[:recursive] >= 0))
74
+ ensure_array_object_observer(element, options)
75
+ end
70
76
  end
71
77
 
72
78
  def ensure_array_object_observer(object, options)
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: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-15 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: array_include_methods