glimmer-dsl-xml 1.3.1 → 1.4.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 +10 -0
- data/LICENSE.txt +1 -1
- data/README.md +99 -16
- data/VERSION +1 -1
- data/bin/html_to_glimmer +18 -0
- data/lib/glimmer/dsl/xml/dsl.rb +5 -4
- data/lib/glimmer/dsl/xml/html_expression.rb +5 -5
- data/lib/glimmer/dsl/xml/meta_expression.rb +5 -5
- data/lib/glimmer/dsl/xml/name_space_expression.rb +1 -1
- data/lib/glimmer/dsl/xml/node_parent_expression.rb +1 -1
- data/lib/glimmer/dsl/xml/p_expression.rb +46 -0
- data/lib/glimmer/dsl/xml/tag_expression.rb +4 -4
- data/lib/glimmer/dsl/xml/text_expression.rb +4 -4
- data/lib/glimmer/dsl/xml/xml_expression.rb +4 -4
- data/lib/glimmer/dsl/xml/xml_node_expression.rb +4 -4
- data/lib/glimmer/xml/depth_first_search_iterator.rb +4 -4
- data/lib/glimmer/xml/html_node.rb +5 -6
- data/lib/glimmer/xml/html_to_glimmer_converter.rb +127 -0
- data/lib/glimmer/xml/html_visitor.rb +5 -5
- data/lib/glimmer/xml/name_space_visitor.rb +4 -4
- data/lib/glimmer/xml/node.rb +1 -1
- data/lib/glimmer/xml/node_visitor.rb +4 -4
- data/lib/glimmer/xml/xml_visitor.rb +1 -1
- data/lib/glimmer-dsl-xml.rb +2 -2
- metadata +17 -7
- /data/lib/{ext → glimmer-dsl-xml-ext}/glimmer/config.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 299589b2fe8ece942e67b330eaf32929870da8faa32b2ecf3dab2c92c3d28b13
|
4
|
+
data.tar.gz: dd4742f77cfe0e81299a80539069989e7315b04c276e07266403eac3d8758f91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96b1e96fed543c46ee0c04a4e3b0d2ffcc25d7b7691df64f7335eb12b80d770f5254e47ce711961e593a9ba21bb976197b0253912c38340e6bf324a126c072bc
|
7
|
+
data.tar.gz: 70af6db063691aeaa12342a4a4ada5eab28e016718cccdc41ab3b1cbb4916db83066c25353a01d9c6ff45eaa85a83387a1419aa61b7cbacee7a5247a66d16d13
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.4.0
|
4
|
+
|
5
|
+
- `html_to_glimmer` converter command for automatically converting HTML to Glimmer DSL Ruby code
|
6
|
+
- Support `p` keyword directly (without having to use the custom `tag` keyword like `tag(:_name => "p")`)
|
7
|
+
|
8
|
+
## 1.3.2
|
9
|
+
|
10
|
+
- Relaxed glimmer dependency to between 2.4.1 and 3.0.0
|
11
|
+
- Fix issue with `Glimmer::Config.xml_attribute_underscore` not available due to a conflict with other Glimmer gems having `ext` directory, by renaming this gem's `ext` directory to `glimmer-dsl-xml-ext`
|
12
|
+
|
3
13
|
## 1.3.1
|
4
14
|
|
5
15
|
- Support `Glimmer::Config.xml_attribute_underscore = '-'` to auto convert xml attribute underscores to dashes (or any character) only in symbols, but not strings
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,21 +1,17 @@
|
|
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 & HTML 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 & HTML 1.4.0
|
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) and HTML documents.
|
8
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for XML provides Ruby syntax for building XML (eXtensible Markup Language) and HTML documents, included in [Glimmer DSL for Web](https://github.com/AndyObtiva/glimmer-dsl-web) (Ruby in the Browser Web Frontend Framework) to use in Rails Frontend Development. It used to be part of the [Glimmer](https://github.com/AndyObtiva/glimmer) library (created in 2007), but eventually got extracted into its own project. The Ruby gem also includes an [HTML to Glimmer Converter](#html-to-glimmer-converter) (`html_to_glimmer`) to automatically convert legacy HTML code into Glimmer DSL syntax.
|
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-dsl-swt/
|
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/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#browser-widget).
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
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)
|
17
|
-
- [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
|
18
|
-
- [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
|
12
|
+
Otherwise, it is also used in the development of [Glimmer DSL for Opal](https://github.com/AndyObtiva/glimmer-dsl-opal).
|
13
|
+
|
14
|
+
Learn more about the differences between various [Glimmer](https://github.com/AndyObtiva/glimmer) DSLs by looking at the **[Glimmer DSL Comparison Table](https://github.com/AndyObtiva/glimmer#glimmer-dsl-comparison-table)**.
|
19
15
|
|
20
16
|
## Setup
|
21
17
|
|
@@ -25,7 +21,7 @@ Please follow these instructions to make the `glimmer` command available on your
|
|
25
21
|
|
26
22
|
Run this command to install directly:
|
27
23
|
```
|
28
|
-
gem install glimmer-dsl-xml -v 1.
|
24
|
+
gem install glimmer-dsl-xml -v 1.4.0
|
29
25
|
```
|
30
26
|
|
31
27
|
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 ...`
|
@@ -40,7 +36,7 @@ That's it! Requiring the gem activates the Glimmer XML DSL automatically.
|
|
40
36
|
|
41
37
|
Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):
|
42
38
|
```
|
43
|
-
gem 'glimmer-dsl-xml', '~> 1.
|
39
|
+
gem 'glimmer-dsl-xml', '~> 1.4.0'
|
44
40
|
```
|
45
41
|
|
46
42
|
And, then run:
|
@@ -65,7 +61,7 @@ Here are all the Glimmer XML DSL top-level keywords:
|
|
65
61
|
- `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
62
|
- `xml`: renders XML/XHTML content (e.g. `xml {span {'Hello'}; br}.to_s` renders `<span>Hello</span><br />`)
|
67
63
|
- `name_space`: enables namespacing html tags
|
68
|
-
- `tag`: enables custom tag creation for exceptional cases (e.g. `
|
64
|
+
- `tag`: enables custom tag creation for exceptional cases (e.g. `acme:window` as reserved Ruby keyword) by passing tag name as '_name' attribute
|
69
65
|
|
70
66
|
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')` )
|
71
67
|
|
@@ -171,13 +167,100 @@ Output:
|
|
171
167
|
Example (custom tag):
|
172
168
|
|
173
169
|
```ruby
|
174
|
-
puts tag(:_name => "
|
170
|
+
puts tag(:_name => "acme:window") {"This is a window under acme inc."}
|
175
171
|
```
|
176
172
|
|
177
173
|
Output:
|
178
174
|
|
179
175
|
```
|
180
|
-
<
|
176
|
+
<acme:window>This is a window under acme inc.</acme:window>
|
177
|
+
```
|
178
|
+
|
179
|
+
### HTML to Glimmer Converter
|
180
|
+
|
181
|
+
The Ruby gem includes a HTML to Glimmer converter (`html_to_glimmer`) to automatically convert legacy HTML code into Glimmer DSL syntax.
|
182
|
+
|
183
|
+
Prerequisite: the `nokogiri` Ruby gem. If not already installed, run `gem install nokogiri` before using `html_to_glimmer`.
|
184
|
+
|
185
|
+
Script:
|
186
|
+
|
187
|
+
[bin/html_to_glimmer](/bin/html_to_glimmer)
|
188
|
+
|
189
|
+
Usage:
|
190
|
+
|
191
|
+
```
|
192
|
+
html_to_glimmer path_to_html_file
|
193
|
+
```
|
194
|
+
|
195
|
+
Example:
|
196
|
+
|
197
|
+
Suppose we have an HTML file called `input.html`:
|
198
|
+
|
199
|
+
```html
|
200
|
+
<html style='max-height: 100%'>
|
201
|
+
<body style="max-height: 100%; font: 'Times New Roman', Arial;">
|
202
|
+
<h1 id="top-header" class="header" data-owner='John "Bonham" Doe'>Welcome</h1>
|
203
|
+
<p>It is good to have <strong>you</strong> in our <strong><em>platform</em></strong>!</p>
|
204
|
+
<form action="/owner" method="post">
|
205
|
+
<input type="text" value="you" />
|
206
|
+
</form>
|
207
|
+
</body>
|
208
|
+
</html>
|
209
|
+
```
|
210
|
+
|
211
|
+
We can run this command:
|
212
|
+
|
213
|
+
```
|
214
|
+
html_to_glimmer input.html
|
215
|
+
```
|
216
|
+
|
217
|
+
Printout:
|
218
|
+
|
219
|
+
```
|
220
|
+
Converting from HTML syntax to Glimmer DSL Ruby syntax for input file: input.html
|
221
|
+
Converted output file: input.html.glimmer.rb
|
222
|
+
```
|
223
|
+
|
224
|
+
Output file (`input.html.glimmer.rb`) is a runnable Ruby file containing Glimmer DSL for XML & HTML syntax:
|
225
|
+
|
226
|
+
```rb
|
227
|
+
require 'glimmer-dsl-xml'
|
228
|
+
|
229
|
+
include Glimmer
|
230
|
+
|
231
|
+
html_document = xml {
|
232
|
+
html(style: 'max-height: 100%') {
|
233
|
+
body(style: "max-height: 100%; font: 'Times New Roman', Arial;") {
|
234
|
+
h1(id: 'top-header', class: 'header', 'data-owner': 'John "Bonham" Doe') {
|
235
|
+
"Welcome"
|
236
|
+
}
|
237
|
+
p {
|
238
|
+
span {
|
239
|
+
"It is good to have "
|
240
|
+
}
|
241
|
+
strong {
|
242
|
+
"you"
|
243
|
+
}
|
244
|
+
span {
|
245
|
+
" in our "
|
246
|
+
}
|
247
|
+
strong {
|
248
|
+
em {
|
249
|
+
"platform"
|
250
|
+
}
|
251
|
+
}
|
252
|
+
span {
|
253
|
+
"!"
|
254
|
+
}
|
255
|
+
}
|
256
|
+
form(action: '/owner', method: 'post') {
|
257
|
+
input(type: 'text', value: 'you')
|
258
|
+
}
|
259
|
+
}
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
puts html_document.to_s
|
181
264
|
```
|
182
265
|
|
183
266
|
## Glimmer Config
|
@@ -281,7 +364,7 @@ These features have been suggested. You might see them in a future version of Gl
|
|
281
364
|
|
282
365
|
[MIT](LICENSE.txt)
|
283
366
|
|
284
|
-
Copyright (c) 2020 - Andy Maleh.
|
367
|
+
Copyright (c) 2020-2023 - Andy Maleh.
|
285
368
|
|
286
369
|
--
|
287
370
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/bin/html_to_glimmer
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/glimmer/xml/html_to_glimmer_converter'
|
4
|
+
|
5
|
+
usage = "***Glimmer DSL for XML & HTML - HTML to Glimmer Converter***\nPrerequisite: `nokogiri` gem (install by running: gem install nokogiri)\nUsage: html_to_glimmer path_to_html_file"
|
6
|
+
|
7
|
+
if ARGV.empty?
|
8
|
+
puts usage
|
9
|
+
else
|
10
|
+
html_file_path = ARGV.last
|
11
|
+
puts "Converting from HTML syntax to Glimmer DSL Ruby syntax for input file: #{html_file_path}"
|
12
|
+
html = File.read(html_file_path)
|
13
|
+
converter = Glimmer::XML::HTMLToGlimmerConverter.new
|
14
|
+
glimmer = converter.convert(html)
|
15
|
+
glimmer_file_path = "#{html_file_path}.glimmer.rb"
|
16
|
+
File.write(glimmer_file_path, glimmer)
|
17
|
+
puts "Converted output file: #{glimmer_file_path}"
|
18
|
+
end
|
data/lib/glimmer/dsl/xml/dsl.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -27,6 +27,7 @@ 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'
|
30
|
+
require 'glimmer/dsl/xml/p_expression'
|
30
31
|
|
31
32
|
module Glimmer
|
32
33
|
module DSL
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -27,7 +27,7 @@ require 'glimmer/xml/html_node'
|
|
27
27
|
module Glimmer
|
28
28
|
module DSL
|
29
29
|
module XML
|
30
|
-
# This static html expression flips the DSL switch on for
|
30
|
+
# This static html expression flips the DSL switch on for
|
31
31
|
# XML DSL in Glimmer
|
32
32
|
class HtmlExpression < StaticExpression
|
33
33
|
include TopLevelExpression
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -26,7 +26,7 @@ require 'glimmer/dsl/static_expression'
|
|
26
26
|
module Glimmer
|
27
27
|
module DSL
|
28
28
|
module XML
|
29
|
-
# This static html expression flips the DSL switch on for
|
29
|
+
# This static html expression flips the DSL switch on for
|
30
30
|
# XML DSL in Glimmer
|
31
31
|
class MetaExpression < StaticExpression
|
32
32
|
include NodeParentExpression
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (c) 2020-2023 - 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/static_expression'
|
24
|
+
require 'glimmer/xml/node'
|
25
|
+
|
26
|
+
module Kernel
|
27
|
+
alias pi p
|
28
|
+
end
|
29
|
+
|
30
|
+
module Glimmer
|
31
|
+
module DSL
|
32
|
+
module XML
|
33
|
+
class PExpression < StaticExpression
|
34
|
+
include NodeParentExpression
|
35
|
+
|
36
|
+
def can_interpret?(parent, keyword, *args, &block)
|
37
|
+
keyword == 'p' && parent.is_a?(Glimmer::XML::Node)
|
38
|
+
end
|
39
|
+
|
40
|
+
def interpret(parent, keyword, *args, &block)
|
41
|
+
Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
4
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
4
|
# a copy of this software and associated documentation files (the
|
6
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -8,10 +7,10 @@
|
|
8
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
10
9
|
# the following conditions:
|
11
|
-
#
|
10
|
+
#
|
12
11
|
# The above copyright notice and this permission notice shall be
|
13
12
|
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
13
|
+
#
|
15
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -33,7 +32,7 @@ module Glimmer
|
|
33
32
|
node_visitor.document
|
34
33
|
end
|
35
34
|
alias to_html to_xml
|
36
|
-
alias to_s to_xml
|
35
|
+
alias to_s to_xml
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Copyright (c) 2020-2024 - 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
|
+
begin
|
23
|
+
require 'nokogiri'
|
24
|
+
rescue LoadError
|
25
|
+
puts 'Please install the `nokogiri` gem by running: gem install nokogiri'
|
26
|
+
raise 'The `nokogiri` gem is not installed!'
|
27
|
+
end
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module XML
|
31
|
+
class HTMLToGlimmerConverter
|
32
|
+
def convert(html)
|
33
|
+
glimmer = ''
|
34
|
+
glimmer += "require 'glimmer-dsl-xml'\n\n"
|
35
|
+
glimmer += "include Glimmer\n\n"
|
36
|
+
glimmer += "html_document = xml {\n"
|
37
|
+
glimmer += indent_lines(convert_html(html))
|
38
|
+
glimmer += "}\n\n"
|
39
|
+
glimmer += "puts html_document.to_s\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def convert_html(html)
|
45
|
+
html_doc = Nokogiri::HTML(html)
|
46
|
+
glimmer = ''
|
47
|
+
html_doc.children.select(&:element?).each do |element|
|
48
|
+
glimmer += convert_element(element)
|
49
|
+
end
|
50
|
+
glimmer
|
51
|
+
end
|
52
|
+
|
53
|
+
def convert_element(element)
|
54
|
+
children_count = element.children.size
|
55
|
+
glimmer = ''
|
56
|
+
glimmer += "#{element.node_name}#{convert_attributes(element)}" if element.element?
|
57
|
+
glimmer += " {\n" if element.element? && children_count > 0
|
58
|
+
if element.children.size == 1 && element.children.first.text?
|
59
|
+
glimmer += indent_lines(convert_text(element.children.first))
|
60
|
+
else
|
61
|
+
element.children.each do |child|
|
62
|
+
if child.element?
|
63
|
+
glimmer += indent_lines(convert_element(child))
|
64
|
+
elsif child.text?
|
65
|
+
glimmer += indent_lines(convert_span(child))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
glimmer += "}\n" if element.element? && children_count > 0
|
70
|
+
glimmer += "\n" if element.element? && children_count == 0
|
71
|
+
glimmer
|
72
|
+
end
|
73
|
+
|
74
|
+
def convert_span(text_element)
|
75
|
+
text_content = indent_lines(convert_text(text_element))
|
76
|
+
return '' if text_content.strip.empty?
|
77
|
+
glimmer = ''
|
78
|
+
glimmer += "span {\n"
|
79
|
+
glimmer += text_content
|
80
|
+
glimmer += "}\n"
|
81
|
+
glimmer
|
82
|
+
end
|
83
|
+
|
84
|
+
def convert_text(text_element)
|
85
|
+
text_content = text_element.to_s
|
86
|
+
if text_content.strip.empty?
|
87
|
+
''
|
88
|
+
else
|
89
|
+
"#{text_element.to_s.dump}\n"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def convert_attributes(element)
|
94
|
+
attributes_string = element.attributes.to_a.map do |attribute, value|
|
95
|
+
"#{normalize_attribute(attribute)}: #{normalize_value(value)}"
|
96
|
+
end.join(', ')
|
97
|
+
return '' if attributes_string.strip.empty?
|
98
|
+
glimmer = ''
|
99
|
+
glimmer += '('
|
100
|
+
glimmer += attributes_string
|
101
|
+
glimmer += ')'
|
102
|
+
glimmer
|
103
|
+
end
|
104
|
+
|
105
|
+
def normalize_attribute(attribute)
|
106
|
+
if attribute.include?('-')
|
107
|
+
"'#{attribute}'"
|
108
|
+
else
|
109
|
+
attribute
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def normalize_value(value)
|
114
|
+
value = value.to_s
|
115
|
+
if value.include?("'")
|
116
|
+
"\"#{value}\""
|
117
|
+
else
|
118
|
+
"'#{value}'"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def indent_lines(multi_line_string)
|
123
|
+
multi_line_string.lines.map { |line| " #{line}" }.join
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -50,7 +50,7 @@ module Glimmer
|
|
50
50
|
def append_close_tag(node)
|
51
51
|
return unless render_html_tag?(node)
|
52
52
|
super(node)
|
53
|
-
end
|
53
|
+
end
|
54
54
|
|
55
55
|
def append_attributes(node)
|
56
56
|
return unless render_html_tag?(node)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
data/lib/glimmer/xml/node.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
2
|
-
#
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
data/lib/glimmer-dsl-xml.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2020 - Andy Maleh
|
1
|
+
# Copyright (c) 2020-2023 - Andy Maleh
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
@@ -23,5 +23,5 @@
|
|
23
23
|
$LOAD_PATH.unshift(File.expand_path('..', __FILE__))
|
24
24
|
|
25
25
|
require 'glimmer'
|
26
|
-
require 'ext/glimmer/config'
|
26
|
+
require 'glimmer-dsl-xml-ext/glimmer/config'
|
27
27
|
require 'glimmer/dsl/xml/dsl'
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
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.4.0
|
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: 2024-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.4.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 2.4.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rspec-mocks
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,7 +190,8 @@ dependencies:
|
|
184
190
|
version: '0'
|
185
191
|
description: Glimmer DSL for XML & HTML
|
186
192
|
email: andy.am@gmail.com
|
187
|
-
executables:
|
193
|
+
executables:
|
194
|
+
- html_to_glimmer
|
188
195
|
extensions: []
|
189
196
|
extra_rdoc_files:
|
190
197
|
- CHANGELOG.md
|
@@ -196,19 +203,22 @@ files:
|
|
196
203
|
- LICENSE.txt
|
197
204
|
- README.md
|
198
205
|
- VERSION
|
199
|
-
-
|
206
|
+
- bin/html_to_glimmer
|
207
|
+
- lib/glimmer-dsl-xml-ext/glimmer/config.rb
|
200
208
|
- lib/glimmer-dsl-xml.rb
|
201
209
|
- lib/glimmer/dsl/xml/dsl.rb
|
202
210
|
- lib/glimmer/dsl/xml/html_expression.rb
|
203
211
|
- lib/glimmer/dsl/xml/meta_expression.rb
|
204
212
|
- lib/glimmer/dsl/xml/name_space_expression.rb
|
205
213
|
- lib/glimmer/dsl/xml/node_parent_expression.rb
|
214
|
+
- lib/glimmer/dsl/xml/p_expression.rb
|
206
215
|
- lib/glimmer/dsl/xml/tag_expression.rb
|
207
216
|
- lib/glimmer/dsl/xml/text_expression.rb
|
208
217
|
- lib/glimmer/dsl/xml/xml_expression.rb
|
209
218
|
- lib/glimmer/dsl/xml/xml_node_expression.rb
|
210
219
|
- lib/glimmer/xml/depth_first_search_iterator.rb
|
211
220
|
- lib/glimmer/xml/html_node.rb
|
221
|
+
- lib/glimmer/xml/html_to_glimmer_converter.rb
|
212
222
|
- lib/glimmer/xml/html_visitor.rb
|
213
223
|
- lib/glimmer/xml/name_space_visitor.rb
|
214
224
|
- lib/glimmer/xml/node.rb
|
@@ -233,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
243
|
- !ruby/object:Gem::Version
|
234
244
|
version: '0'
|
235
245
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
246
|
+
rubygems_version: 3.5.3
|
237
247
|
signing_key:
|
238
248
|
specification_version: 4
|
239
249
|
summary: Glimmer DSL for XML
|
File without changes
|