zenml 1.1.2 → 1.2.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 +4 -4
- data/source/zenml/converter.rb +26 -0
- data/source/zenml/utility.rb +12 -1
- data/source/zenml.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe7549c25553e14b86955e3f8cd6845344034ff2b291c8c6d80bc1ee9c5cda4
|
4
|
+
data.tar.gz: 3ba34fd9bf168248bfff57d97651a3789cd5d0f05878167a6881bd1ae68275b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b198af5998ddddc17c1abea09194f49f1a005136bb60dce503a1daef8aabc149074371e3e814251330077064794b797cfef3478681787c62de0e0806498f45e7
|
7
|
+
data.tar.gz: 8016d739c4aed76219cefc5299333a6bb8cd95619f4ae83dd07d6ba7671800e7cb58e6ba5772d5533983332feb11e78dfb5fb37f987baf4a2c2daec6c7c7bb94
|
data/source/zenml/converter.rb
CHANGED
@@ -8,6 +8,8 @@ include REXML
|
|
8
8
|
|
9
9
|
class ZenithalConverter
|
10
10
|
|
11
|
+
SINGLETON_NAMES = ["br", "img", "hr", "meta", "input", "embed", "area", "base", "link"]
|
12
|
+
|
11
13
|
attr_reader :configs
|
12
14
|
|
13
15
|
def initialize(document, type = :node)
|
@@ -121,4 +123,28 @@ class ZenithalConverter
|
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
126
|
+
def self.simple_html(document)
|
127
|
+
converter = ZenithalConverter.new(document, :text)
|
128
|
+
converter.add([//], [""]) do |element|
|
129
|
+
close = !SINGLETON_NAMES.include?(element.name)
|
130
|
+
html = "<#{element.name}"
|
131
|
+
element.attributes.each_attribute do |attribute|
|
132
|
+
html << " #{attribute.name}='#{attribute.to_s}'"
|
133
|
+
end
|
134
|
+
html << ">"
|
135
|
+
if close
|
136
|
+
html << apply(element, "")
|
137
|
+
html << "</#{element.name}>"
|
138
|
+
end
|
139
|
+
if element.name == "html"
|
140
|
+
html = "<!DOCTYPE html>\n\n" + html
|
141
|
+
end
|
142
|
+
next html
|
143
|
+
end
|
144
|
+
converter.add_default(nil) do |text|
|
145
|
+
next text.to_s
|
146
|
+
end
|
147
|
+
return converter
|
148
|
+
end
|
149
|
+
|
124
150
|
end
|
data/source/zenml/utility.rb
CHANGED
@@ -54,6 +54,17 @@ class Element
|
|
54
54
|
return texts
|
55
55
|
end
|
56
56
|
|
57
|
+
def inner_text(compress = false)
|
58
|
+
text = XPath.match(self, ".//text()").map{|s| s.value}.join("")
|
59
|
+
if compress
|
60
|
+
text.gsub!(/\r/, "")
|
61
|
+
text.gsub!(/\n\s*/, " ")
|
62
|
+
text.gsub!(/\s+/, " ")
|
63
|
+
text.strip!
|
64
|
+
end
|
65
|
+
return text
|
66
|
+
end
|
67
|
+
|
57
68
|
def self.build(name, &block)
|
58
69
|
element = Element.new(name)
|
59
70
|
block.call(element)
|
@@ -132,7 +143,7 @@ end
|
|
132
143
|
class String
|
133
144
|
|
134
145
|
def ~
|
135
|
-
return Text.new(self, true, nil,
|
146
|
+
return Text.new(self, true, nil, false)
|
136
147
|
end
|
137
148
|
|
138
149
|
end
|
data/source/zenml.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zenml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ziphil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
This gem serves a tool for parsing a document written in ZenML, an alternative new syntax for XML, to an XML node tree.
|