glimmer-dsl-css 0.1.0 → 0.2.0

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: b8bc05a543f2281ad44c1073149fda8c8f947ebf4205d98cc106219e1477f14e
4
- data.tar.gz: e4f674a887a0c6d231a6ed6e259662de616eb3a6be770e20ddff30ca52946a00
3
+ metadata.gz: b4028d046f5729d4216c8de1d0138008b9d969a181172849fff9ffee2d889bf8
4
+ data.tar.gz: 8670ef828253b45b5a6afb6a1463b80db3d4156cd42aaafe36cbabefc9cc09a8
5
5
  SHA512:
6
- metadata.gz: 8c0aadaad6a38cabfea3b4e2d62aea9d429389b298c3b89187a5548ed50ad90a91a00dce46773edc9b93248561c55f2966bba19f2af3f2031b7eec14e777f04f
7
- data.tar.gz: ffe9a44219bca30c59fa961df2792792c3957e49118ea16da617fb026e843088b5ffa8c22f7cfded1a794a018c61b2fb082284bbe86c961bdf417edba71a2bf6
6
+ metadata.gz: 5c1a7e35b921f6a3e0459ee27ad813052f92261feb963d44a97b12834b9c7ee486ccae930593f70d0f59eca6991c1a7337a66af25bade8eb9b89f840d0484699
7
+ data.tar.gz: dfea2c013f10f30db0b8420fa2a87c626bb71e026a92fa9016ff88c7920f52ab1deabe243968200182974c8932bbd56daa1bf1417491d4c3e499c8b59980b44c
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 Andy Maleh
1
+ Copyright (c) 2020 - Andy Maleh
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
- # Glimmer DSL for CSS 0.1.0 Beta (Cascading Style Sheets)
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 CSS 0.2.0
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-css.svg)](http://badge.fury.io/rb/glimmer-dsl-css)
3
3
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-css.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-css)
4
+ [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-css/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-css?branch=master)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c7365cdb8556be433115/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-css/maintainability)
6
+ [![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
7
 
5
8
  [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for CSS provides Ruby syntax for building CSS (Cascading Style Sheets).
6
9
 
7
- Within the context of desktop development, Glimmer DSL for CSS is useful in providing CSS for the [SWT Browser widget](https://github.com/AndyObtiva/glimmer/tree/master#browser-widget).
10
+ 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).
11
+
12
+ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
13
+ - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (Desktop GUI)
14
+ - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
15
+ - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
8
16
 
9
17
  ## Setup
10
18
 
@@ -14,20 +22,24 @@ Please follow these instructions to make the `glimmer` command available on your
14
22
 
15
23
  Run this command to install directly:
16
24
  ```
17
- jgem install glimmer-dsl-xml -v 0.1.0
25
+ jgem install glimmer-dsl-css -v 0.2.0
18
26
  ```
19
27
 
20
28
  `jgem` is JRuby's version of `gem` command.
21
29
  RVM allows running `gem` as an alias.
22
30
  Otherwise, you may also run `jruby -S gem install ...`
23
31
 
24
- Add `require 'glimmer-dsl-xml'` to your code after `require glimmer-dsl-swt` or `require glimmer-dsl-opal`
32
+ Add `require 'glimmer-dsl-css'` to your code.
33
+
34
+ When using with Glimmer DSL for SWT or Glimmer DSL for Opal, make sure it is added after `require glimmer-dsl-swt` and `require glimmer-dsl-opal` to give it a lower precedence than them when processed by the Glimmer DSL engine.
35
+
36
+ That's it! Requiring the gem activates the Glimmer CSS DSL automatically.
25
37
 
26
38
  ### Option 2: Bundler
27
39
 
28
- Add the following to `Gemfile` after `glimmer-dsl-swt` or `glimmer-dsl-opal`:
40
+ Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):
29
41
  ```
30
- gem 'glimmer-dsl-xml', '~> 0.1.0'
42
+ gem 'glimmer-dsl-css', '~> 0.2.0'
31
43
  ```
32
44
 
33
45
  And, then run:
@@ -35,7 +47,11 @@ And, then run:
35
47
  jruby -S bundle install
36
48
  ```
37
49
 
38
- That's it! Requiring the gem activates the Glimmer XML DSL automatically.
50
+ Require in your code via Bundler (e.g. `require 'bundler'; Bundler.require`) or add `require 'glimmer-dsl-css'` to your code.
51
+
52
+ When using with Glimmer DSL for SWT or Glimmer DSL for Opal, make sure it is loaded after `glimmer-dsl-swt` and `glimmer-dsl-opal` to give it a lower precedence than them when processed by the Glimmer DSL engine.
53
+
54
+ That's it! Requiring the gem activates the Glimmer CSS DSL automatically.
39
55
 
40
56
  ## CSS DSL
41
57
 
@@ -78,11 +94,9 @@ You may submit [issues](https://github.com/AndyObtiva/glimmer/issues) on [GitHub
78
94
 
79
95
  [Click here to submit an issue.](https://github.com/AndyObtiva/glimmer/issues)
80
96
 
81
- ### IRC Channel
97
+ ### Chat
82
98
 
83
- If you need live help, try the [#glimmer](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer) IRC channel on [irc.mibbit.net](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer). If no one was available, you may [leave a GitHub issue](https://github.com/AndyObtiva/glimmer/issues) to schedule a meetup on IRC.
84
-
85
- [Click here to connect to #glimmer IRC channel immediately via a web interface.](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer)
99
+ If you need live help, try to [![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)
86
100
 
87
101
  ## Feature Suggestions
88
102
 
@@ -101,11 +115,15 @@ These features have been suggested. You might see them in a future version of Gl
101
115
  ## Contributors
102
116
 
103
117
  * [Andy Maleh](https://github.com/AndyObtiva) (Founder)
104
- * [Dennis Theisen](https://github.com/Soleone) (Contributor)
105
118
 
106
- [Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer/graphs/contributors)
119
+ [Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-dsl-css/graphs/contributors)
107
120
 
108
121
  ## License
109
122
 
110
- Copyright (c) 2007-2020 Andy Maleh.
111
- See LICENSE.txt for further details.
123
+ [MIT](LICENSE.txt)
124
+
125
+ Copyright (c) 2020 - Andy Maleh.
126
+
127
+ --
128
+
129
+ [<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).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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-14 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
18
  version: 0.9.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
19
22
  name: glimmer
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.9.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
@@ -57,7 +63,7 @@ dependencies:
57
63
  requirements:
58
64
  - - "~>"
59
65
  - !ruby/object:Gem::Version
60
- version: 0.8.1
66
+ version: 0.8.2
61
67
  name: puts_debuggerer
62
68
  type: :development
63
69
  prerelease: false
@@ -65,7 +71,7 @@ dependencies:
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: 0.8.1
74
+ version: 0.8.2
69
75
  - !ruby/object:Gem::Dependency
70
76
  requirement: !ruby/object:Gem::Requirement
71
77
  requirements:
@@ -126,6 +132,48 @@ dependencies:
126
132
  - - "<"
127
133
  - !ruby/object:Gem::Version
128
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
129
177
  description: Glimmer DSL for CSS (Cascading Style Sheets)
130
178
  email: andy.am@gmail.com
131
179
  executables: []
@@ -138,7 +186,6 @@ files:
138
186
  - README.md
139
187
  - VERSION
140
188
  - lib/glimmer-dsl-css.rb
141
- - lib/glimmer/config.rb
142
189
  - lib/glimmer/css/rule.rb
143
190
  - lib/glimmer/css/style_sheet.rb
144
191
  - lib/glimmer/dsl/css/css_expression.rb
@@ -148,33 +195,6 @@ files:
148
195
  - lib/glimmer/dsl/css/pv_expression.rb
149
196
  - lib/glimmer/dsl/css/rule_expression.rb
150
197
  - lib/glimmer/dsl/css/s_expression.rb
151
- - lib/glimmer/dsl/engine.rb
152
- - lib/glimmer/dsl/expression.rb
153
- - lib/glimmer/dsl/expression_handler.rb
154
- - lib/glimmer/dsl/opal/dsl.rb
155
- - lib/glimmer/dsl/opal/label_expression.rb
156
- - lib/glimmer/dsl/opal/property_expression.rb
157
- - lib/glimmer/dsl/opal/shell_expression.rb
158
- - lib/glimmer/dsl/parent_expression.rb
159
- - lib/glimmer/dsl/static_expression.rb
160
- - lib/glimmer/dsl/top_level_expression.rb
161
- - lib/glimmer/dsl/xml/dsl.rb
162
- - lib/glimmer/dsl/xml/html_expression.rb
163
- - lib/glimmer/dsl/xml/meta_expression.rb
164
- - lib/glimmer/dsl/xml/name_space_expression.rb
165
- - lib/glimmer/dsl/xml/node_parent_expression.rb
166
- - lib/glimmer/dsl/xml/tag_expression.rb
167
- - lib/glimmer/dsl/xml/text_expression.rb
168
- - lib/glimmer/dsl/xml/xml_expression.rb
169
- - lib/glimmer/error.rb
170
- - lib/glimmer/invalid_keyword_error.rb
171
- - lib/glimmer/opal/label.rb
172
- - lib/glimmer/opal/shell.rb
173
- - lib/glimmer/xml/depth_first_search_iterator.rb
174
- - lib/glimmer/xml/name_space_visitor.rb
175
- - lib/glimmer/xml/node.rb
176
- - lib/glimmer/xml/node_visitor.rb
177
- - lib/glimmer/xml/xml_visitor.rb
178
198
  homepage: http://github.com/AndyObtiva/glimmer-dsl-css
179
199
  licenses:
180
200
  - MIT
@@ -1,22 +0,0 @@
1
- module Glimmer
2
- module Config
3
- class << self
4
- # Returns Glimmer logger (standard Ruby logger)
5
- def logger
6
- # unless defined? @@logger
7
- # @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
8
- # end
9
- @@logger if defined? @@logger
10
- end
11
-
12
- def enable_logging
13
- @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
14
- end
15
- end
16
- end
17
- end
18
-
19
- if ENV['GLIMMER_LOGGER_LEVEL']
20
- Glimmer::Config.enable_logging
21
- Glimmer::Config.logger.level = ENV['GLIMMER_LOGGER_LEVEL'].downcase
22
- end
@@ -1,193 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/expression_handler'
3
-
4
- module Glimmer
5
- module DSL
6
- # Glimmer DSL Engine
7
- #
8
- # Follows Interpreter and Chain of Responsibility Design Patterns
9
- #
10
- # When DSL engine interprets an expression, it attempts to handle
11
- # with ordered expression array specified via `.expressions=` method.
12
- class Engine
13
- class << self
14
- def dsl=(dsl_name)
15
- dsl_name = dsl_name&.to_sym
16
- if dsl_name
17
- dsl_stack.push(dsl_name)
18
- else
19
- dsl_stack.clear
20
- end
21
- end
22
-
23
- def dsl
24
- dsl_stack.last
25
- end
26
-
27
- def dsls
28
- static_expressions.values.map(&:keys).flatten.uniq
29
- end
30
-
31
- def disable_dsl(dsl_name)
32
- dsl_name = dsl_name.to_sym
33
- disabled_dsls << dsl_name
34
- end
35
-
36
- def enable_dsl(dsl_name)
37
- dsl_name = dsl_name.to_sym
38
- disabled_dsls.delete(dsl_name)
39
- end
40
-
41
- def disabled_dsls
42
- @disabled_dsls ||= []
43
- end
44
-
45
- def enabled_dsls=(dsl_names)
46
- dsls.each {|dsl_name| disable_dsl(dsl_name)}
47
- dsl_names.each {|dsl_name| enable_dsl(dsl_name)}
48
- end
49
-
50
- # Resets Glimmer's engine activity and configuration. Useful in rspec before or after blocks in tests.
51
- def reset
52
- parent_stacks.values.each do |a_parent_stack|
53
- a_parent_stack.clear
54
- end
55
- dsl_stack.clear
56
- disabled_dsls.clear
57
- end
58
-
59
- # Dynamic expression chains of responsibility indexed by dsl
60
- def dynamic_expression_chains_of_responsibility
61
- @dynamic_expression_chains_of_responsibility ||= {}
62
- end
63
-
64
- # Static expressions indexed by keyword and dsl
65
- def static_expressions
66
- @static_expressions ||= {}
67
- end
68
-
69
- # Sets an ordered array of DSL expressions to support
70
- #
71
- # Every expression has an underscored name corresponding to an upper
72
- # camelcase AbstractExpression subclass name in glimmer/dsl
73
- #
74
- # They are used in order following the Chain of Responsibility Design
75
- # Pattern when interpretting a DSL expression
76
- def add_dynamic_expressions(dsl_namespace, expression_names)
77
- dsl = dsl_namespace.name.split("::").last.downcase.to_sym
78
- dynamic_expression_chains_of_responsibility[dsl] = expression_names.reverse.map do |expression_name|
79
- expression_class(dsl_namespace, expression_name).new
80
- end.reduce(nil) do |last_expresion_handler, expression|
81
- Glimmer::Config.logger&.debug "Adding dynamic expression: #{expression.class.name}"
82
- expression_handler = ExpressionHandler.new(expression)
83
- expression_handler.next = last_expresion_handler if last_expresion_handler
84
- expression_handler
85
- end
86
- end
87
-
88
- def add_static_expression(static_expression)
89
- Glimmer::Config.logger&.debug "Adding static expression: #{static_expression.class.name}"
90
- keyword = static_expression.class.keyword
91
- static_expression_dsl = static_expression.class.dsl
92
- static_expressions[keyword] ||= {}
93
- static_expressions[keyword][static_expression_dsl] = static_expression
94
- Glimmer.send(:define_method, keyword) do |*args, &block|
95
- begin
96
- retrieved_static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
97
- static_expression_dsl = (Glimmer::DSL::Engine.static_expressions[keyword].keys - Glimmer::DSL::Engine.disabled_dsls).last if retrieved_static_expression.nil?
98
- interpretation = nil
99
- 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))
100
- begin
101
- interpretation = Glimmer::DSL::Engine.interpret(keyword, *args, &block)
102
- rescue => e
103
- Glimmer::DSL::Engine.reset
104
- raise e if static_expression_dsl.nil? || !Glimmer::DSL::Engine.static_expressions[keyword][static_expression_dsl].is_a?(TopLevelExpression)
105
- end
106
- end
107
- if interpretation
108
- interpretation
109
- else
110
- raise Glimmer::Error, "Unsupported keyword: #{keyword}" unless static_expression_dsl || retrieved_static_expression
111
- Glimmer::DSL::Engine.dsl_stack.push(static_expression_dsl || Glimmer::DSL::Engine.dsl)
112
- static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
113
- if !static_expression.can_interpret?(Glimmer::DSL::Engine.parent, keyword, *args, &block)
114
- raise Error, "Invalid use of Glimmer keyword #{keyword} with args #{args} under parent #{Glimmer::DSL::Engine.parent}"
115
- else
116
- Glimmer::Config.logger&.debug "#{static_expression.class.name} will handle expression keyword #{keyword}"
117
- static_expression.interpret(Glimmer::DSL::Engine.parent, keyword, *args, &block).tap do |ui_object|
118
- Glimmer::DSL::Engine.add_content(ui_object, static_expression, &block) unless block.nil?
119
- Glimmer::DSL::Engine.dsl_stack.pop
120
- end
121
- end
122
- end
123
- rescue StandardError => e
124
- # Glimmer::DSL::Engine.dsl_stack.pop
125
- Glimmer::DSL::Engine.reset
126
- raise e
127
- end
128
- end
129
- end
130
-
131
- def expression_class(dsl_namespace, expression_name)
132
- dsl_namespace.const_get(expression_class_name(expression_name).to_sym)
133
- end
134
-
135
- def expression_class_name(expression_name)
136
- "#{expression_name}_expression".camelcase(:upper)
137
- end
138
-
139
- # Interprets Glimmer dynamic DSL expression consisting of keyword, args, and block (e.g. shell(:no_resize) { ... })
140
- def interpret(keyword, *args, &block)
141
- keyword = keyword.to_s
142
- dynamic_expression_dsl = (dynamic_expression_chains_of_responsibility.keys - disabled_dsls).last if dsl.nil?
143
- dsl_stack.push(dynamic_expression_dsl || dsl)
144
- expression = dynamic_expression_chains_of_responsibility[dsl].handle(parent, keyword, *args, &block)
145
- expression.interpret(parent, keyword, *args, &block).tap do |ui_object|
146
- add_content(ui_object, expression, &block)
147
- dsl_stack.pop
148
- end
149
- rescue StandardError => e
150
- # dsl_stack.pop
151
- reset
152
- raise e
153
- end
154
-
155
- # Adds content block to parent UI object
156
- #
157
- # This allows evaluating parent UI object properties and children
158
- #
159
- # For example, a shell widget would get properties set and children added
160
- def add_content(parent, expression, &block)
161
- if block_given? && expression.is_a?(ParentExpression)
162
- dsl_stack.push(expression.class.dsl)
163
- parent_stack.push(parent)
164
- expression.add_content(parent, &block)
165
- parent_stack.pop
166
- dsl_stack.pop
167
- end
168
- end
169
-
170
- # Current parent while evaluating Glimmer DSL (nil if just started or done evaluatiing)
171
- #
172
- # Parents are maintained in a stack while evaluating Glimmer DSL
173
- # to ensure properly ordered interpretation of DSL syntax
174
- def parent
175
- parent_stack.last
176
- end
177
-
178
- def parent_stack
179
- parent_stacks[dsl] ||= []
180
- end
181
-
182
- def parent_stacks
183
- @parent_stacks ||= {}
184
- end
185
-
186
- # Enables multiple DSLs to play well with each other when mixing together
187
- def dsl_stack
188
- @dsl_stack ||= []
189
- end
190
- end
191
- end
192
- end
193
- end
@@ -1,42 +0,0 @@
1
- require 'glimmer/error'
2
-
3
- module Glimmer
4
- module DSL
5
- # Represents a Glimmer DSL expression (e.g. label(:center) { ... })
6
- #
7
- # An expression object can interpret a keyword, args, and a block into a UI object
8
- #
9
- # Expressions subclasses follow the convention of using `and` and `or`
10
- # english versino of Ruby's boolean operations. This allows easy DSL-like
11
- # readability of the rules, and easy tagging with pd when troubleshooting.
12
- class Expression
13
- class << self
14
- def dsl
15
- @dsl ||= name.split(/::/)[-2].downcase.to_sym
16
- end
17
- end
18
-
19
- # Checks if it can interpret parameters (subclass must override)
20
- def can_interpret?(parent, keyword, *args, &block)
21
- raise Error, "#can_interpret? must be implemented by an Expression subclass"
22
- end
23
-
24
- # Interprets parameters (subclass must override)
25
- def interpret(parent, keyword, *args, &block)
26
- raise Error, "#interpret must be implemented by an Expression subclass"
27
- end
28
-
29
- # Adds block content to specified parent UI object (Optional)
30
- #
31
- # Only expressions that receive a content block should implement
32
- def add_content(parent, &block)
33
- # No Op by default
34
- end
35
-
36
- # Checks if object is a Symbol or a String
37
- def textual?(object)
38
- object.is_a?(Symbol) or object.is_a?(String)
39
- end
40
- end
41
- end
42
- end
@@ -1,48 +0,0 @@
1
- require 'glimmer/invalid_keyword_error'
2
-
3
- module Glimmer
4
- module DSL
5
- # Expression handler for a Glimmer DSL specific expression
6
- #
7
- # Follows the Chain of Responsibility Design Pattern
8
- #
9
- # Handlers are configured in Glimmer::DSL in the right order
10
- # to attempt handling Glimmer DSL interpretation calls
11
- #
12
- # Each handler knows the next handler in the chain of responsibility.
13
- #
14
- # If it handles successfully, it returns. Otherwise, it forwards to the next
15
- # handler in the chain of responsibility
16
- class ExpressionHandler
17
- def initialize(expression)
18
- @expression = expression
19
- end
20
-
21
- # Handles interpretation of Glimmer DSL expression if expression supports it
22
- # If it succeeds, it returns the correct Glimmer DSL expression object
23
- # Otherwise, it forwards to the next handler configured via `#next=` method
24
- # If there is no handler next, then it raises an error
25
- def handle(parent, keyword, *args, &block)
26
- Glimmer::Config.logger&.debug "Attempting to handle #{keyword} with #{@expression.class.name.split(":").last}"
27
- if @expression.can_interpret?(parent, keyword, *args, &block)
28
- Glimmer::Config.logger&.debug "#{@expression.class.name} will handle expression keyword #{keyword}"
29
- return @expression
30
- elsif @next_expression_handler
31
- return @next_expression_handler.handle(parent, keyword, *args, &block)
32
- else
33
- # TODO see if we need a better response here (e.g. dev mode error raising vs production mode silent failure)
34
- message = "Glimmer keyword #{keyword} with args #{args} cannot be handled"
35
- message += " inside parent #{parent}" if parent
36
- message += "! Check the validity of the code."
37
- # Glimmer::Config.logger&.error message
38
- raise InvalidKeywordError, message
39
- end
40
- end
41
-
42
- # Sets the next handler in the expression handler chain of responsibility
43
- def next=(next_expression_handler)
44
- @next_expression_handler = next_expression_handler
45
- end
46
- end
47
- end
48
- end
@@ -1,41 +0,0 @@
1
- require 'opal'
2
- # require 'opal-jquery'
3
- require 'browser'
4
-
5
- class String
6
- def underscore
7
- gsub(/[A-Z]/) {|m| "_#{m.downcase}"}.sub(/^_/, '')
8
- end
9
-
10
- def camelcase(option=nil)
11
- new_string = split("_").map {|word| word[0].upcase + word[1..-1]}.join
12
- if option == :upper
13
- new_string
14
- else
15
- new_string.sub(/^./) {|c| c.downcase}
16
- end
17
- end
18
-
19
- # def titlecase
20
- # #TODO
21
- # end
22
- end
23
-
24
- require 'glimmer/dsl/engine'
25
- # Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f}
26
- require 'glimmer/dsl/opal/shell_expression'
27
- require 'glimmer/dsl/opal/label_expression'
28
- require 'glimmer/dsl/opal/property_expression'
29
-
30
- module Glimmer
31
- module DSL
32
- module Opal
33
- Engine.add_dynamic_expressions(
34
- Opal,
35
- %w[
36
- property
37
- ]
38
- )
39
- end
40
- end
41
- end
@@ -1,17 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/dsl/parent_expression'
3
- require 'glimmer/opal/label'
4
-
5
- module Glimmer
6
- module DSL
7
- module Opal
8
- class LabelExpression < StaticExpression
9
- include ParentExpression
10
-
11
- def interpret(parent, keyword, *args, &block)
12
- Glimmer::Opal::Label.new(parent, args)
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- require 'glimmer/dsl/expression'
2
-
3
- module Glimmer
4
- module DSL
5
- module Opal
6
- class PropertyExpression < StaticExpression
7
- include TopLevelExpression
8
-
9
- def can_interpret?(parent, keyword, *args, &block)
10
- keyword.to_s == 'text'
11
- end
12
-
13
- def interpret(parent, keyword, *args, &block)
14
- parent.text = args.first.to_s
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/dsl/top_level_expression'
3
- require 'glimmer/dsl/parent_expression'
4
- require 'glimmer/opal/shell'
5
-
6
- module Glimmer
7
- module DSL
8
- module Opal
9
- class ShellExpression < StaticExpression
10
- include TopLevelExpression
11
- include ParentExpression
12
-
13
- def interpret(parent, keyword, *args, &block)
14
- Glimmer::Opal::Shell.new(args)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,12 +0,0 @@
1
- require 'glimmer/error'
2
-
3
- module Glimmer
4
- module DSL
5
- # Mixin that represents expressions that always have a content block
6
- module ParentExpression
7
- def add_content(parent, &block)
8
- block.call(parent)
9
- end
10
- end
11
- end
12
- end
@@ -1,36 +0,0 @@
1
- require 'glimmer/error'
2
- require 'glimmer/dsl/engine'
3
- require 'glimmer/dsl/expression'
4
-
5
- module Glimmer
6
- module DSL
7
- # Represents a StaticExpression for expressions where
8
- # the keyword does not vary dynamically. These static keywords are then
9
- # predefined as methods in Glimmer instead of needing method_missing
10
- #
11
- # StaticExpression subclasses may optionally implement `#can_interpret?`
12
- # (not needed if it only checks for keyword)
13
- #
14
- # StaticExpression subclasses must define `#interpret`.
15
- #
16
- # The direct parent namespace of a StaticExpression subclass must match the DSL name (case-insensitive)
17
- # (e.g. Glimmer::DSL::SWT::WidgetExpression has a DSL of :swt)
18
- class StaticExpression < Expression
19
- class << self
20
- def inherited(base)
21
- Glimmer::DSL::Engine.add_static_expression(base.new)
22
- super
23
- end
24
-
25
- def keyword
26
- @keyword ||= name.split(/::/).last.sub(/Expression$/, '').underscore
27
- end
28
- end
29
-
30
- # Subclasses may optionally implement
31
- def can_interpret?(parent, keyword, *args, &block)
32
- true
33
- end
34
- end
35
- end
36
- end
@@ -1,7 +0,0 @@
1
- module Glimmer
2
- module DSL
3
- # Mixin that represents expressions that are always at the top with parent nil
4
- module TopLevelExpression
5
- end
6
- end
7
- end
@@ -1,23 +0,0 @@
1
- require 'glimmer/dsl/engine'
2
- # Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f} # cannot in Opal
3
- require 'glimmer/dsl/xml/text_expression'
4
- require 'glimmer/dsl/xml/tag_expression'
5
- require 'glimmer/dsl/xml/xml_expression'
6
- require 'glimmer/dsl/xml/html_expression'
7
- require 'glimmer/dsl/xml/meta_expression'
8
- require 'glimmer/dsl/xml/name_space_expression'
9
-
10
- module Glimmer
11
- module DSL
12
- module XML
13
- Engine.add_dynamic_expressions(
14
- XML,
15
- %w[
16
- text
17
- tag
18
- xml
19
- ]
20
- )
21
- end
22
- end
23
- end
@@ -1,25 +0,0 @@
1
- require 'glimmer/dsl/xml/node_parent_expression'
2
- require 'glimmer/dsl/xml/xml_expression'
3
- require 'glimmer/dsl/static_expression'
4
- require 'glimmer/dsl/top_level_expression'
5
-
6
- module Glimmer
7
- module DSL
8
- module XML
9
- # This static html expression flips the DSL switch on for
10
- # XML DSL in Glimmer
11
- class HtmlExpression < StaticExpression
12
- include TopLevelExpression
13
- include NodeParentExpression
14
-
15
- def interpret(parent, keyword, *args, &block)
16
- xml_expression.interpret(parent, keyword, *args, &block)
17
- end
18
-
19
- def xml_expression
20
- @xml_expression ||= XmlExpression.new
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,23 +0,0 @@
1
- require 'glimmer/dsl/xml/node_parent_expression'
2
- require 'glimmer/dsl/xml/xml_expression'
3
- require 'glimmer/dsl/static_expression'
4
-
5
- module Glimmer
6
- module DSL
7
- module XML
8
- # This static html expression flips the DSL switch on for
9
- # XML DSL in Glimmer
10
- class MetaExpression < StaticExpression
11
- include NodeParentExpression
12
-
13
- def interpret(parent, keyword, *args, &block)
14
- xml_expression.interpret(parent, keyword, *args, &block)
15
- end
16
-
17
- def xml_expression
18
- @xml_expression ||= XmlExpression.new
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,37 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/dsl/top_level_expression'
3
- require 'glimmer/xml/node'
4
- require 'glimmer/xml/depth_first_search_iterator'
5
- require 'glimmer/xml/name_space_visitor'
6
-
7
- module Glimmer
8
- module DSL
9
- module XML
10
- class NameSpaceExpression < StaticExpression
11
- include TopLevelExpression
12
-
13
- def can_interpret?(parent, keyword, *args, &block)
14
- (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
15
- (keyword.to_s == "name_space")
16
- (args.size == 1) and
17
- (args[0].is_a?(Symbol)) and
18
- block
19
- end
20
-
21
- def interpret(parent, keyword, *args, &block)
22
- node = block.call
23
- unless node.is_a?(String)
24
- name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(args[0].to_s)
25
- Glimmer::XML::DepthFirstSearchIterator.new(node, name_space_visitor).iterate
26
- def node.process_block(block)
27
- Glimmer::Config.logger&.debug 'block'
28
- #NOOP
29
- end
30
- end
31
- parent.children << node if parent and !parent.children.include?(node)
32
- node
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,33 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/parent_expression'
3
- require 'glimmer/xml/node'
4
-
5
- module Glimmer
6
- module DSL
7
- module XML
8
- module NodeParentExpression
9
- include ParentExpression
10
- include Glimmer
11
-
12
- def add_content(parent, &block)
13
- return_value = block.call(parent)
14
- if !return_value.is_a?(Glimmer::XML::Node) and !parent.children.include?(return_value)
15
- text = return_value.to_s
16
- first_match = text.match(/[#][^{]+[{][^}]+[}]/)
17
- match = first_match
18
- while (match)
19
- instance_eval(parent.text_command(match.pre_match))
20
- tag_text = match.to_s
21
- instance_eval(parent.rubyize(tag_text))
22
- text = tag_text
23
- post_match = match.post_match
24
- match = text.match(/[#]\w+[{]\w+[}]/)
25
- end
26
- instance_eval(parent.text_command(post_match)) if post_match
27
- parent.children << return_value unless first_match
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,29 +0,0 @@
1
- require 'glimmer/dsl/xml/node_parent_expression'
2
- require 'glimmer/dsl/xml/xml_expression'
3
- require 'glimmer/dsl/static_expression'
4
- require 'glimmer/dsl/top_level_expression'
5
- require 'glimmer/xml/node'
6
-
7
- module Glimmer
8
- module DSL
9
- module XML
10
- class TagExpression < StaticExpression
11
- include TopLevelExpression
12
- include NodeParentExpression
13
-
14
- def can_interpret?(parent, keyword, *args, &block)
15
- (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
16
- (keyword.to_s == "tag") and
17
- args[0].include?(:_name)
18
- end
19
-
20
- def interpret(parent, keyword, *args, &block)
21
- attributes = args[0] if (args.size == 1)
22
- tag_name = attributes[:_name]
23
- attributes.delete(:_name)
24
- Glimmer::XML::Node.new(parent, tag_name, attributes, &block)
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,22 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/xml/node'
3
-
4
- module Glimmer
5
- module DSL
6
- module XML
7
- class TextExpression < StaticExpression
8
- def can_interpret?(parent, keyword, *args, &block)
9
- (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
10
- (keyword.to_s == "text") and
11
- (args.size == 1) and
12
- !block
13
- end
14
-
15
- def interpret(parent, keyword, *args, &block)
16
- parent.children << args[0].to_s if parent
17
- args[0].to_s
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,21 +0,0 @@
1
- require 'glimmer/dsl/xml/node_parent_expression'
2
- require 'glimmer/dsl/expression'
3
- require 'glimmer/xml/node'
4
-
5
- module Glimmer
6
- module DSL
7
- module XML
8
- class XmlExpression < Expression
9
- include NodeParentExpression
10
-
11
- def can_interpret?(parent, keyword, *args, &block)
12
- parent.is_a?(Glimmer::XML::Node)
13
- end
14
-
15
- def interpret(parent, keyword, *args, &block)
16
- Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,6 +0,0 @@
1
- module Glimmer
2
- # Represents Glimmer errors that occur due to invalid use of Glimmer
3
- # without handing control flow back to original method_missing
4
- class Error < RuntimeError
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module Glimmer
2
- # Represents Glimmer errors that occur due to invalid use of Glimmer
3
- # without handing control flow back to original method_missing
4
- class InvalidKeywordError < RuntimeError
5
- end
6
- end
@@ -1,31 +0,0 @@
1
- module Glimmer
2
- module Opal
3
- class Label
4
- attr_reader :text
5
-
6
- def initialize(parent, args)
7
- @parent = parent
8
- @args = args
9
- @parent.add_child(self)
10
- end
11
-
12
- def text=(value)
13
- @text = value
14
- redraw
15
- end
16
-
17
- def redraw
18
- old_dom = @dom
19
- @dom = nil
20
- old_dom.replace dom
21
- end
22
-
23
- def dom
24
- label_text = @text
25
- @dom ||= DOM {
26
- label label_text
27
- }
28
- end
29
- end
30
- end
31
- end
@@ -1,34 +0,0 @@
1
- module Glimmer
2
- module Opal
3
- class Shell
4
- def initialize(args)
5
- @args = args
6
- @children = []
7
- $document.ready do
8
- $document.body.replace(dom)
9
- end
10
- end
11
-
12
- def text
13
- $document.title
14
- end
15
-
16
- def text=(value)
17
- $document.title = value
18
- end
19
-
20
- def add_child(child)
21
- return if @children.include?(child)
22
- @children << child
23
- dom << child.dom
24
- end
25
-
26
- def dom
27
- @dom ||= DOM {
28
- body {
29
- }
30
- }
31
- end
32
- end
33
- end
34
- end
@@ -1,22 +0,0 @@
1
- require 'glimmer/xml/node'
2
-
3
- module Glimmer
4
- module XML
5
- class DepthFirstSearchIterator
6
- def initialize(node, node_visitor)
7
- @node = node
8
- @node_visitor = node_visitor
9
- end
10
-
11
- def iterate
12
- process(@node)
13
- end
14
-
15
- def process(node)
16
- @node_visitor.process_before_children(node)
17
- node.children.each { |child| process(child) } if node.is_a?(Node)
18
- @node_visitor.process_after_children(node)
19
- end
20
- end
21
- end
22
- end
@@ -1,21 +0,0 @@
1
- require "glimmer/xml/node_visitor"
2
-
3
- module Glimmer
4
- module XML
5
- class NameSpaceVisitor < NodeVisitor
6
-
7
- def initialize(name_space_name)
8
- @name_space_name = name_space_name
9
- end
10
-
11
- def process_before_children(node)
12
- return if node.is_a?(String)
13
- node.name_space = Node.new(nil, @name_space_name, nil) if node and !node.name_space
14
- end
15
-
16
- def process_after_children(node)
17
- #NOOP
18
- end
19
- end
20
- end
21
- end
@@ -1,75 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/xml/depth_first_search_iterator'
3
- require 'glimmer/xml/xml_visitor'
4
-
5
- module Glimmer
6
- module XML
7
- class Node
8
- include Glimmer
9
-
10
- attr_accessor :children, :name, :contents, :attributes, :is_name_space, :is_attribute, :name_space, :parent
11
-
12
- def initialize(parent, name, attributes, &contents)
13
- @is_name_space = false
14
- @children = []
15
- @parent = parent
16
- if attributes.is_a?(Array)
17
- attributes = attributes.compact
18
- hash_attributes = attributes.last.is_a?(Hash) ? attributes.delete(attributes.last) : {}
19
- hash_attributes = attributes.reduce(hash_attributes) do |hash, attribute|
20
- hash.merge(attribute => nil)
21
- end
22
- attributes = hash_attributes
23
- end
24
- if (parent and parent.is_name_space)
25
- @name_space = parent
26
- @parent = @name_space.parent
27
- end
28
- @parent.children << self if @parent
29
- @name = name
30
- @contents = contents
31
- @attributes = attributes
32
- if @attributes
33
- @attributes.each_key do |attribute|
34
- if attribute.is_a?(Node)
35
- attribute.is_attribute = true
36
- attribute.parent.children.delete(attribute) if attribute.parent
37
- attribute.parent = nil #attributes do not usually have parents
38
- end
39
- end
40
- Glimmer::Config.logger&.debug(attributes)
41
- end
42
- end
43
-
44
- def method_missing(symbol, *args, &block)
45
- @is_name_space = true
46
- parent.children.delete(self) if parent
47
- Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::HtmlExpression.new) {@tag = super}
48
- @tag
49
- end
50
-
51
- def to_xml
52
- xml_visitor = XmlVisitor.new
53
- DepthFirstSearchIterator.new(self, xml_visitor).iterate
54
- xml_visitor.document
55
- end
56
- alias to_html to_xml
57
- alias to_s to_xml
58
-
59
- def text_command(text)
60
- "text \"#{text}\""
61
- end
62
-
63
- def rubyize(text)
64
- text = text.gsub(/[}]/, '"}')
65
- text = text.gsub(/[{]/, '{"')
66
- text = text.gsub(/[#]/, '')
67
- end
68
-
69
- #override Object default id method and route it to Glimmer engine
70
- def id
71
- method_missing(:id)
72
- end
73
- end
74
- end
75
- end
@@ -1,13 +0,0 @@
1
- module Glimmer
2
- module XML
3
- class NodeVisitor
4
- def process_before_children
5
- raise "must be implemented by a class"
6
- end
7
-
8
- def process_after_children
9
- raise "must be implemented by a class"
10
- end
11
- end
12
- end
13
- end
@@ -1,65 +0,0 @@
1
- require "glimmer/xml/node_visitor"
2
- require "glimmer/xml/node"
3
-
4
- module Glimmer
5
- module XML
6
- class XmlVisitor < NodeVisitor
7
-
8
- attr_reader :document
9
-
10
- def initialize
11
- @document = ""
12
- end
13
-
14
- def process_before_children(node)
15
- if (!node.is_a?(Glimmer::XML::Node))
16
- @document += node.to_s
17
- return
18
- end
19
- begin_open_tag(node)
20
- append_attributes(node) if node.attributes
21
- end_open_tag(node)
22
- end
23
-
24
- def process_after_children(node)
25
- return if (!node.is_a?(Glimmer::XML::Node))
26
- append_close_tag(node)
27
- end
28
-
29
- def begin_open_tag(node)
30
- @document += "<"
31
- @document += "#{node.name_space.name}:" if node.name_space
32
- @document += node.name
33
- end
34
-
35
- def end_open_tag(node)
36
- if (node.contents)
37
- @document += ">"
38
- else
39
- @document += " " if node.attributes.keys.size > 0
40
- @document += "/>"
41
- end
42
- end
43
-
44
- def append_close_tag(node)
45
- if (node.contents)
46
- @document += "</"
47
- @document += "#{node.name_space.name}:" if node.name_space
48
- @document += "#{node.name}>"
49
- end
50
- end
51
-
52
- def append_attributes(node)
53
- Glimmer::Config.logger&.debug "Take 3"
54
- Glimmer::Config.logger&.debug(node.attributes)
55
- node.attributes.each do |attribute, value|
56
- attribute_name = attribute
57
- attribute_name = "#{attribute.name_space.name}:#{attribute.name}" if attribute.is_a?(Node)
58
- @document += " #{attribute_name}"
59
- @document += "=\"#{value}\"" unless value.nil?
60
- end
61
- end
62
-
63
- end
64
- end
65
- end