glimmer-dsl-xml 1.0.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebf5f9c4f6a0a9e7d85e9b32631567f77bf74184feb18c9bcef7aa61090b960f
4
- data.tar.gz: 2633f0f7f517564fb9215554ce5a4ac295666aa975ba86f0353d15bba561479a
3
+ metadata.gz: b7531b79c996e380ee9e921e33240bb043db4e5e194f6cd2d3582fd45f6a316e
4
+ data.tar.gz: b65de2fe406335a7ea4190943cce76736867f4e74507d42d938ab754a8ccbfd2
5
5
  SHA512:
6
- metadata.gz: 53983e3a66b82326f3c6e8eb189dd49a6e5f60d50e56eb4e9ca2a31472a6e95a9f61651dd26a21d14f3c5ada2661e519f5e7ca35d323f43e94d8f9531a2fc599
7
- data.tar.gz: 0275cdecb4f9ee755c074d9f8b0ccc29a03e4c932f7837519e64500c87c32ff0f75bad10e328e2517ceaedd40099dddc9dfc1ad2de5c4b50c18d51d5a15f376c
6
+ metadata.gz: 6f5182930e5e4067e91affa54be7353de536a22bc7619ffda01951231f8d4b4bebeedc7c1293966889704e924384cab16bd1443ddb6ebc257e5f108398cc79f5
7
+ data.tar.gz: 5b3c56a03f721ec475ad45ab0ef0321a8626c3e8efe6b6ce207dcaab35b3ce63a64db040bf837f45749f33c7f19a2511f6d977f325fde9b84112e0b16f78bbb7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.3.0
4
+
5
+ - Upgrade to Glimmer 2.4.1 (automatically gets rid of `invalid log level:` output without needing v1.2.1's fix)
6
+
7
+ ## 1.2.1
8
+
9
+ - Get rid of `invalid log level:` output by setting `GLIMMER_LOGGER_LEVEL` env var before requiring `glimmer`
10
+
11
+ ## 1.2.0
12
+
13
+ - Upgraded to Glimmer 2
14
+
15
+ ## 1.1.0
16
+
17
+ - Support `xml` keyword to produce partial xml/html without the html tag in output
18
+ - Update `html` keyword to add a doctype (`<!DOCTYPE html>`) at the top of rendered content
19
+ - Make `html` keyword automatically not include a doctype or html tag if content does not have HEAD or BODY
20
+ - Make name_space act like an alternative to `xml` keyword, not requiring `xml` or `html` underneath
21
+ - Upgraded to glimmer 1.0.1
22
+
3
23
  ## 1.0.0
4
24
 
5
25
  - Upgraded to Glimmer 1.0.0
data/README.md CHANGED
@@ -1,17 +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.0.0 (& HTML)
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.3.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) 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
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
+ - [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)
15
17
  - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
16
18
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
17
19
 
@@ -23,12 +25,10 @@ Please follow these instructions to make the `glimmer` command available on your
23
25
 
24
26
  Run this command to install directly:
25
27
  ```
26
- jgem install glimmer-dsl-xml -v 1.0.0
28
+ gem install glimmer-dsl-xml -v 1.3.0
27
29
  ```
28
30
 
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 ...`
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 ...`
32
32
 
33
33
  Add `require 'glimmer-dsl-xml'` to your code.
34
34
 
@@ -40,14 +40,16 @@ That's it! Requiring the gem activates the Glimmer XML DSL automatically.
40
40
 
41
41
  Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):
42
42
  ```
43
- gem 'glimmer-dsl-xml', '~> 1.0.0'
43
+ gem 'glimmer-dsl-xml', '~> 1.3.0'
44
44
  ```
45
45
 
46
46
  And, then run:
47
47
  ```
48
- jruby -S bundle install
48
+ bundle install
49
49
  ```
50
50
 
51
+ Note: When using JRuby, prefix with `jruby -S`
52
+
51
53
  Require in your code via Bundler (e.g. `require 'bundler'; Bundler.require`) or add `require 'glimmer-dsl-xml'` to your code.
52
54
 
53
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.
@@ -56,20 +58,31 @@ That's it! Requiring the gem activates the Glimmer XML DSL automatically.
56
58
 
57
59
  ## XML DSL
58
60
 
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.
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.
61
63
 
62
64
  Here are all the Glimmer XML DSL top-level keywords:
63
- - `html`
64
- - `tag`: enables custom tag creation for exceptional cases by passing tag name as '_name' attribute
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 />`)
65
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
66
69
 
67
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')` )
68
71
 
69
- Example (basic HTML):
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:
70
75
 
71
76
  ```ruby
72
- @xml = html {
77
+ require 'glimmer-dsl-xml'
78
+
79
+ include Glimmer
80
+ ```
81
+
82
+ Example (full HTML document):
83
+
84
+ ```ruby
85
+ @html = html {
73
86
  head {
74
87
  meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
75
88
  }
@@ -77,59 +90,94 @@ Example (basic HTML):
77
90
  h1 { "Hello, World!" }
78
91
  }
79
92
  }
80
- puts @xml
93
+
94
+ puts @html
95
+ ```
96
+
97
+ Output:
98
+
99
+ ```
100
+ <!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>
101
+ ```
102
+
103
+ Example (partial HTML fragment):
104
+
105
+ ```ruby
106
+ @html = html {
107
+ h1 { "Hello, World!" }
108
+ }
109
+
110
+ puts @html
81
111
  ```
82
112
 
83
113
  Output:
84
114
 
85
115
  ```
86
- <html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>
116
+ <h1>Hello, World!</h1>
87
117
  ```
88
118
 
89
- Example (explicit XML tag):
119
+ Example (basic XML):
90
120
 
91
121
  ```ruby
92
- puts tag(:_name => "DOCUMENT")
122
+ @xml = xml {
123
+ greeting { "Hello, World!" }
124
+ }
125
+
126
+ puts @xml
93
127
  ```
94
128
 
95
129
  Output:
96
130
 
97
131
  ```
98
- <DOCUMENT/>
132
+ <greeting>Hello, World!</greeting>
99
133
  ```
100
134
 
101
135
  Example (XML namespaces using `name_space` keyword):
102
136
 
103
137
  ```ruby
104
- @xml = name_space(:w3c) {
105
- html(:id => "thesis", :class => "document") {
106
- body(:id => "main") {
138
+ @xml = name_space(:acme) {
139
+ product(:id => "thesis", :class => "document") {
140
+ component(:id => "main") {
107
141
  }
108
142
  }
109
143
  }
144
+
110
145
  puts @xml
111
146
  ```
112
147
 
113
148
  Output:
114
149
 
115
150
  ```
116
- <w3c:html id="thesis" class="document"><w3c:body id="main"></w3c:body></w3c:html>
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
- @xml = tag(:_name => "DOCUMENT") {
123
- document.body(document.id => "main") {
157
+ @xml = xml {
158
+ document.body(document.id => "main") {
159
+ }
124
160
  }
125
- }
126
- puts @xml
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"}
127
175
  ```
128
176
 
129
177
  Output:
130
178
 
131
179
  ```
132
- <DOCUMENT><document:body document:id="main"></document:body></DOCUMENT>
180
+ <p>p is a reserved keyword in Ruby</p>
133
181
  ```
134
182
 
135
183
  ## Multi-DSL Support
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.3.0
@@ -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/xml_expression'
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
- xml
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
- xml_expression.interpret(parent, keyword, *args, &block)
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
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2020 - Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
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
@@ -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
- node = block.call
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)
44
51
  unless node.is_a?(String)
45
- name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(args[0].to_s)
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
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2020 - Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
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
@@ -30,8 +30,8 @@ module Glimmer
30
30
  include ParentExpression
31
31
  include Glimmer
32
32
 
33
- def add_content(parent, &block)
34
- return_value = block.call(parent)
33
+ def add_content(parent, keyword, *args, &block)
34
+ return_value = block.call(parent)
35
35
  if !return_value.is_a?(Glimmer::XML::Node) and !parent.children.include?(return_value)
36
36
  text = return_value.to_s
37
37
  first_match = text.match(/[#][^{]+[{][^}]+[}]/)
@@ -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/expression'
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 < Expression
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
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2020 - Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
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
@@ -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::HtmlExpression.new) {@tag = super}
69
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::XmlExpression.new, name, attributes) {@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|
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2020 - Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
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
@@ -21,4 +21,5 @@
21
21
 
22
22
  $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
23
23
 
24
+ require 'glimmer'
24
25
  require 'glimmer/dsl/xml/dsl'
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.3.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-09-18 00:00:00.000000000 Z
11
+ date: 2021-11-10 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
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 1.0.0
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: 2.0.0
19
+ version: 2.4.1
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: 1.0.0
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: 2.0.0
26
+ version: 2.4.1
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rspec-mocks
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -62,16 +56,16 @@ dependencies:
62
56
  name: puts_debuggerer
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - "~>"
59
+ - - ">="
66
60
  - !ruby/object:Gem::Version
67
- version: 0.8.2
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.8.2
68
+ version: '0'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: rake
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -174,6 +168,20 @@ 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: []
@@ -197,7 +205,10 @@ files:
197
205
  - lib/glimmer/dsl/xml/tag_expression.rb
198
206
  - lib/glimmer/dsl/xml/text_expression.rb
199
207
  - lib/glimmer/dsl/xml/xml_expression.rb
208
+ - lib/glimmer/dsl/xml/xml_node_expression.rb
200
209
  - lib/glimmer/xml/depth_first_search_iterator.rb
210
+ - lib/glimmer/xml/html_node.rb
211
+ - lib/glimmer/xml/html_visitor.rb
201
212
  - lib/glimmer/xml/name_space_visitor.rb
202
213
  - lib/glimmer/xml/node.rb
203
214
  - lib/glimmer/xml/node_visitor.rb
@@ -221,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
232
  - !ruby/object:Gem::Version
222
233
  version: '0'
223
234
  requirements: []
224
- rubygems_version: 3.1.2
235
+ rubygems_version: 3.2.22
225
236
  signing_key:
226
237
  specification_version: 4
227
238
  summary: Glimmer DSL for XML