glimmer-dsl-xml 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +84 -29
- data/VERSION +1 -1
- data/lib/glimmer-dsl-xml.rb +1 -0
- data/lib/glimmer/dsl/xml/dsl.rb +2 -2
- data/lib/glimmer/dsl/xml/html_expression.rb +2 -6
- data/lib/glimmer/dsl/xml/name_space_expression.rb +10 -3
- data/lib/glimmer/dsl/xml/xml_expression.rb +4 -6
- data/lib/glimmer/dsl/xml/xml_node_expression.rb +42 -0
- data/lib/glimmer/xml/html_node.rb +39 -0
- data/lib/glimmer/xml/html_visitor.rb +61 -0
- data/lib/glimmer/xml/node.rb +8 -4
- data/lib/glimmer/xml/xml_visitor.rb +5 -1
- metadata +26 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c774d77fe8923afccfdc96d47731da399f3743c5b42aeaa569288d41438e3ca
|
4
|
+
data.tar.gz: 31d231cbb7893502c0322df99e3c8c2b36d086ffa9357708626476119bb0a70c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4316b94b77344436530a5d6e6ffe3db75f2aaa8997fc9f6418c4317a327bc614fd7820bd179142f1833ba8a629e3b9f3673acd9a452de3b552b4c7a48d4b3b88
|
7
|
+
data.tar.gz: 81a8014a802c731077eae762263284691ed9e7f2d4d9b82ac0409333a4693778a67736919fca2a8620787e2b280badcaf43d67c8f8d5dfafa3b1141bca78b6f0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.1.0
|
4
|
+
|
5
|
+
- Support `xml` keyword to produce partial xml/html without the html tag in output
|
6
|
+
- Update `html` keyword to add a doctype (`<!DOCTYPE html>`) at the top of rendered content
|
7
|
+
- Make `html` keyword automatically not include a doctype or html tag if content does not have HEAD or BODY
|
8
|
+
- Make name_space act like an alternative to `xml` keyword, not requiring `xml` or `html` underneath
|
9
|
+
- Upgraded to glimmer 1.0.1
|
10
|
+
|
3
11
|
## 1.0.0
|
4
12
|
|
5
13
|
- Upgraded to Glimmer 1.0.0
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
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.
|
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.1.0 (& 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)
|
@@ -10,8 +10,8 @@
|
|
10
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 (JRuby Desktop GUI)
|
14
|
-
- [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (Ruby 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
15
|
- [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
|
16
16
|
- [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
|
17
17
|
|
@@ -23,12 +23,10 @@ Please follow these instructions to make the `glimmer` command available on your
|
|
23
23
|
|
24
24
|
Run this command to install directly:
|
25
25
|
```
|
26
|
-
|
26
|
+
gem install glimmer-dsl-xml -v 1.1.0
|
27
27
|
```
|
28
28
|
|
29
|
-
`jgem` is JRuby's version of `gem` command.
|
30
|
-
RVM allows running `gem` as an alias.
|
31
|
-
Otherwise, you may also run `jruby -S gem install ...`
|
29
|
+
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 ...`
|
32
30
|
|
33
31
|
Add `require 'glimmer-dsl-xml'` to your code.
|
34
32
|
|
@@ -40,14 +38,16 @@ That's it! Requiring the gem activates the Glimmer XML DSL automatically.
|
|
40
38
|
|
41
39
|
Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):
|
42
40
|
```
|
43
|
-
gem 'glimmer-dsl-xml', '~> 1.
|
41
|
+
gem 'glimmer-dsl-xml', '~> 1.1.0'
|
44
42
|
```
|
45
43
|
|
46
44
|
And, then run:
|
47
45
|
```
|
48
|
-
|
46
|
+
bundle install
|
49
47
|
```
|
50
48
|
|
49
|
+
Note: When using JRuby, prefix with `jruby -S`
|
50
|
+
|
51
51
|
Require in your code via Bundler (e.g. `require 'bundler'; Bundler.require`) or add `require 'glimmer-dsl-xml'` to your code.
|
52
52
|
|
53
53
|
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.
|
@@ -56,20 +56,25 @@ That's it! Requiring the gem activates the Glimmer XML DSL automatically.
|
|
56
56
|
|
57
57
|
## XML DSL
|
58
58
|
|
59
|
-
Simply start with `html` keyword and add HTML inside its block using Glimmer DSL syntax.
|
60
|
-
Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted HTML output.
|
59
|
+
Simply start with the `html`, `xml`, `name_space`, or `tag` keyword and add XML/HTML inside its block using Glimmer DSL for XML syntax.
|
60
|
+
Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted XML/HTML output.
|
61
61
|
|
62
62
|
Here are all the Glimmer XML DSL top-level keywords:
|
63
|
-
- `html`
|
64
|
-
- `
|
63
|
+
- `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
|
64
|
+
- `xml`: renders XML/XHTML content (e.g. `xml {span {'Hello'}; br}.to_s` renders `<span>Hello</span><br />`)
|
65
65
|
- `name_space`: enables namespacing html tags
|
66
|
+
- `tag`: enables custom tag creation for exceptional cases (e.g. `p` as reserved Ruby keyword) by passing tag name as '_name' attribute
|
66
67
|
|
67
68
|
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')` )
|
68
69
|
|
69
|
-
Example (
|
70
|
+
Example (full HTML document):
|
70
71
|
|
71
72
|
```ruby
|
72
|
-
|
73
|
+
require 'glimmer-dsl-xml'
|
74
|
+
|
75
|
+
include Glimmer
|
76
|
+
|
77
|
+
@html = html {
|
73
78
|
head {
|
74
79
|
meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
|
75
80
|
}
|
@@ -77,33 +82,63 @@ Example (basic HTML):
|
|
77
82
|
h1 { "Hello, World!" }
|
78
83
|
}
|
79
84
|
}
|
80
|
-
puts @
|
85
|
+
puts @html
|
86
|
+
```
|
87
|
+
|
88
|
+
Output:
|
89
|
+
|
90
|
+
```
|
91
|
+
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>
|
92
|
+
```
|
93
|
+
|
94
|
+
Example (partial HTML fragment):
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
require 'glimmer-dsl-xml'
|
98
|
+
|
99
|
+
include Glimmer
|
100
|
+
|
101
|
+
@html = html {
|
102
|
+
h1 { "Hello, World!" }
|
103
|
+
}
|
104
|
+
puts @html
|
81
105
|
```
|
82
106
|
|
83
107
|
Output:
|
84
108
|
|
85
109
|
```
|
86
|
-
<
|
110
|
+
<h1>Hello, World!</h1>
|
87
111
|
```
|
88
112
|
|
89
|
-
Example (
|
113
|
+
Example (basic XML):
|
90
114
|
|
91
115
|
```ruby
|
92
|
-
|
116
|
+
require 'glimmer-dsl-xml'
|
117
|
+
|
118
|
+
include Glimmer
|
119
|
+
|
120
|
+
@xml = xml {
|
121
|
+
h1 { "Hello, World!" }
|
122
|
+
}
|
123
|
+
puts @xml
|
93
124
|
```
|
94
125
|
|
95
126
|
Output:
|
96
127
|
|
97
128
|
```
|
98
|
-
<
|
129
|
+
<h1>Hello, World!</h1>
|
99
130
|
```
|
100
131
|
|
101
132
|
Example (XML namespaces using `name_space` keyword):
|
102
133
|
|
103
134
|
```ruby
|
104
|
-
|
105
|
-
|
106
|
-
|
135
|
+
require 'glimmer-dsl-xml'
|
136
|
+
|
137
|
+
include Glimmer
|
138
|
+
|
139
|
+
@xml = name_space(:acme) {
|
140
|
+
product(:id => "thesis", :class => "document") {
|
141
|
+
component(:id => "main") {
|
107
142
|
}
|
108
143
|
}
|
109
144
|
}
|
@@ -113,23 +148,43 @@ puts @xml
|
|
113
148
|
Output:
|
114
149
|
|
115
150
|
```
|
116
|
-
<
|
151
|
+
<acme:product id="thesis" class="document"><acme:component id="main"></acme:component></acme:product>
|
117
152
|
```
|
118
153
|
|
119
154
|
Example (XML namespaces using dot operator):
|
120
155
|
|
121
156
|
```ruby
|
122
|
-
|
123
|
-
|
157
|
+
require 'glimmer-dsl-xml'
|
158
|
+
|
159
|
+
include Glimmer
|
160
|
+
|
161
|
+
@xml = xml {
|
162
|
+
document.body(document.id => "main") {
|
163
|
+
}
|
124
164
|
}
|
125
|
-
|
126
|
-
|
165
|
+
puts @xml
|
166
|
+
```
|
167
|
+
|
168
|
+
Output:
|
169
|
+
|
170
|
+
```
|
171
|
+
<document:body document:id="main"></document:body>
|
172
|
+
```
|
173
|
+
|
174
|
+
Example (custom tag):
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
require 'glimmer-dsl-xml'
|
178
|
+
|
179
|
+
include Glimmer
|
180
|
+
|
181
|
+
puts tag(:_name => "p") {"p is a reserved keyword in Ruby"}
|
127
182
|
```
|
128
183
|
|
129
184
|
Output:
|
130
185
|
|
131
186
|
```
|
132
|
-
<
|
187
|
+
<p>p is a reserved keyword in Ruby</p>
|
133
188
|
```
|
134
189
|
|
135
190
|
## Multi-DSL Support
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/glimmer-dsl-xml.rb
CHANGED
data/lib/glimmer/dsl/xml/dsl.rb
CHANGED
@@ -23,7 +23,7 @@ require 'glimmer/dsl/engine'
|
|
23
23
|
# Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f} # cannot in Opal, disabling automated requires for now
|
24
24
|
require 'glimmer/dsl/xml/text_expression'
|
25
25
|
require 'glimmer/dsl/xml/tag_expression'
|
26
|
-
require 'glimmer/dsl/xml/
|
26
|
+
require 'glimmer/dsl/xml/xml_node_expression'
|
27
27
|
require 'glimmer/dsl/xml/html_expression'
|
28
28
|
require 'glimmer/dsl/xml/meta_expression'
|
29
29
|
require 'glimmer/dsl/xml/name_space_expression'
|
@@ -36,7 +36,7 @@ module Glimmer
|
|
36
36
|
%w[
|
37
37
|
text
|
38
38
|
tag
|
39
|
-
|
39
|
+
xml_node
|
40
40
|
]
|
41
41
|
)
|
42
42
|
end
|
@@ -20,9 +20,9 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/dsl/xml/node_parent_expression'
|
23
|
-
require 'glimmer/dsl/xml/xml_expression'
|
24
23
|
require 'glimmer/dsl/static_expression'
|
25
24
|
require 'glimmer/dsl/top_level_expression'
|
25
|
+
require 'glimmer/xml/html_node'
|
26
26
|
|
27
27
|
module Glimmer
|
28
28
|
module DSL
|
@@ -34,11 +34,7 @@ module Glimmer
|
|
34
34
|
include NodeParentExpression
|
35
35
|
|
36
36
|
def interpret(parent, keyword, *args, &block)
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def xml_expression
|
41
|
-
@xml_expression ||= XmlExpression.new
|
37
|
+
Glimmer::XML::HtmlNode.new(parent, keyword.to_s, args, &block)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
end
|
@@ -21,6 +21,7 @@
|
|
21
21
|
|
22
22
|
require 'glimmer/dsl/static_expression'
|
23
23
|
require 'glimmer/dsl/top_level_expression'
|
24
|
+
require 'glimmer/dsl/parent_expression'
|
24
25
|
require 'glimmer/xml/node'
|
25
26
|
require 'glimmer/xml/depth_first_search_iterator'
|
26
27
|
require 'glimmer/xml/name_space_visitor'
|
@@ -30,6 +31,7 @@ module Glimmer
|
|
30
31
|
module XML
|
31
32
|
class NameSpaceExpression < StaticExpression
|
32
33
|
include TopLevelExpression
|
34
|
+
include ParentExpression
|
33
35
|
|
34
36
|
def can_interpret?(parent, keyword, *args, &block)
|
35
37
|
(parent == nil or parent.is_a?(Glimmer::XML::Node)) and
|
@@ -40,18 +42,23 @@ module Glimmer
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def interpret(parent, keyword, *args, &block)
|
43
|
-
|
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, &block)
|
50
|
+
node = block.call(parent)
|
44
51
|
unless node.is_a?(String)
|
45
|
-
name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(
|
52
|
+
name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(parent.name)
|
46
53
|
Glimmer::XML::DepthFirstSearchIterator.new(node, name_space_visitor).iterate
|
47
54
|
def node.process_block(block)
|
48
55
|
Glimmer::Config.logger&.debug 'block'
|
49
|
-
#NOOP
|
50
56
|
end
|
51
57
|
end
|
52
58
|
parent.children << node if parent and !parent.children.include?(node)
|
53
59
|
node
|
54
60
|
end
|
61
|
+
|
55
62
|
end
|
56
63
|
end
|
57
64
|
end
|
@@ -20,19 +20,17 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/dsl/xml/node_parent_expression'
|
23
|
-
require 'glimmer/dsl/
|
23
|
+
require 'glimmer/dsl/static_expression'
|
24
|
+
require 'glimmer/dsl/top_level_expression'
|
24
25
|
require 'glimmer/xml/node'
|
25
26
|
|
26
27
|
module Glimmer
|
27
28
|
module DSL
|
28
29
|
module XML
|
29
|
-
class XmlExpression <
|
30
|
+
class XmlExpression < StaticExpression
|
31
|
+
include TopLevelExpression
|
30
32
|
include NodeParentExpression
|
31
33
|
|
32
|
-
def can_interpret?(parent, keyword, *args, &block)
|
33
|
-
parent.is_a?(Glimmer::XML::Node)
|
34
|
-
end
|
35
|
-
|
36
34
|
def interpret(parent, keyword, *args, &block)
|
37
35
|
Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
|
38
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
|
@@ -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
|
data/lib/glimmer/xml/node.rb
CHANGED
@@ -19,7 +19,6 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
-
require 'glimmer'
|
23
22
|
require 'glimmer/xml/depth_first_search_iterator'
|
24
23
|
require 'glimmer/xml/xml_visitor'
|
25
24
|
|
@@ -28,8 +27,10 @@ module Glimmer
|
|
28
27
|
class Node
|
29
28
|
include Glimmer
|
30
29
|
|
30
|
+
# TODO change is_name_space to name_space?
|
31
|
+
|
31
32
|
attr_accessor :children, :name, :contents, :attributes, :is_name_space, :is_attribute, :name_space, :parent
|
32
|
-
|
33
|
+
|
33
34
|
def initialize(parent, name, attributes, &contents)
|
34
35
|
@is_name_space = false
|
35
36
|
@children = []
|
@@ -65,16 +66,19 @@ module Glimmer
|
|
65
66
|
def method_missing(symbol, *args, &block)
|
66
67
|
@is_name_space = true
|
67
68
|
parent.children.delete(self) if parent
|
68
|
-
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::
|
69
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::XmlExpression.new) {@tag = super}
|
69
70
|
@tag
|
70
71
|
end
|
72
|
+
|
73
|
+
def name_space_context?
|
74
|
+
attributes[:_name_space_context]
|
75
|
+
end
|
71
76
|
|
72
77
|
def to_xml
|
73
78
|
xml_visitor = XmlVisitor.new
|
74
79
|
DepthFirstSearchIterator.new(self, xml_visitor).iterate
|
75
80
|
xml_visitor.document
|
76
81
|
end
|
77
|
-
alias to_html to_xml
|
78
82
|
alias to_s to_xml
|
79
83
|
|
80
84
|
def text_command(text)
|
@@ -48,21 +48,24 @@ module Glimmer
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def begin_open_tag(node)
|
51
|
+
return if node.name == 'xml' || node.name_space_context?
|
51
52
|
@document += "<"
|
52
53
|
@document += "#{node.name_space.name}:" if node.name_space
|
53
54
|
@document += node.name
|
54
55
|
end
|
55
56
|
|
56
57
|
def end_open_tag(node)
|
58
|
+
return if node.name == 'xml' || node.name_space_context?
|
57
59
|
if (node.contents)
|
58
60
|
@document += ">"
|
59
61
|
else
|
60
62
|
@document += " " if node.attributes.keys.size > 0
|
61
|
-
@document += "/>"
|
63
|
+
@document += " />"
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
67
|
def append_close_tag(node)
|
68
|
+
return if node.name == 'xml' || node.name_space_context?
|
66
69
|
if (node.contents)
|
67
70
|
@document += "</"
|
68
71
|
@document += "#{node.name_space.name}:" if node.name_space
|
@@ -71,6 +74,7 @@ module Glimmer
|
|
71
74
|
end
|
72
75
|
|
73
76
|
def append_attributes(node)
|
77
|
+
return if node.name == 'xml' || node.name_space_context?
|
74
78
|
Glimmer::Config.logger&.debug "Take 3"
|
75
79
|
Glimmer::Config.logger&.debug(node.attributes)
|
76
80
|
node.attributes.each do |attribute, value|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2020-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.
|
19
|
+
version: 1.0.1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 2.0.0
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.0.
|
29
|
+
version: 1.0.1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 2.0.0
|
@@ -62,16 +62,16 @@ dependencies:
|
|
62
62
|
name: puts_debuggerer
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0
|
67
|
+
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0
|
74
|
+
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +174,20 @@ dependencies:
|
|
174
174
|
- - "~>"
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: 0.7.0
|
177
|
+
- !ruby/object:Gem::Dependency
|
178
|
+
name: rake-tui
|
179
|
+
requirement: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
type: :development
|
185
|
+
prerelease: false
|
186
|
+
version_requirements: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
177
191
|
description: Glimmer DSL for XML (& HTML)
|
178
192
|
email: andy.am@gmail.com
|
179
193
|
executables: []
|
@@ -197,7 +211,10 @@ files:
|
|
197
211
|
- lib/glimmer/dsl/xml/tag_expression.rb
|
198
212
|
- lib/glimmer/dsl/xml/text_expression.rb
|
199
213
|
- lib/glimmer/dsl/xml/xml_expression.rb
|
214
|
+
- lib/glimmer/dsl/xml/xml_node_expression.rb
|
200
215
|
- lib/glimmer/xml/depth_first_search_iterator.rb
|
216
|
+
- lib/glimmer/xml/html_node.rb
|
217
|
+
- lib/glimmer/xml/html_visitor.rb
|
201
218
|
- lib/glimmer/xml/name_space_visitor.rb
|
202
219
|
- lib/glimmer/xml/node.rb
|
203
220
|
- lib/glimmer/xml/node_visitor.rb
|
@@ -221,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
238
|
- !ruby/object:Gem::Version
|
222
239
|
version: '0'
|
223
240
|
requirements: []
|
224
|
-
rubygems_version: 3.1.
|
241
|
+
rubygems_version: 3.1.4
|
225
242
|
signing_key:
|
226
243
|
specification_version: 4
|
227
244
|
summary: Glimmer DSL for XML
|