zenml 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/source/zenml.rb +11 -9
- data/source/zenml/converter.rb +8 -13
- data/source/zenml/error.rb +1 -1
- data/source/zenml/parser.rb +19 -24
- data/source/zenml/parser_utility.rb +8 -8
- data/source/zenml/reader.rb +1 -1
- data/source/zenml/utility.rb +18 -22
- 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: bc8d8a0fee635054ffabb1fc90ba5b8ed78e6225f7932e2aa777a79274a5d502
|
4
|
+
data.tar.gz: 37c86142fdae037d59d5a27b661fdd5c0689a9bd8a652b910bdc30e82e2d63f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecc6096ee7aca2992e8e3eb2f9d8d6dd703bca5d00a53c8d5b1eba2ccf256ac466c41ee97a795eb4afea9d55bdb576cc5d0133314e788a3ed8cf0d82aa8ea69b
|
7
|
+
data.tar.gz: e9aa413207a31753012f8e814fc63ac7ec7d7fdd4ea4a57312d2b4698d221fd3e0377556902367328dc4dd64ee4495d59461bcc01ebd077a8062cec90e80b120
|
data/source/zenml.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
|
4
|
-
|
4
|
+
module Zenithal
|
5
5
|
|
6
|
+
VERSION = "1.5.1"
|
7
|
+
VERSION_ARRAY = VERSION.split(/\./).map(&:to_i)
|
6
8
|
|
7
|
-
|
9
|
+
end
|
8
10
|
|
9
|
-
VERSION = "1.5.0"
|
10
11
|
|
11
|
-
|
12
|
-
require 'zenml/reader'
|
13
|
-
require 'zenml/parser_utility'
|
14
|
-
require 'zenml/parser'
|
15
|
-
require 'zenml/converter'
|
12
|
+
require 'rexml/document'
|
16
13
|
|
17
|
-
|
14
|
+
require 'zenml/error'
|
15
|
+
require 'zenml/reader'
|
16
|
+
require 'zenml/parser_utility'
|
17
|
+
require 'zenml/parser'
|
18
|
+
require 'zenml/converter'
|
19
|
+
require 'zenml/utility'
|
data/source/zenml/converter.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
require 'rexml/document'
|
6
|
-
include REXML
|
7
|
-
|
8
|
-
|
9
|
-
class ZenithalConverter
|
4
|
+
class Zenithal::ZenithalConverter
|
10
5
|
|
11
6
|
SINGLETON_NAMES = ["br", "img", "hr", "meta", "input", "embed", "area", "base", "link"]
|
12
7
|
|
@@ -39,7 +34,7 @@ class ZenithalConverter
|
|
39
34
|
if @type == :text
|
40
35
|
document = convert_element(@document.root, initial_scope)
|
41
36
|
else
|
42
|
-
document = Document.new
|
37
|
+
document = REXML::Document.new
|
43
38
|
children = convert_element(@document.root, initial_scope)
|
44
39
|
children.each do |child|
|
45
40
|
document.add(child)
|
@@ -74,12 +69,12 @@ class ZenithalConverter
|
|
74
69
|
nodes = empty_nodes
|
75
70
|
element.children.each do |child|
|
76
71
|
case child
|
77
|
-
when Element
|
72
|
+
when REXML::Element
|
78
73
|
result_nodes = convert_element(child, scope, *args)
|
79
74
|
if result_nodes
|
80
75
|
nodes << result_nodes
|
81
76
|
end
|
82
|
-
when Text
|
77
|
+
when REXML::Text
|
83
78
|
result_nodes = convert_text(child, scope, *args)
|
84
79
|
if result_nodes
|
85
80
|
nodes << result_nodes
|
@@ -93,12 +88,12 @@ class ZenithalConverter
|
|
93
88
|
nodes = empty_nodes
|
94
89
|
element.each_xpath(xpath) do |child|
|
95
90
|
case child
|
96
|
-
when Element
|
91
|
+
when REXML::Element
|
97
92
|
result_nodes = convert_element(child, scope, *args)
|
98
93
|
if result_nodes
|
99
94
|
nodes << result_nodes
|
100
95
|
end
|
101
|
-
when Text
|
96
|
+
when REXML::Text
|
102
97
|
result_nodes = convert_text(child, scope, *args)
|
103
98
|
if result_nodes
|
104
99
|
nodes << result_nodes
|
@@ -136,7 +131,7 @@ class ZenithalConverter
|
|
136
131
|
end
|
137
132
|
|
138
133
|
def empty_nodes
|
139
|
-
return (@type == :text) ? "" : Nodes[]
|
134
|
+
return (@type == :text) ? "" : REXML::Nodes[]
|
140
135
|
end
|
141
136
|
|
142
137
|
# Override this method to customise how to initialise the variable hash.
|
@@ -147,7 +142,7 @@ class ZenithalConverter
|
|
147
142
|
|
148
143
|
# Returns a simple converter that converts an XML document to the equivalent HTML document.
|
149
144
|
def self.simple_html(document)
|
150
|
-
converter = ZenithalConverter.new(document, :text)
|
145
|
+
converter = Zenithal::ZenithalConverter.new(document, :text)
|
151
146
|
converter.add([//], [""]) do |element|
|
152
147
|
close = !SINGLETON_NAMES.include?(element.name)
|
153
148
|
html = "<#{element.name}"
|
data/source/zenml/error.rb
CHANGED
data/source/zenml/parser.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
require 'rexml/document'
|
6
|
-
include REXML
|
7
|
-
|
8
|
-
|
9
|
-
module ZenithalParserMethod
|
4
|
+
module Zenithal::ZenithalParserMethod
|
10
5
|
|
11
6
|
ELEMENT_START = "\\"
|
12
7
|
MACRO_START = "&"
|
@@ -23,7 +18,7 @@ module ZenithalParserMethod
|
|
23
18
|
SPECIAL_ELEMENT_ENDS = {:brace => "}", :bracket => "]", :slash => "/"}
|
24
19
|
COMMENT_DELIMITER = "#"
|
25
20
|
SYSTEM_INSTRUCTION_NAME = "zml"
|
26
|
-
|
21
|
+
MARK_CHARS = {:instruction => "?", :trim => "*", :verbal => "~", :multiple => "+"}
|
27
22
|
ESCAPE_CHARS = ["&", "<", ">", "'", "\"", "{", "}", "[", "]", "/", "\\", "|", "`", "#"]
|
28
23
|
SPACE_CHARS = [0x20, 0x9, 0xD, 0xA]
|
29
24
|
VALID_FIRST_IDENTIFIER_CHARS = [
|
@@ -58,7 +53,7 @@ module ZenithalParserMethod
|
|
58
53
|
private
|
59
54
|
|
60
55
|
def parse_document
|
61
|
-
document = Document.new
|
56
|
+
document = REXML::Document.new
|
62
57
|
children = parse_nodes({})
|
63
58
|
if @exact
|
64
59
|
parse_eof
|
@@ -75,7 +70,7 @@ module ZenithalParserMethod
|
|
75
70
|
nodes = options[:plugin].parse
|
76
71
|
elsif options[:verbal]
|
77
72
|
raw_nodes = many(->{parse_text(options)})
|
78
|
-
nodes = raw_nodes.inject(Nodes[], :<<)
|
73
|
+
nodes = raw_nodes.inject(REXML::Nodes[], :<<)
|
79
74
|
else
|
80
75
|
parsers = []
|
81
76
|
parsers << ->{parse_element(options)}
|
@@ -93,7 +88,7 @@ module ZenithalParserMethod
|
|
93
88
|
parsers << ->{parse_comment(options)}
|
94
89
|
parsers << ->{parse_text(options)}
|
95
90
|
raw_nodes = many(->{choose(*parsers)})
|
96
|
-
nodes = raw_nodes.inject(Nodes[], :<<)
|
91
|
+
nodes = raw_nodes.inject(REXML::Nodes[], :<<)
|
97
92
|
end
|
98
93
|
return nodes
|
99
94
|
end
|
@@ -137,7 +132,7 @@ module ZenithalParserMethod
|
|
137
132
|
end
|
138
133
|
|
139
134
|
def parse_mark(options)
|
140
|
-
parsers =
|
135
|
+
parsers = MARK_CHARS.map do |mark, query|
|
141
136
|
next ->{parse_char(query).yield_self{|_| mark}}
|
142
137
|
end
|
143
138
|
mark = choose(*parsers)
|
@@ -208,7 +203,7 @@ module ZenithalParserMethod
|
|
208
203
|
|
209
204
|
def parse_empty_children(options)
|
210
205
|
parse_char(CONTENT_END)
|
211
|
-
children = Nodes[]
|
206
|
+
children = REXML::Nodes[]
|
212
207
|
return children
|
213
208
|
end
|
214
209
|
|
@@ -313,7 +308,7 @@ module ZenithalParserMethod
|
|
313
308
|
end
|
314
309
|
|
315
310
|
def create_element(name, marks, attributes, children_list, options)
|
316
|
-
nodes = Nodes[]
|
311
|
+
nodes = REXML::Nodes[]
|
317
312
|
if marks.include?(:trim)
|
318
313
|
children_list.each do |children|
|
319
314
|
children.trim_indents
|
@@ -334,20 +329,20 @@ module ZenithalParserMethod
|
|
334
329
|
end
|
335
330
|
|
336
331
|
def create_instruction(target, attributes, children, options)
|
337
|
-
nodes = Nodes[]
|
332
|
+
nodes = REXML::Nodes[]
|
338
333
|
if target == SYSTEM_INSTRUCTION_NAME
|
339
334
|
@version = attributes["version"] if attributes["version"]
|
340
335
|
@special_element_names[:brace] = attributes["brace"] if attributes["brace"]
|
341
336
|
@special_element_names[:bracket] = attributes["bracket"] if attributes["bracket"]
|
342
337
|
@special_element_names[:slash] = attributes["slash"] if attributes["slash"]
|
343
338
|
elsif target == "xml"
|
344
|
-
instruction = XMLDecl.new
|
345
|
-
instruction.version = attributes["version"] || XMLDecl::DEFAULT_VERSION
|
339
|
+
instruction = REXML::XMLDecl.new
|
340
|
+
instruction.version = attributes["version"] || REXML::XMLDecl::DEFAULT_VERSION
|
346
341
|
instruction.encoding = attributes["encoding"]
|
347
342
|
instruction.standalone = attributes["standalone"]
|
348
343
|
nodes << instruction
|
349
344
|
else
|
350
|
-
instruction = Instruction.new(target)
|
345
|
+
instruction = REXML::Instruction.new(target)
|
351
346
|
actual_contents = []
|
352
347
|
attributes.each do |key, value|
|
353
348
|
actual_contents << "#{key}=\"#{value}\""
|
@@ -362,9 +357,9 @@ module ZenithalParserMethod
|
|
362
357
|
end
|
363
358
|
|
364
359
|
def create_normal_element(name, attributes, children_list, options)
|
365
|
-
nodes = Nodes[]
|
360
|
+
nodes = REXML::Nodes[]
|
366
361
|
children_list.each do |children|
|
367
|
-
element = Element.new(name)
|
362
|
+
element = REXML::Element.new(name)
|
368
363
|
attributes.each do |key, value|
|
369
364
|
element.add_attribute(key, value)
|
370
365
|
end
|
@@ -387,12 +382,12 @@ module ZenithalParserMethod
|
|
387
382
|
end
|
388
383
|
|
389
384
|
def create_text(raw_text, options)
|
390
|
-
text = Text.new(raw_text, true, nil, false)
|
385
|
+
text = REXML::Text.new(raw_text, true, nil, false)
|
391
386
|
return text
|
392
387
|
end
|
393
388
|
|
394
389
|
def create_comment(kind, content, options)
|
395
|
-
comment = Comment.new(" " + content.strip + " ")
|
390
|
+
comment = REXML::Comment.new(" " + content.strip + " ")
|
396
391
|
return comment
|
397
392
|
end
|
398
393
|
|
@@ -404,7 +399,7 @@ module ZenithalParserMethod
|
|
404
399
|
end
|
405
400
|
|
406
401
|
def process_macro(name, marks, attributes, children_list, options)
|
407
|
-
elements = Nodes[]
|
402
|
+
elements = REXML::Nodes[]
|
408
403
|
if @macros.key?(name)
|
409
404
|
raw_elements = @macros[name].call(attributes, children_list)
|
410
405
|
raw_elements.each do |raw_element|
|
@@ -421,9 +416,9 @@ module ZenithalParserMethod
|
|
421
416
|
end
|
422
417
|
|
423
418
|
|
424
|
-
class ZenithalParser < Parser
|
419
|
+
class Zenithal::ZenithalParser < Zenithal::Parser
|
425
420
|
|
426
|
-
include ZenithalParserMethod
|
421
|
+
include Zenithal::ZenithalParserMethod
|
427
422
|
|
428
423
|
attr_accessor :exact
|
429
424
|
attr_accessor :whole
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
|
4
|
-
class Parser
|
4
|
+
class Zenithal::Parser
|
5
5
|
|
6
6
|
ERROR_TAG = Object.new
|
7
7
|
|
@@ -9,24 +9,24 @@ class Parser
|
|
9
9
|
|
10
10
|
def initialize(source)
|
11
11
|
case source
|
12
|
-
when StringReader
|
12
|
+
when Zenithal::StringReader
|
13
13
|
@source = source
|
14
14
|
when File
|
15
|
-
@source = StringReader.new(source.read)
|
15
|
+
@source = Zenithal::StringReader.new(source.read)
|
16
16
|
else
|
17
|
-
@source = StringReader.new(source.to_s)
|
17
|
+
@source = Zenithal::StringReader.new(source.to_s)
|
18
18
|
end
|
19
19
|
@inside_run = false
|
20
20
|
end
|
21
21
|
|
22
22
|
def update(source)
|
23
23
|
case source
|
24
|
-
when StringReader
|
24
|
+
when Zenithal::StringReader
|
25
25
|
@source = source
|
26
26
|
when File
|
27
|
-
@source = StringReader.new(source.read)
|
27
|
+
@source = Zenithal::StringReader.new(source.read)
|
28
28
|
else
|
29
|
-
@source = StringReader.new(source.to_s)
|
29
|
+
@source = Zenithal::StringReader.new(source.to_s)
|
30
30
|
end
|
31
31
|
@inside_run = false
|
32
32
|
end
|
@@ -42,7 +42,7 @@ class Parser
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
unless value
|
45
|
-
raise ZenithalParseError.new(message)
|
45
|
+
raise Zenithal::ZenithalParseError.new(message)
|
46
46
|
end
|
47
47
|
return value
|
48
48
|
end
|
data/source/zenml/reader.rb
CHANGED
data/source/zenml/utility.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
include REXML
|
6
|
-
|
7
|
-
|
8
|
-
class Tag
|
4
|
+
class Zenithal::Tag
|
9
5
|
|
10
6
|
attr_accessor :name
|
11
7
|
attr_accessor :content
|
@@ -71,7 +67,7 @@ class Tag
|
|
71
67
|
end
|
72
68
|
|
73
69
|
|
74
|
-
class Element
|
70
|
+
class REXML::Element
|
75
71
|
|
76
72
|
alias old_get_index []
|
77
73
|
alias old_set_index []=
|
@@ -94,12 +90,12 @@ class Element
|
|
94
90
|
|
95
91
|
def each_xpath(*args, &block)
|
96
92
|
if block
|
97
|
-
XPath.each(self, *args) do |element|
|
93
|
+
REXML::XPath.each(self, *args) do |element|
|
98
94
|
block.call(element)
|
99
95
|
end
|
100
96
|
else
|
101
97
|
enumerator = Enumerator.new do |yielder|
|
102
|
-
XPath.each(self, *args) do |element|
|
98
|
+
REXML::XPath.each(self, *args) do |element|
|
103
99
|
yielder << element
|
104
100
|
end
|
105
101
|
end
|
@@ -111,9 +107,9 @@ class Element
|
|
111
107
|
texts = []
|
112
108
|
self.children.each do |child|
|
113
109
|
case child
|
114
|
-
when Text
|
110
|
+
when REXML::Text
|
115
111
|
texts << child
|
116
|
-
when Element
|
112
|
+
when REXML::Element
|
117
113
|
texts.concat(child.get_texts_recursive)
|
118
114
|
end
|
119
115
|
end
|
@@ -121,7 +117,7 @@ class Element
|
|
121
117
|
end
|
122
118
|
|
123
119
|
def inner_text(compress = false)
|
124
|
-
text = XPath.match(self, ".//text()").map{|s| s.value}.join("")
|
120
|
+
text = REXML::XPath.match(self, ".//text()").map{|s| s.value}.join("")
|
125
121
|
if compress
|
126
122
|
text.gsub!(/\r/, "")
|
127
123
|
text.gsub!(/\n\s*/, " ")
|
@@ -132,7 +128,7 @@ class Element
|
|
132
128
|
end
|
133
129
|
|
134
130
|
def self.build(name, &block)
|
135
|
-
element = Element.new(name)
|
131
|
+
element = REXML::Element.new(name)
|
136
132
|
block.call(element)
|
137
133
|
return element
|
138
134
|
end
|
@@ -140,12 +136,12 @@ class Element
|
|
140
136
|
end
|
141
137
|
|
142
138
|
|
143
|
-
class Parent
|
139
|
+
class REXML::Parent
|
144
140
|
|
145
141
|
alias old_push <<
|
146
142
|
|
147
143
|
def <<(object)
|
148
|
-
if object.is_a?(Nodes)
|
144
|
+
if object.is_a?(REXML::Nodes)
|
149
145
|
object.each do |child|
|
150
146
|
old_push(child)
|
151
147
|
end
|
@@ -157,12 +153,12 @@ class Parent
|
|
157
153
|
end
|
158
154
|
|
159
155
|
|
160
|
-
class Nodes < Array
|
156
|
+
class REXML::Nodes < Array
|
161
157
|
|
162
158
|
alias old_push <<
|
163
159
|
|
164
160
|
def <<(object)
|
165
|
-
if object.is_a?(Nodes)
|
161
|
+
if object.is_a?(REXML::Nodes)
|
166
162
|
object.each do |child|
|
167
163
|
old_push(child)
|
168
164
|
end
|
@@ -173,19 +169,19 @@ class Nodes < Array
|
|
173
169
|
end
|
174
170
|
|
175
171
|
def +(other)
|
176
|
-
return Nodes.new(super(other))
|
172
|
+
return REXML::Nodes.new(super(other))
|
177
173
|
end
|
178
174
|
|
179
175
|
def trim_indents
|
180
176
|
texts = []
|
181
|
-
if self.last.is_a?(Text)
|
177
|
+
if self.last.is_a?(REXML::Text)
|
182
178
|
self.last.value = self.last.value.rstrip
|
183
179
|
end
|
184
180
|
self.each do |child|
|
185
181
|
case child
|
186
|
-
when Text
|
182
|
+
when REXML::Text
|
187
183
|
texts << child
|
188
|
-
when Element
|
184
|
+
when REXML::Element
|
189
185
|
texts.concat(child.get_texts_recursive)
|
190
186
|
end
|
191
187
|
end
|
@@ -198,7 +194,7 @@ class Nodes < Array
|
|
198
194
|
texts.each do |text|
|
199
195
|
text.value = text.value.gsub(/\n(\x20+)/){"\n" + " " * ($1.length - indent_length)}
|
200
196
|
end
|
201
|
-
if self.first.is_a?(Text)
|
197
|
+
if self.first.is_a?(REXML::Text)
|
202
198
|
self.first.value = self.first.value.lstrip
|
203
199
|
end
|
204
200
|
end
|
@@ -209,7 +205,7 @@ end
|
|
209
205
|
class String
|
210
206
|
|
211
207
|
def ~
|
212
|
-
return Text.new(self, true, nil, false)
|
208
|
+
return REXML::Text.new(self, true, nil, false)
|
213
209
|
end
|
214
210
|
|
215
211
|
end
|
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.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ziphil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-15 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.
|