glimmer-dsl-xml 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +161 -0
- data/VERSION +1 -0
- data/lib/glimmer-dsl-xml.rb +3 -0
- data/lib/glimmer/dsl/xml/dsl.rb +23 -0
- data/lib/glimmer/dsl/xml/html_expression.rb +25 -0
- data/lib/glimmer/dsl/xml/meta_expression.rb +23 -0
- data/lib/glimmer/dsl/xml/name_space_expression.rb +37 -0
- data/lib/glimmer/dsl/xml/node_parent_expression.rb +33 -0
- data/lib/glimmer/dsl/xml/tag_expression.rb +29 -0
- data/lib/glimmer/dsl/xml/text_expression.rb +22 -0
- data/lib/glimmer/dsl/xml/xml_expression.rb +21 -0
- data/lib/glimmer/xml/depth_first_search_iterator.rb +22 -0
- data/lib/glimmer/xml/name_space_visitor.rb +21 -0
- data/lib/glimmer/xml/node.rb +75 -0
- data/lib/glimmer/xml/node_visitor.rb +13 -0
- data/lib/glimmer/xml/xml_visitor.rb +65 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4e55c040198e311801f606a3f22656d84805c342fa5c25929d7f28e8cfe9ec4a
|
4
|
+
data.tar.gz: a81f95e9122d5ca908fb88c15d280f9720fc71aa14867cf2debfd9d01fd3e81f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcc5dcca330d69dec00dc3c978944db47526ebf056d3816a8280c6aacf1ab608a85fd5dd5f6ee7983fa755da733393f38fbd3abc806252dd00680ed8be70547a
|
7
|
+
data.tar.gz: 4358fa9b80ec648599fd511f8b82e54f6d0de219d9ea33643a225b2adf32bae288f13bd6e1ce2d1892430fffdd103cedfa8755077ef894530e1b10046b9c932b
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Glimmer DSL for XML 0.1.0 Beta (& HTML)
|
2
|
+
[](http://badge.fury.io/rb/glimmer-dsl-xml)
|
3
|
+
[](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-xml)
|
4
|
+
|
5
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for XML provides Ruby syntax for building XML (eXtensible Markup Language) documents.
|
6
|
+
|
7
|
+
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).
|
8
|
+
|
9
|
+
## Setup
|
10
|
+
|
11
|
+
Please follow these instructions to make the `glimmer` command available on your system.
|
12
|
+
|
13
|
+
### Option 1: Direct Install
|
14
|
+
|
15
|
+
Run this command to install directly:
|
16
|
+
```
|
17
|
+
jgem install glimmer-dsl-xml -v 0.1.0
|
18
|
+
```
|
19
|
+
|
20
|
+
`jgem` is JRuby's version of `gem` command.
|
21
|
+
RVM allows running `gem` as an alias.
|
22
|
+
Otherwise, you may also run `jruby -S gem install ...`
|
23
|
+
|
24
|
+
Add `require 'glimmer-dsl-xml'` to your code after `require glimmer-dsl-swt` or `require glimmer-dsl-opal`
|
25
|
+
|
26
|
+
### Option 2: Bundler
|
27
|
+
|
28
|
+
Add the following to `Gemfile` after `glimmer-dsl-swt` or `glimmer-dsl-opal`:
|
29
|
+
```
|
30
|
+
gem 'glimmer-dsl-xml', '~> 0.1.0'
|
31
|
+
```
|
32
|
+
|
33
|
+
And, then run:
|
34
|
+
```
|
35
|
+
jruby -S bundle install
|
36
|
+
```
|
37
|
+
|
38
|
+
That's it! Requiring the gem activates the Glimmer XML DSL automatically.
|
39
|
+
|
40
|
+
## XML DSL
|
41
|
+
|
42
|
+
Simply start with `html` keyword and add HTML inside its block using Glimmer DSL syntax.
|
43
|
+
Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted HTML output.
|
44
|
+
|
45
|
+
Here are all the Glimmer XML DSL top-level keywords:
|
46
|
+
- `html`
|
47
|
+
- `tag`: enables custom tag creation for exceptional cases by passing tag name as '_name' attribute
|
48
|
+
- `name_space`: enables namespacing html tags
|
49
|
+
|
50
|
+
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')` )
|
51
|
+
|
52
|
+
Example (basic HTML / you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
@xml = html {
|
56
|
+
head {
|
57
|
+
meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
|
58
|
+
}
|
59
|
+
body {
|
60
|
+
h1 { "Hello, World!" }
|
61
|
+
}
|
62
|
+
}
|
63
|
+
puts @xml
|
64
|
+
```
|
65
|
+
|
66
|
+
Output:
|
67
|
+
|
68
|
+
```
|
69
|
+
<html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>
|
70
|
+
```
|
71
|
+
|
72
|
+
Example (explicit XML tag / you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
puts tag(:_name => "DOCUMENT")
|
76
|
+
```
|
77
|
+
|
78
|
+
Output:
|
79
|
+
|
80
|
+
```
|
81
|
+
<DOCUMENT/>
|
82
|
+
```
|
83
|
+
|
84
|
+
Example (XML namespaces using `name_space` keyword / you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
@xml = name_space(:w3c) {
|
88
|
+
html(:id => "thesis", :class => "document") {
|
89
|
+
body(:id => "main") {
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
puts @xml
|
94
|
+
```
|
95
|
+
|
96
|
+
Output:
|
97
|
+
|
98
|
+
```
|
99
|
+
<w3c:html id="thesis" class="document"><w3c:body id="main"></w3c:body></w3c:html>
|
100
|
+
```
|
101
|
+
|
102
|
+
Example (XML namespaces using dot operator / you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
@xml = tag(:_name => "DOCUMENT") {
|
106
|
+
document.body(document.id => "main") {
|
107
|
+
}
|
108
|
+
}
|
109
|
+
puts @xml
|
110
|
+
```
|
111
|
+
|
112
|
+
Output:
|
113
|
+
|
114
|
+
```
|
115
|
+
<DOCUMENT><document:body document:id="main"></document:body></DOCUMENT>
|
116
|
+
```
|
117
|
+
|
118
|
+
## Multi-DSL Support
|
119
|
+
|
120
|
+
Learn more about how to use this DSL alongside other Glimmer DSLs:
|
121
|
+
|
122
|
+
[Glimmer Multi-DSL Support](https://github.com/AndyObtiva/glimmer/tree/master#multi-dsl-support)
|
123
|
+
|
124
|
+
## Help
|
125
|
+
|
126
|
+
### Issues
|
127
|
+
|
128
|
+
You may submit [issues](https://github.com/AndyObtiva/glimmer/issues) on [GitHub](https://github.com/AndyObtiva/glimmer/issues).
|
129
|
+
|
130
|
+
[Click here to submit an issue.](https://github.com/AndyObtiva/glimmer/issues)
|
131
|
+
|
132
|
+
### IRC Channel
|
133
|
+
|
134
|
+
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.
|
135
|
+
|
136
|
+
[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)
|
137
|
+
|
138
|
+
## Feature Suggestions
|
139
|
+
|
140
|
+
These features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions.
|
141
|
+
|
142
|
+
[TODO.md](TODO.md)
|
143
|
+
|
144
|
+
## Change Log
|
145
|
+
|
146
|
+
[CHANGELOG.md](CHANGELOG.md)
|
147
|
+
|
148
|
+
## Contributing
|
149
|
+
|
150
|
+
[CONTRIBUTING.md](CONTRIBUTING.md)
|
151
|
+
|
152
|
+
## Contributors
|
153
|
+
|
154
|
+
* [Andy Maleh](https://github.com/AndyObtiva) (Founder)
|
155
|
+
|
156
|
+
[Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer/graphs/contributors)
|
157
|
+
|
158
|
+
## License
|
159
|
+
|
160
|
+
Copyright (c) 2020 Andy Maleh.
|
161
|
+
See LICENSE.txt for further details.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,23 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
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
|
@@ -0,0 +1,37 @@
|
|
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
|
@@ -0,0 +1,33 @@
|
|
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
|
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,75 @@
|
|
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
|
@@ -0,0 +1,65 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glimmer-dsl-xml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AndyMaleh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.9.0
|
19
|
+
name: glimmer
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.5.0
|
33
|
+
name: rspec-mocks
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.5.0
|
47
|
+
name: rspec
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.8.1
|
61
|
+
name: puts_debuggerer
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 10.1.0
|
75
|
+
- - "<"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 14.0.0
|
78
|
+
name: rake
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 10.1.0
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 14.0.0
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.3.9
|
95
|
+
- - "<"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.0.0
|
98
|
+
name: jeweler
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 2.3.9
|
106
|
+
- - "<"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 3.0.0
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
requirement: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 6.2.1
|
115
|
+
- - "<"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 7.0.0
|
118
|
+
name: rdoc
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 6.2.1
|
126
|
+
- - "<"
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 7.0.0
|
129
|
+
description: Glimmer DSL for XML (& HTML)
|
130
|
+
email: andy.am@gmail.com
|
131
|
+
executables: []
|
132
|
+
extensions: []
|
133
|
+
extra_rdoc_files:
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
files:
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- VERSION
|
140
|
+
- lib/glimmer-dsl-xml.rb
|
141
|
+
- lib/glimmer/dsl/xml/dsl.rb
|
142
|
+
- lib/glimmer/dsl/xml/html_expression.rb
|
143
|
+
- lib/glimmer/dsl/xml/meta_expression.rb
|
144
|
+
- lib/glimmer/dsl/xml/name_space_expression.rb
|
145
|
+
- lib/glimmer/dsl/xml/node_parent_expression.rb
|
146
|
+
- lib/glimmer/dsl/xml/tag_expression.rb
|
147
|
+
- lib/glimmer/dsl/xml/text_expression.rb
|
148
|
+
- lib/glimmer/dsl/xml/xml_expression.rb
|
149
|
+
- lib/glimmer/xml/depth_first_search_iterator.rb
|
150
|
+
- lib/glimmer/xml/name_space_visitor.rb
|
151
|
+
- lib/glimmer/xml/node.rb
|
152
|
+
- lib/glimmer/xml/node_visitor.rb
|
153
|
+
- lib/glimmer/xml/xml_visitor.rb
|
154
|
+
homepage: http://github.com/AndyObtiva/glimmer-dsl-xml
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
metadata: {}
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubygems_version: 3.0.6
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Glimmer DSL for XML
|
177
|
+
test_files: []
|