glimmer-dsl-xml 0.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/CONTRIBUTING.md +60 -0
- data/README.md +83 -34
- data/VERSION +1 -1
- data/lib/glimmer/dsl/xml/dsl.rb +24 -3
- data/lib/glimmer/dsl/xml/html_expression.rb +23 -6
- data/lib/glimmer/dsl/xml/meta_expression.rb +21 -0
- data/lib/glimmer/dsl/xml/name_space_expression.rb +31 -3
- data/lib/glimmer/dsl/xml/node_parent_expression.rb +23 -2
- data/lib/glimmer/dsl/xml/tag_expression.rb +21 -0
- data/lib/glimmer/dsl/xml/text_expression.rb +21 -0
- data/lib/glimmer/dsl/xml/xml_expression.rb +25 -6
- data/lib/glimmer/dsl/xml/xml_node_expression.rb +42 -0
- data/lib/glimmer/xml/depth_first_search_iterator.rb +21 -0
- data/lib/glimmer/xml/html_node.rb +39 -0
- data/lib/glimmer/xml/html_visitor.rb +61 -0
- data/lib/glimmer/xml/name_space_visitor.rb +21 -0
- data/lib/glimmer/xml/node.rb +29 -4
- data/lib/glimmer/xml/node_visitor.rb +21 -0
- data/lib/glimmer/xml/xml_visitor.rb +26 -1
- data/lib/glimmer-dsl-xml.rb +24 -0
- metadata +39 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a41194ca7b9d1c4277916694742b0200f044d5535ce12a2299c564b4fc9fa26
|
4
|
+
data.tar.gz: 559c0fcfd9c7ba89ccf64bc260eac14d419e16267f40833851a78cdd3c3f5795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9788fbb50dc70495e1e27c7c027c9524635482bf403e0e0ae5ba626cf153697e4706aaf71cc29de68623678d0e202b8d02b513fa7707e987bd061af30d046647
|
7
|
+
data.tar.gz: ee1a657454c1b14a956b5e5aa3e7e909f96e643015fdc849add4b79f21e551fd906c0f1e9fb7baad51f20ff7e3f40b12ced59b6a4529d409d1b18d21d1a889e9
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 1.2.1
|
4
|
+
|
5
|
+
- Get rid of `invalid log level:` output by setting `GLIMMER_LOGGER_LEVEL` env var before requiring `glimmer`
|
6
|
+
|
7
|
+
## 1.2.0
|
8
|
+
|
9
|
+
- Upgraded to Glimmer 2
|
10
|
+
|
11
|
+
## 1.1.0
|
12
|
+
|
13
|
+
- Support `xml` keyword to produce partial xml/html without the html tag in output
|
14
|
+
- Update `html` keyword to add a doctype (`<!DOCTYPE html>`) at the top of rendered content
|
15
|
+
- Make `html` keyword automatically not include a doctype or html tag if content does not have HEAD or BODY
|
16
|
+
- Make name_space act like an alternative to `xml` keyword, not requiring `xml` or `html` underneath
|
17
|
+
- Upgraded to glimmer 1.0.1
|
18
|
+
|
19
|
+
## 1.0.0
|
20
|
+
|
21
|
+
- Upgraded to Glimmer 1.0.0
|
22
|
+
|
23
|
+
## 0.2.0
|
24
|
+
|
25
|
+
- Relaxed dependency on glimmer
|
26
|
+
|
27
|
+
## 0.1.0
|
28
|
+
|
29
|
+
- Extracted Glimmer DSL for SWT (glimmer-dsl-swt gem) from Glimmer
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
## Pre-requisites
|
4
|
+
|
5
|
+
- MacOS
|
6
|
+
- Other pre-requisites mentioned in [README.md](https://github.com/AndyObtiva/glimmer/tree/master#pre-requisites)
|
7
|
+
|
8
|
+
## Machine Setup
|
9
|
+
|
10
|
+
Follow these steps, running mentioned commands in the terminal:
|
11
|
+
- Fork project repo
|
12
|
+
- Ensure pre-requisites installed (installing JRuby via RVM on the Mac)
|
13
|
+
- cd into project again to activate RVM glimmer gemset
|
14
|
+
- gem install bundler
|
15
|
+
- bundle
|
16
|
+
- rake # runs specs (ensure they finish successfully)
|
17
|
+
- Once done, open a pull request with master branch.
|
18
|
+
|
19
|
+
### rspec
|
20
|
+
|
21
|
+
`rake` or `rake spec` runs all specs.
|
22
|
+
|
23
|
+
To run a specific spec file, run:
|
24
|
+
```
|
25
|
+
rake SPEC=spec_file_path
|
26
|
+
```
|
27
|
+
|
28
|
+
To run a specific spec, run:
|
29
|
+
```
|
30
|
+
rake SPEC=spec_file_path:line_number
|
31
|
+
```
|
32
|
+
|
33
|
+
To display Glimmer debug information, add `GLIMMER_DEBUG=true`:
|
34
|
+
```
|
35
|
+
rake SPEC=spec_file_path:line_number GLIMMER_DEBUG=true
|
36
|
+
```
|
37
|
+
|
38
|
+
Note: make sure not to use the keyboard or mouse while tests are running since they bring up UI elements behind the scenes (invisible). This avoids fudging them and causing false test failures. If you get obscure failures related to focus of widgets, they are most likely false negatives. Just rerun the specs without touching the keyboard or mouse and they would pass if they are not really broken.
|
39
|
+
|
40
|
+
### build
|
41
|
+
|
42
|
+
`rake build` builds the Glimmer gem under the `pkg` directory.
|
43
|
+
|
44
|
+
### glimmer command
|
45
|
+
|
46
|
+
To run a glimmer sample, run local `bin/glimmer` command:
|
47
|
+
```
|
48
|
+
bin/glimmer samples/hello_world.rb
|
49
|
+
```
|
50
|
+
|
51
|
+
It will notify you that you are in development mode.
|
52
|
+
|
53
|
+
### girb command
|
54
|
+
|
55
|
+
To experiment with glimmer syntax using `girb`, run local `bin/girb`:
|
56
|
+
```
|
57
|
+
bin/girb
|
58
|
+
```
|
59
|
+
|
60
|
+
It will notify you that you are in development mode.
|
data/README.md
CHANGED
@@ -1,16 +1,19 @@
|
|
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 XML
|
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 XML 1.2.1 (& HTML)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-xml.svg)](http://badge.fury.io/rb/glimmer-dsl-xml)
|
3
3
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-xml.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-xml)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-xml/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-xml?branch=master)
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/65f487b8807f7126b803/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-xml/maintainability)
|
6
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)
|
7
7
|
|
8
|
-
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for XML provides Ruby syntax for building XML (eXtensible Markup Language) documents.
|
8
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for XML provides Ruby syntax for building XML (eXtensible Markup Language) and HTML documents.
|
9
9
|
|
10
|
-
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).
|
10
|
+
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-dsl-swt/tree/master#browser-widget).
|
11
11
|
|
12
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)
|
13
|
+
- [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Library)
|
14
|
+
- [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (Ruby Desktop Development GUI Library)
|
15
|
+
- [glimmer-dsl-libui](https://github.com/AndyObtiva/glimmer-dsl-libui): Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)
|
16
|
+
- [glimmer-dsl-gtk](https://github.com/AndyObtiva/glimmer-dsl-gtk): Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library)
|
14
17
|
- [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
|
15
18
|
- [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
|
16
19
|
|
@@ -22,12 +25,10 @@ Please follow these instructions to make the `glimmer` command available on your
|
|
22
25
|
|
23
26
|
Run this command to install directly:
|
24
27
|
```
|
25
|
-
|
28
|
+
gem install glimmer-dsl-xml -v 1.2.1
|
26
29
|
```
|
27
30
|
|
28
|
-
`jgem` is JRuby's version of `gem` command.
|
29
|
-
RVM allows running `gem` as an alias.
|
30
|
-
Otherwise, you may also run `jruby -S gem install ...`
|
31
|
+
Note: When using JRuby, `jgem` is JRuby's version of `gem` command. RVM allows running `gem` as an alias in JRuby. Otherwise, you may also run `jruby -S gem install ...`
|
31
32
|
|
32
33
|
Add `require 'glimmer-dsl-xml'` to your code.
|
33
34
|
|
@@ -39,14 +40,16 @@ That's it! Requiring the gem activates the Glimmer XML DSL automatically.
|
|
39
40
|
|
40
41
|
Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):
|
41
42
|
```
|
42
|
-
gem 'glimmer-dsl-xml', '~>
|
43
|
+
gem 'glimmer-dsl-xml', '~> 1.2.1'
|
43
44
|
```
|
44
45
|
|
45
46
|
And, then run:
|
46
47
|
```
|
47
|
-
|
48
|
+
bundle install
|
48
49
|
```
|
49
50
|
|
51
|
+
Note: When using JRuby, prefix with `jruby -S`
|
52
|
+
|
50
53
|
Require in your code via Bundler (e.g. `require 'bundler'; Bundler.require`) or add `require 'glimmer-dsl-xml'` to your code.
|
51
54
|
|
52
55
|
When using with [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) or [Glimmer DSL for Opal](https://github.com/AndyObtiva/glimmer-dsl-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.
|
@@ -55,20 +58,31 @@ That's it! Requiring the gem activates the Glimmer XML DSL automatically.
|
|
55
58
|
|
56
59
|
## XML DSL
|
57
60
|
|
58
|
-
Simply start with `html` keyword and add HTML inside its block using Glimmer DSL syntax.
|
59
|
-
Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted HTML output.
|
61
|
+
Simply start with the `html`, `xml`, `name_space`, or `tag` keyword and add XML/HTML inside its block using Glimmer DSL for XML syntax.
|
62
|
+
Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted XML/HTML output.
|
60
63
|
|
61
64
|
Here are all the Glimmer XML DSL top-level keywords:
|
62
|
-
- `html`
|
63
|
-
- `
|
65
|
+
- `html`: renders partial HTML just like `xml` (not having body/head) or full HTML document (having body/head), automatically including doctype (`<!DOCTYPE html>`) and surrounding content by the `<html></html>` tag
|
66
|
+
- `xml`: renders XML/XHTML content (e.g. `xml {span {'Hello'}; br}.to_s` renders `<span>Hello</span><br />`)
|
64
67
|
- `name_space`: enables namespacing html tags
|
68
|
+
- `tag`: enables custom tag creation for exceptional cases (e.g. `p` as reserved Ruby keyword) by passing tag name as '_name' attribute
|
65
69
|
|
66
70
|
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')` )
|
67
71
|
|
68
|
-
|
72
|
+
You may try the following examples in IRB after installing the [glimmer-dsl-xml](https://rubygems.org/gems/glimmer-dsl-xml) gem.
|
73
|
+
|
74
|
+
Just make sure to require the library and include Glimmer first:
|
69
75
|
|
70
76
|
```ruby
|
71
|
-
|
77
|
+
require 'glimmer-dsl-xml'
|
78
|
+
|
79
|
+
include Glimmer
|
80
|
+
```
|
81
|
+
|
82
|
+
Example (full HTML document):
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
@html = html {
|
72
86
|
head {
|
73
87
|
meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
|
74
88
|
}
|
@@ -76,59 +90,94 @@ Example (basic HTML / you may copy/paste in [`girb`](#girb-glimmer-irb-command))
|
|
76
90
|
h1 { "Hello, World!" }
|
77
91
|
}
|
78
92
|
}
|
79
|
-
|
93
|
+
|
94
|
+
puts @html
|
80
95
|
```
|
81
96
|
|
82
97
|
Output:
|
83
98
|
|
84
99
|
```
|
85
|
-
|
100
|
+
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>
|
86
101
|
```
|
87
102
|
|
88
|
-
Example (
|
103
|
+
Example (partial HTML fragment):
|
89
104
|
|
90
105
|
```ruby
|
91
|
-
|
106
|
+
@html = html {
|
107
|
+
h1 { "Hello, World!" }
|
108
|
+
}
|
109
|
+
|
110
|
+
puts @html
|
92
111
|
```
|
93
112
|
|
94
113
|
Output:
|
95
114
|
|
96
115
|
```
|
97
|
-
<
|
116
|
+
<h1>Hello, World!</h1>
|
98
117
|
```
|
99
118
|
|
100
|
-
Example (XML
|
119
|
+
Example (basic XML):
|
101
120
|
|
102
121
|
```ruby
|
103
|
-
@xml =
|
104
|
-
|
105
|
-
body(:id => "main") {
|
106
|
-
}
|
107
|
-
}
|
122
|
+
@xml = xml {
|
123
|
+
greeting { "Hello, World!" }
|
108
124
|
}
|
125
|
+
|
109
126
|
puts @xml
|
110
127
|
```
|
111
128
|
|
112
129
|
Output:
|
113
130
|
|
114
131
|
```
|
115
|
-
<
|
132
|
+
<greeting>Hello, World!</greeting>
|
116
133
|
```
|
117
134
|
|
118
|
-
Example (XML namespaces using
|
135
|
+
Example (XML namespaces using `name_space` keyword):
|
119
136
|
|
120
137
|
```ruby
|
121
|
-
@xml =
|
122
|
-
|
138
|
+
@xml = name_space(:acme) {
|
139
|
+
product(:id => "thesis", :class => "document") {
|
140
|
+
component(:id => "main") {
|
141
|
+
}
|
123
142
|
}
|
124
143
|
}
|
144
|
+
|
125
145
|
puts @xml
|
126
146
|
```
|
127
147
|
|
128
148
|
Output:
|
129
149
|
|
130
150
|
```
|
131
|
-
<
|
151
|
+
<acme:product id="thesis" class="document"><acme:component id="main"></acme:component></acme:product>
|
152
|
+
```
|
153
|
+
|
154
|
+
Example (XML namespaces using dot operator):
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
@xml = xml {
|
158
|
+
document.body(document.id => "main") {
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
puts @xml
|
163
|
+
```
|
164
|
+
|
165
|
+
Output:
|
166
|
+
|
167
|
+
```
|
168
|
+
<document:body document:id="main"></document:body>
|
169
|
+
```
|
170
|
+
|
171
|
+
Example (custom tag):
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
puts tag(:_name => "p") {"p is a reserved keyword in Ruby"}
|
175
|
+
```
|
176
|
+
|
177
|
+
Output:
|
178
|
+
|
179
|
+
```
|
180
|
+
<p>p is a reserved keyword in Ruby</p>
|
132
181
|
```
|
133
182
|
|
134
183
|
## Multi-DSL Support
|
@@ -141,9 +190,9 @@ Learn more about how to use this DSL alongside other Glimmer DSLs:
|
|
141
190
|
|
142
191
|
### Issues
|
143
192
|
|
144
|
-
You may submit [issues](https://github.com/AndyObtiva/glimmer/issues) on [GitHub](https://github.com/AndyObtiva/glimmer/issues).
|
193
|
+
You may submit [issues](https://github.com/AndyObtiva/glimmer-dsl-xml/issues) on [GitHub](https://github.com/AndyObtiva/glimmer-dsl-xml/issues).
|
145
194
|
|
146
|
-
[Click here to submit an issue.](https://github.com/AndyObtiva/glimmer/issues)
|
195
|
+
[Click here to submit an issue.](https://github.com/AndyObtiva/glimmer-dsl-xml/issues)
|
147
196
|
|
148
197
|
### Chat
|
149
198
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.2.1
|
data/lib/glimmer/dsl/xml/dsl.rb
CHANGED
@@ -1,8 +1,29 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/dsl/engine'
|
2
|
-
# Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f} # cannot in Opal
|
23
|
+
# Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f} # cannot in Opal, disabling automated requires for now
|
3
24
|
require 'glimmer/dsl/xml/text_expression'
|
4
25
|
require 'glimmer/dsl/xml/tag_expression'
|
5
|
-
require 'glimmer/dsl/xml/
|
26
|
+
require 'glimmer/dsl/xml/xml_node_expression'
|
6
27
|
require 'glimmer/dsl/xml/html_expression'
|
7
28
|
require 'glimmer/dsl/xml/meta_expression'
|
8
29
|
require 'glimmer/dsl/xml/name_space_expression'
|
@@ -15,7 +36,7 @@ module Glimmer
|
|
15
36
|
%w[
|
16
37
|
text
|
17
38
|
tag
|
18
|
-
|
39
|
+
xml_node
|
19
40
|
]
|
20
41
|
)
|
21
42
|
end
|
@@ -1,7 +1,28 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/dsl/xml/node_parent_expression'
|
2
|
-
require 'glimmer/dsl/xml/xml_expression'
|
3
23
|
require 'glimmer/dsl/static_expression'
|
4
24
|
require 'glimmer/dsl/top_level_expression'
|
25
|
+
require 'glimmer/xml/html_node'
|
5
26
|
|
6
27
|
module Glimmer
|
7
28
|
module DSL
|
@@ -13,11 +34,7 @@ module Glimmer
|
|
13
34
|
include NodeParentExpression
|
14
35
|
|
15
36
|
def interpret(parent, keyword, *args, &block)
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def xml_expression
|
20
|
-
@xml_expression ||= XmlExpression.new
|
37
|
+
Glimmer::XML::HtmlNode.new(parent, keyword.to_s, args, &block)
|
21
38
|
end
|
22
39
|
end
|
23
40
|
end
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/dsl/xml/node_parent_expression'
|
2
23
|
require 'glimmer/dsl/xml/xml_expression'
|
3
24
|
require 'glimmer/dsl/static_expression'
|
@@ -1,5 +1,27 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/dsl/static_expression'
|
2
23
|
require 'glimmer/dsl/top_level_expression'
|
24
|
+
require 'glimmer/dsl/parent_expression'
|
3
25
|
require 'glimmer/xml/node'
|
4
26
|
require 'glimmer/xml/depth_first_search_iterator'
|
5
27
|
require 'glimmer/xml/name_space_visitor'
|
@@ -9,6 +31,7 @@ module Glimmer
|
|
9
31
|
module XML
|
10
32
|
class NameSpaceExpression < StaticExpression
|
11
33
|
include TopLevelExpression
|
34
|
+
include ParentExpression
|
12
35
|
|
13
36
|
def can_interpret?(parent, keyword, *args, &block)
|
14
37
|
(parent == nil or parent.is_a?(Glimmer::XML::Node)) and
|
@@ -19,18 +42,23 @@ module Glimmer
|
|
19
42
|
end
|
20
43
|
|
21
44
|
def interpret(parent, keyword, *args, &block)
|
22
|
-
|
45
|
+
# act like a top-level xml tag
|
46
|
+
Glimmer::XML::Node.new(parent, args[0].to_s, :_name_space_context => true)
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_content(parent, keyword, *args, &block)
|
50
|
+
node = block.call(parent)
|
23
51
|
unless node.is_a?(String)
|
24
|
-
name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(
|
52
|
+
name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(parent.name)
|
25
53
|
Glimmer::XML::DepthFirstSearchIterator.new(node, name_space_visitor).iterate
|
26
54
|
def node.process_block(block)
|
27
55
|
Glimmer::Config.logger&.debug 'block'
|
28
|
-
#NOOP
|
29
56
|
end
|
30
57
|
end
|
31
58
|
parent.children << node if parent and !parent.children.include?(node)
|
32
59
|
node
|
33
60
|
end
|
61
|
+
|
34
62
|
end
|
35
63
|
end
|
36
64
|
end
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer'
|
2
23
|
require 'glimmer/dsl/parent_expression'
|
3
24
|
require 'glimmer/xml/node'
|
@@ -9,8 +30,8 @@ module Glimmer
|
|
9
30
|
include ParentExpression
|
10
31
|
include Glimmer
|
11
32
|
|
12
|
-
def add_content(parent, &block)
|
13
|
-
return_value = block.call(parent)
|
33
|
+
def add_content(parent, keyword, *args, &block)
|
34
|
+
return_value = block.call(parent)
|
14
35
|
if !return_value.is_a?(Glimmer::XML::Node) and !parent.children.include?(return_value)
|
15
36
|
text = return_value.to_s
|
16
37
|
first_match = text.match(/[#][^{]+[{][^}]+[}]/)
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/dsl/xml/node_parent_expression'
|
2
23
|
require 'glimmer/dsl/xml/xml_expression'
|
3
24
|
require 'glimmer/dsl/static_expression'
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/dsl/static_expression'
|
2
23
|
require 'glimmer/xml/node'
|
3
24
|
|
@@ -1,17 +1,36 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/dsl/xml/node_parent_expression'
|
2
|
-
require 'glimmer/dsl/
|
23
|
+
require 'glimmer/dsl/static_expression'
|
24
|
+
require 'glimmer/dsl/top_level_expression'
|
3
25
|
require 'glimmer/xml/node'
|
4
26
|
|
5
27
|
module Glimmer
|
6
28
|
module DSL
|
7
29
|
module XML
|
8
|
-
class XmlExpression <
|
30
|
+
class XmlExpression < StaticExpression
|
31
|
+
include TopLevelExpression
|
9
32
|
include NodeParentExpression
|
10
33
|
|
11
|
-
def can_interpret?(parent, keyword, *args, &block)
|
12
|
-
parent.is_a?(Glimmer::XML::Node)
|
13
|
-
end
|
14
|
-
|
15
34
|
def interpret(parent, keyword, *args, &block)
|
16
35
|
Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
|
17
36
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/dsl/xml/node_parent_expression'
|
23
|
+
require 'glimmer/dsl/expression'
|
24
|
+
require 'glimmer/xml/node'
|
25
|
+
|
26
|
+
module Glimmer
|
27
|
+
module DSL
|
28
|
+
module XML
|
29
|
+
class XmlNodeExpression < Expression
|
30
|
+
include NodeParentExpression
|
31
|
+
|
32
|
+
def can_interpret?(parent, keyword, *args, &block)
|
33
|
+
parent.is_a?(Glimmer::XML::Node)
|
34
|
+
end
|
35
|
+
|
36
|
+
def interpret(parent, keyword, *args, &block)
|
37
|
+
Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/xml/node'
|
2
23
|
|
3
24
|
module Glimmer
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
# Copyright (c) 2020 - Andy Maleh
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'glimmer/xml/node'
|
24
|
+
require 'glimmer/xml/html_visitor'
|
25
|
+
require 'glimmer/xml/xml_visitor'
|
26
|
+
|
27
|
+
module Glimmer
|
28
|
+
module XML
|
29
|
+
class HtmlNode < Node
|
30
|
+
def to_xml
|
31
|
+
node_visitor = @name_space.nil? ? HtmlVisitor.new : XmlVisitor.new
|
32
|
+
DepthFirstSearchIterator.new(self, node_visitor).iterate
|
33
|
+
node_visitor.document
|
34
|
+
end
|
35
|
+
alias to_html to_xml
|
36
|
+
alias to_s to_xml
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/xml/xml_visitor'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module XML
|
26
|
+
class HtmlVisitor < XmlVisitor
|
27
|
+
|
28
|
+
def render_html_tag?(node)
|
29
|
+
if node.name == 'html'
|
30
|
+
node_children = node.children.select {|node_or_text| node_or_text.is_a?(Glimmer::XML::Node)}
|
31
|
+
if !node_children.empty?
|
32
|
+
children_names = node_children.map(&:name)
|
33
|
+
return false unless children_names.include?('head') || children_names.include?('body')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def begin_open_tag(node)
|
40
|
+
return unless render_html_tag?(node)
|
41
|
+
@document += "<!DOCTYPE html>" if node.name == 'html'
|
42
|
+
super(node)
|
43
|
+
end
|
44
|
+
|
45
|
+
def end_open_tag(node)
|
46
|
+
return unless render_html_tag?(node)
|
47
|
+
super(node)
|
48
|
+
end
|
49
|
+
|
50
|
+
def append_close_tag(node)
|
51
|
+
return unless render_html_tag?(node)
|
52
|
+
super(node)
|
53
|
+
end
|
54
|
+
|
55
|
+
def append_attributes(node)
|
56
|
+
return unless render_html_tag?(node)
|
57
|
+
super(node)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require "glimmer/xml/node_visitor"
|
2
23
|
|
3
24
|
module Glimmer
|
data/lib/glimmer/xml/node.rb
CHANGED
@@ -1,4 +1,24 @@
|
|
1
|
-
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
2
22
|
require 'glimmer/xml/depth_first_search_iterator'
|
3
23
|
require 'glimmer/xml/xml_visitor'
|
4
24
|
|
@@ -7,8 +27,10 @@ module Glimmer
|
|
7
27
|
class Node
|
8
28
|
include Glimmer
|
9
29
|
|
30
|
+
# TODO change is_name_space to name_space?
|
31
|
+
|
10
32
|
attr_accessor :children, :name, :contents, :attributes, :is_name_space, :is_attribute, :name_space, :parent
|
11
|
-
|
33
|
+
|
12
34
|
def initialize(parent, name, attributes, &contents)
|
13
35
|
@is_name_space = false
|
14
36
|
@children = []
|
@@ -44,16 +66,19 @@ module Glimmer
|
|
44
66
|
def method_missing(symbol, *args, &block)
|
45
67
|
@is_name_space = true
|
46
68
|
parent.children.delete(self) if parent
|
47
|
-
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::
|
69
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::XmlExpression.new, name, attributes) {@tag = super}
|
48
70
|
@tag
|
49
71
|
end
|
72
|
+
|
73
|
+
def name_space_context?
|
74
|
+
attributes[:_name_space_context]
|
75
|
+
end
|
50
76
|
|
51
77
|
def to_xml
|
52
78
|
xml_visitor = XmlVisitor.new
|
53
79
|
DepthFirstSearchIterator.new(self, xml_visitor).iterate
|
54
80
|
xml_visitor.document
|
55
81
|
end
|
56
|
-
alias to_html to_xml
|
57
82
|
alias to_s to_xml
|
58
83
|
|
59
84
|
def text_command(text)
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
module Glimmer
|
2
23
|
module XML
|
3
24
|
class NodeVisitor
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require "glimmer/xml/node_visitor"
|
2
23
|
require "glimmer/xml/node"
|
3
24
|
|
@@ -27,21 +48,24 @@ module Glimmer
|
|
27
48
|
end
|
28
49
|
|
29
50
|
def begin_open_tag(node)
|
51
|
+
return if node.name == 'xml' || node.name_space_context?
|
30
52
|
@document += "<"
|
31
53
|
@document += "#{node.name_space.name}:" if node.name_space
|
32
54
|
@document += node.name
|
33
55
|
end
|
34
56
|
|
35
57
|
def end_open_tag(node)
|
58
|
+
return if node.name == 'xml' || node.name_space_context?
|
36
59
|
if (node.contents)
|
37
60
|
@document += ">"
|
38
61
|
else
|
39
62
|
@document += " " if node.attributes.keys.size > 0
|
40
|
-
@document += "/>"
|
63
|
+
@document += " />"
|
41
64
|
end
|
42
65
|
end
|
43
66
|
|
44
67
|
def append_close_tag(node)
|
68
|
+
return if node.name == 'xml' || node.name_space_context?
|
45
69
|
if (node.contents)
|
46
70
|
@document += "</"
|
47
71
|
@document += "#{node.name_space.name}:" if node.name_space
|
@@ -50,6 +74,7 @@ module Glimmer
|
|
50
74
|
end
|
51
75
|
|
52
76
|
def append_attributes(node)
|
77
|
+
return if node.name == 'xml' || node.name_space_context?
|
53
78
|
Glimmer::Config.logger&.debug "Take 3"
|
54
79
|
Glimmer::Config.logger&.debug(node.attributes)
|
55
80
|
node.attributes.each do |attribute, value|
|
data/lib/glimmer-dsl-xml.rb
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
# Copyright (c) 2020 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
$LOAD_PATH.unshift(File.expand_path('..', __FILE__))
|
2
23
|
|
24
|
+
ENV['GLIMMER_LOGGER_LEVEL'] = 'error'
|
25
|
+
|
26
|
+
require 'glimmer'
|
3
27
|
require 'glimmer/dsl/xml/dsl'
|
metadata
CHANGED
@@ -1,42 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: glimmer
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
|
-
- - "
|
17
|
-
- !ruby/object:Gem::Version
|
18
|
-
version: 0.9.0
|
19
|
-
- - "<"
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.0.0
|
22
|
-
name: glimmer
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.9.0
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: 2.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-mocks
|
34
29
|
requirement: !ruby/object:Gem::Requirement
|
35
30
|
requirements:
|
36
31
|
- - "~>"
|
37
32
|
- !ruby/object:Gem::Version
|
38
33
|
version: 3.5.0
|
39
|
-
name: rspec-mocks
|
40
34
|
type: :development
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -45,12 +39,12 @@ dependencies:
|
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: 3.5.0
|
47
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
44
|
requirements:
|
50
45
|
- - "~>"
|
51
46
|
- !ruby/object:Gem::Version
|
52
47
|
version: 3.5.0
|
53
|
-
name: rspec
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -59,20 +53,21 @@ dependencies:
|
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: 3.5.0
|
61
55
|
- !ruby/object:Gem::Dependency
|
56
|
+
name: puts_debuggerer
|
62
57
|
requirement: !ruby/object:Gem::Requirement
|
63
58
|
requirements:
|
64
|
-
- - "
|
59
|
+
- - ">="
|
65
60
|
- !ruby/object:Gem::Version
|
66
|
-
version: 0
|
67
|
-
name: puts_debuggerer
|
61
|
+
version: '0'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
|
-
- - "
|
66
|
+
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0
|
68
|
+
version: '0'
|
75
69
|
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
76
71
|
requirement: !ruby/object:Gem::Requirement
|
77
72
|
requirements:
|
78
73
|
- - ">="
|
@@ -81,7 +76,6 @@ dependencies:
|
|
81
76
|
- - "<"
|
82
77
|
- !ruby/object:Gem::Version
|
83
78
|
version: 14.0.0
|
84
|
-
name: rake
|
85
79
|
type: :development
|
86
80
|
prerelease: false
|
87
81
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -93,6 +87,7 @@ dependencies:
|
|
93
87
|
- !ruby/object:Gem::Version
|
94
88
|
version: 14.0.0
|
95
89
|
- !ruby/object:Gem::Dependency
|
90
|
+
name: jeweler
|
96
91
|
requirement: !ruby/object:Gem::Requirement
|
97
92
|
requirements:
|
98
93
|
- - ">="
|
@@ -101,7 +96,6 @@ dependencies:
|
|
101
96
|
- - "<"
|
102
97
|
- !ruby/object:Gem::Version
|
103
98
|
version: 3.0.0
|
104
|
-
name: jeweler
|
105
99
|
type: :development
|
106
100
|
prerelease: false
|
107
101
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -113,6 +107,7 @@ dependencies:
|
|
113
107
|
- !ruby/object:Gem::Version
|
114
108
|
version: 3.0.0
|
115
109
|
- !ruby/object:Gem::Dependency
|
110
|
+
name: rdoc
|
116
111
|
requirement: !ruby/object:Gem::Requirement
|
117
112
|
requirements:
|
118
113
|
- - ">="
|
@@ -121,7 +116,6 @@ dependencies:
|
|
121
116
|
- - "<"
|
122
117
|
- !ruby/object:Gem::Version
|
123
118
|
version: 7.0.0
|
124
|
-
name: rdoc
|
125
119
|
type: :development
|
126
120
|
prerelease: false
|
127
121
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -133,12 +127,12 @@ dependencies:
|
|
133
127
|
- !ruby/object:Gem::Version
|
134
128
|
version: 7.0.0
|
135
129
|
- !ruby/object:Gem::Dependency
|
130
|
+
name: coveralls
|
136
131
|
requirement: !ruby/object:Gem::Requirement
|
137
132
|
requirements:
|
138
133
|
- - '='
|
139
134
|
- !ruby/object:Gem::Version
|
140
135
|
version: 0.8.23
|
141
|
-
name: coveralls
|
142
136
|
type: :development
|
143
137
|
prerelease: false
|
144
138
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -147,12 +141,12 @@ dependencies:
|
|
147
141
|
- !ruby/object:Gem::Version
|
148
142
|
version: 0.8.23
|
149
143
|
- !ruby/object:Gem::Dependency
|
144
|
+
name: simplecov
|
150
145
|
requirement: !ruby/object:Gem::Requirement
|
151
146
|
requirements:
|
152
147
|
- - "~>"
|
153
148
|
- !ruby/object:Gem::Version
|
154
149
|
version: 0.16.1
|
155
|
-
name: simplecov
|
156
150
|
type: :development
|
157
151
|
prerelease: false
|
158
152
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -161,12 +155,12 @@ dependencies:
|
|
161
155
|
- !ruby/object:Gem::Version
|
162
156
|
version: 0.16.1
|
163
157
|
- !ruby/object:Gem::Dependency
|
158
|
+
name: simplecov-lcov
|
164
159
|
requirement: !ruby/object:Gem::Requirement
|
165
160
|
requirements:
|
166
161
|
- - "~>"
|
167
162
|
- !ruby/object:Gem::Version
|
168
163
|
version: 0.7.0
|
169
|
-
name: simplecov-lcov
|
170
164
|
type: :development
|
171
165
|
prerelease: false
|
172
166
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -174,14 +168,31 @@ dependencies:
|
|
174
168
|
- - "~>"
|
175
169
|
- !ruby/object:Gem::Version
|
176
170
|
version: 0.7.0
|
171
|
+
- !ruby/object:Gem::Dependency
|
172
|
+
name: rake-tui
|
173
|
+
requirement: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
type: :development
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
177
185
|
description: Glimmer DSL for XML (& HTML)
|
178
186
|
email: andy.am@gmail.com
|
179
187
|
executables: []
|
180
188
|
extensions: []
|
181
189
|
extra_rdoc_files:
|
190
|
+
- CHANGELOG.md
|
182
191
|
- LICENSE.txt
|
183
192
|
- README.md
|
184
193
|
files:
|
194
|
+
- CHANGELOG.md
|
195
|
+
- CONTRIBUTING.md
|
185
196
|
- LICENSE.txt
|
186
197
|
- README.md
|
187
198
|
- VERSION
|
@@ -194,7 +205,10 @@ files:
|
|
194
205
|
- lib/glimmer/dsl/xml/tag_expression.rb
|
195
206
|
- lib/glimmer/dsl/xml/text_expression.rb
|
196
207
|
- lib/glimmer/dsl/xml/xml_expression.rb
|
208
|
+
- lib/glimmer/dsl/xml/xml_node_expression.rb
|
197
209
|
- lib/glimmer/xml/depth_first_search_iterator.rb
|
210
|
+
- lib/glimmer/xml/html_node.rb
|
211
|
+
- lib/glimmer/xml/html_visitor.rb
|
198
212
|
- lib/glimmer/xml/name_space_visitor.rb
|
199
213
|
- lib/glimmer/xml/node.rb
|
200
214
|
- lib/glimmer/xml/node_visitor.rb
|
@@ -218,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
232
|
- !ruby/object:Gem::Version
|
219
233
|
version: '0'
|
220
234
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
235
|
+
rubygems_version: 3.2.22
|
222
236
|
signing_key:
|
223
237
|
specification_version: 4
|
224
238
|
summary: Glimmer DSL for XML
|