eim_xml 0.0.4 → 1.0.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 +339 -0
- data/lib/eim_xml/assertions.rb +14 -14
- data/lib/eim_xml/dsl.rb +104 -96
- data/lib/eim_xml/formatter/element_wrapper.rb +8 -6
- data/lib/eim_xml/formatter.rb +105 -106
- data/lib/eim_xml/matcher.rb +23 -20
- data/lib/eim_xml/parser.rb +68 -70
- data/lib/eim_xml/xhtml/dsl.rb +16 -14
- data/lib/eim_xml/xhtml.rb +156 -152
- data/lib/eim_xml.rb +202 -202
- metadata +31 -61
- data/Rakefile +0 -26
- data/Rakefile.utirake +0 -374
- data/spec/assertions_test.rb +0 -30
- data/spec/dsl_spec.rb +0 -217
- data/spec/eim_xml_spec.rb +0 -441
- data/spec/formatter_spec.rb +0 -260
- data/spec/parser_spec.rb +0 -102
- data/spec/xhtml_spec.rb +0 -524
data/lib/eim_xml.rb
CHANGED
@@ -5,206 +5,206 @@
|
|
5
5
|
#
|
6
6
|
|
7
7
|
module EimXML
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
8
|
+
XML_DECLARATION = %(<?xml version="1.0"?>)
|
9
|
+
|
10
|
+
class PCString
|
11
|
+
attr_reader :encoded_string, :src
|
12
|
+
alias to_s encoded_string
|
13
|
+
|
14
|
+
ENCODING_MAP = {
|
15
|
+
'&' => '&',
|
16
|
+
'"' => '"',
|
17
|
+
"'" => ''',
|
18
|
+
'<' => '<',
|
19
|
+
'>' => '>'
|
20
|
+
}
|
21
|
+
|
22
|
+
def self.encode(src)
|
23
|
+
src.to_s.gsub(/[&"'<>]/) do |m|
|
24
|
+
ENCODING_MAP[m]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.[](obj)
|
29
|
+
obj.is_a?(PCString) ? obj : PCString.new(obj)
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(src, encoded = false) # rubocop:disable Style/OptionalBooleanParameter
|
33
|
+
@src = src
|
34
|
+
@encoded_string = encoded ? src : PCString.encode(src)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
other.is_a?(PCString) ? @encoded_string == other.encoded_string : self == PCString.new(other)
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_to(out = '')
|
42
|
+
out << encoded_string
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Comment
|
47
|
+
def initialize(text)
|
48
|
+
raise ArgumentError, "Can not include '--'" if text =~ /--/
|
49
|
+
|
50
|
+
@text = text
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_to(out = '')
|
54
|
+
out << "<!-- #{@text} -->"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Element
|
59
|
+
attr_reader :name, :attributes, :contents
|
60
|
+
|
61
|
+
NEST = ' '
|
62
|
+
|
63
|
+
def initialize(name, attributes = {})
|
64
|
+
@name = name.to_sym
|
65
|
+
@attributes = {}
|
66
|
+
@contents = []
|
67
|
+
|
68
|
+
attributes.each do |k, v|
|
69
|
+
@attributes[k.to_sym] = v
|
70
|
+
end
|
71
|
+
|
72
|
+
yield(self) if block_given?
|
73
|
+
end
|
74
|
+
|
75
|
+
def name=(new_name)
|
76
|
+
@name = new_name.to_sym
|
77
|
+
end
|
78
|
+
protected :name=
|
79
|
+
|
80
|
+
def add(content)
|
81
|
+
case content
|
82
|
+
when nil
|
83
|
+
# nothing to do
|
84
|
+
when Array
|
85
|
+
content.each { |i| add(i) }
|
86
|
+
else
|
87
|
+
@contents << content
|
88
|
+
end
|
89
|
+
self
|
90
|
+
end
|
91
|
+
alias << add
|
92
|
+
|
93
|
+
def name_and_attributes(out = '')
|
94
|
+
out << @name.to_s
|
95
|
+
@attributes.each do |k, v|
|
96
|
+
next unless v
|
97
|
+
|
98
|
+
out << " #{k}='#{v.is_a?(PCString) ? v : PCString.encode(v.to_s)}'"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def write_to(out = '')
|
103
|
+
out << '<'
|
104
|
+
name_and_attributes(out)
|
105
|
+
|
106
|
+
if @contents.empty?
|
107
|
+
out << ' />'
|
108
|
+
else
|
109
|
+
out << '>'
|
110
|
+
@contents.each do |c|
|
111
|
+
case c
|
112
|
+
when Element
|
113
|
+
c.write_to(out)
|
114
|
+
when PCString
|
115
|
+
out << c.to_s
|
116
|
+
else
|
117
|
+
out << PCString.encode(c.to_s)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
out << "</#{@name}>"
|
121
|
+
end
|
122
|
+
out
|
123
|
+
end
|
124
|
+
alias to_s write_to
|
125
|
+
alias inspect to_s
|
126
|
+
|
127
|
+
def ==(other)
|
128
|
+
return false unless other.is_a?(Element)
|
129
|
+
|
130
|
+
@name == other.name && @attributes == other.attributes && @contents == other.contents
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_attribute(key, value)
|
134
|
+
@attributes[key.to_sym] = value
|
135
|
+
end
|
136
|
+
alias []= add_attribute
|
137
|
+
|
138
|
+
def [](key)
|
139
|
+
if key.is_a?(Integer)
|
140
|
+
@contents[key]
|
141
|
+
else
|
142
|
+
@attributes[key.to_sym]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def del_attribute(key)
|
147
|
+
@attributes.delete(key.to_sym)
|
148
|
+
end
|
149
|
+
|
150
|
+
def pcstring_contents
|
151
|
+
@contents.select { |c| c.is_a?(String) || c.is_a?(PCString) }.map { |c| c.is_a?(String) ? PCString.new(c) : c }
|
152
|
+
end
|
153
|
+
|
154
|
+
def match(obj, attr = nil)
|
155
|
+
return match(Element.new(obj, attr)) if attr
|
156
|
+
return obj =~ @name.to_s if obj.is_a?(Regexp)
|
157
|
+
return @name == obj if obj.is_a?(Symbol)
|
158
|
+
return is_a?(obj) if obj.is_a?(Module)
|
159
|
+
|
160
|
+
raise ArgumentError unless obj.is_a?(Element)
|
161
|
+
|
162
|
+
return false unless @name == obj.name
|
163
|
+
|
164
|
+
obj.attributes.all? do |k, v|
|
165
|
+
(v.nil? && !@attributes.include?(k)) ||
|
166
|
+
(@attributes.include?(k) && (v.is_a?(Regexp) ? v =~ @attributes[k] : PCString[v] == PCString[@attributes[k]]))
|
167
|
+
end and obj.contents.all? do |i|
|
168
|
+
case i
|
169
|
+
when Element
|
170
|
+
has_element?(i)
|
171
|
+
when String
|
172
|
+
pcstring_contents.include?(PCString.new(i))
|
173
|
+
when PCString
|
174
|
+
pcstring_contents.include?(i)
|
175
|
+
when Regexp
|
176
|
+
@contents.any? { |c| c.is_a?(String) and i =~ c }
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
alias =~ match
|
181
|
+
|
182
|
+
def has?(obj, attr = nil)
|
183
|
+
return has?(Element.new(obj, attr)) if attr
|
184
|
+
|
185
|
+
@contents.any? do |i|
|
186
|
+
if i.is_a?(Element)
|
187
|
+
i.match(obj) || i.has?(obj)
|
188
|
+
else
|
189
|
+
obj.is_a?(Module) && i.is_a?(obj)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
alias has_element? has?
|
194
|
+
alias include? has?
|
195
|
+
|
196
|
+
def find(obj, dst = Element.new(:found))
|
197
|
+
return find(Element.new(obj, dst)) if dst.is_a?(Hash)
|
198
|
+
|
199
|
+
dst << self if match(obj)
|
200
|
+
@contents.each do |i|
|
201
|
+
if i.is_a?(Element)
|
202
|
+
i.find(obj, dst)
|
203
|
+
elsif obj.is_a?(Module) && i.is_a?(obj)
|
204
|
+
dst << i
|
205
|
+
end
|
206
|
+
end
|
207
|
+
dst
|
208
|
+
end
|
209
|
+
end
|
210
210
|
end
|
metadata
CHANGED
@@ -1,83 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: eim_xml
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- KURODA Hiraku
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-07-19 00:00:00 Z
|
11
|
+
date: 2024-08-03 00:00:00.000000000 Z
|
19
12
|
dependencies: []
|
20
|
-
|
21
13
|
description:
|
22
|
-
email:
|
14
|
+
email: hirakuro@gmail.com
|
23
15
|
executables: []
|
24
|
-
|
25
16
|
extensions: []
|
26
|
-
|
27
17
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
- lib/eim_xml/matcher.rb
|
33
|
-
- lib/eim_xml/xhtml.rb
|
18
|
+
files:
|
19
|
+
- LICENSE
|
20
|
+
- lib/eim_xml.rb
|
21
|
+
- lib/eim_xml/assertions.rb
|
34
22
|
- lib/eim_xml/dsl.rb
|
35
|
-
- lib/eim_xml/parser.rb
|
36
23
|
- lib/eim_xml/formatter.rb
|
37
|
-
- lib/eim_xml/xhtml/dsl.rb
|
38
|
-
- lib/eim_xml/assertions.rb
|
39
24
|
- lib/eim_xml/formatter/element_wrapper.rb
|
40
|
-
- lib/eim_xml.rb
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
-
|
47
|
-
|
48
|
-
|
49
|
-
|
25
|
+
- lib/eim_xml/matcher.rb
|
26
|
+
- lib/eim_xml/parser.rb
|
27
|
+
- lib/eim_xml/xhtml.rb
|
28
|
+
- lib/eim_xml/xhtml/dsl.rb
|
29
|
+
homepage: https://github.com/hirakuro/eim_xml
|
30
|
+
licenses:
|
31
|
+
- GPL-2.0-only
|
32
|
+
metadata:
|
33
|
+
rubygems_mfa_required: 'true'
|
50
34
|
post_install_message:
|
51
35
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
36
|
+
require_paths:
|
54
37
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
|
57
|
-
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.2.0
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
58
45
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
64
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ">"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
hash: 25
|
70
|
-
segments:
|
71
|
-
- 1
|
72
|
-
- 3
|
73
|
-
- 1
|
74
|
-
version: 1.3.1
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
75
48
|
requirements: []
|
76
|
-
|
77
|
-
rubyforge_project: eimxml
|
78
|
-
rubygems_version: 1.8.5
|
49
|
+
rubygems_version: 3.5.11
|
79
50
|
signing_key:
|
80
|
-
specification_version:
|
51
|
+
specification_version: 4
|
81
52
|
summary: Easy IMplemented XML
|
82
53
|
test_files: []
|
83
|
-
|
data/Rakefile
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
load "Rakefile.utirake"
|
2
|
-
VER = "0.0.4"
|
3
|
-
|
4
|
-
UtiRake.setup do
|
5
|
-
rdoc do |t|
|
6
|
-
t.title = "Easy IMplemented XML"
|
7
|
-
t.main = "README"
|
8
|
-
t.rdoc_files.include(FileList["lib/**/*.rb", "README"])
|
9
|
-
end
|
10
|
-
|
11
|
-
gemspec do |s|
|
12
|
-
s.name = "eim_xml"
|
13
|
-
s.summary = "Easy IMplemented XML"
|
14
|
-
s.author = "KURODA Hiraku"
|
15
|
-
s.email = "hiraku@hinet.mydns.jp"
|
16
|
-
s.homepage = "http://eimxml.rubyforge.org/"
|
17
|
-
s.rubyforge_project = "eimxml"
|
18
|
-
s.version = VER
|
19
|
-
end
|
20
|
-
|
21
|
-
publish("eimxml", "hiraku")
|
22
|
-
|
23
|
-
alias_task
|
24
|
-
end
|
25
|
-
|
26
|
-
task :default => :spec
|