wax 0.9.4 → 0.9.5
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.
- data/lib/address.rb +16 -0
- data/lib/car.rb +22 -0
- data/lib/instance_exec.rb +3 -2
- data/lib/person.rb +24 -0
- data/lib/tutorial.rb +131 -107
- data/lib/wax.rb +40 -37
- data/test/test_wax.rb +6 -6
- metadata +4 -1
data/lib/address.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class Address
|
2
|
+
attr_accessor :street, :city, :state, :zip
|
3
|
+
|
4
|
+
def initialize(street, city, state, zip)
|
5
|
+
@street, @city, @state, @zip = street, city, state, zip
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_xml(wax)
|
9
|
+
wax.start('address').
|
10
|
+
child('street', @street).
|
11
|
+
child('city', @city).
|
12
|
+
child('state', @state).
|
13
|
+
child('zip', @zip).
|
14
|
+
end!
|
15
|
+
end
|
16
|
+
end
|
data/lib/car.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Car
|
2
|
+
attr_accessor :make, :model, :year
|
3
|
+
|
4
|
+
def initialize(make, model, year)
|
5
|
+
@make, @model, @year = make, model, year
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_xml(wax)
|
9
|
+
wax.start('car').attr('year', @year).
|
10
|
+
child('make', @make).
|
11
|
+
child('model', @model).
|
12
|
+
end!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if $PROGRAM_NAME == __FILE__ || $PROGRAM_NAME =~ /\/rake/
|
17
|
+
require 'wax'
|
18
|
+
car = Car.new 'Toyota', 'Prius', 2008
|
19
|
+
wax = WAX.new
|
20
|
+
car.to_xml(wax)
|
21
|
+
wax.close
|
22
|
+
end
|
data/lib/instance_exec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# This implements the Object#instance_exec method
|
2
|
+
# for versions that don't have it (before 1.9).
|
1
3
|
# This solution was found at
|
2
|
-
# http://www.jroller.com/abstractScope/entry/
|
3
|
-
# passing_parameters_to_an_instance
|
4
|
+
# http://www.jroller.com/abstractScope/entry/passing_parameters_to_an_instance.
|
4
5
|
|
5
6
|
# Add a bind method to the Proc class.
|
6
7
|
class Proc
|
data/lib/person.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class Person
|
2
|
+
attr_accessor :name, :birthdate, :address
|
3
|
+
|
4
|
+
def initialize(name, birthdate, address)
|
5
|
+
@name, @birthdate, @address = name, birthdate, address
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_xml(wax)
|
9
|
+
wax.start('person').attr('birthdate', @birthdate).child('name', @name)
|
10
|
+
@address.to_xml(wax)
|
11
|
+
wax.end!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if $PROGRAM_NAME == __FILE__ || $PROGRAM_NAME =~ /\/rake/
|
16
|
+
require 'address'
|
17
|
+
require 'wax'
|
18
|
+
|
19
|
+
address = Address.new('123 Some Street', 'Some City', 'MO', 12345)
|
20
|
+
person = Person.new('R. Mark Volkmann', '4/16/1961', address)
|
21
|
+
wax = WAX.new
|
22
|
+
person.to_xml(wax)
|
23
|
+
wax.close
|
24
|
+
end
|
data/lib/tutorial.rb
CHANGED
@@ -1,190 +1,214 @@
|
|
1
1
|
require 'wax'
|
2
2
|
|
3
|
-
# This serves as a tutorial for using WAX.
|
3
|
+
# This serves as a tutorial for using WAX for Ruby.
|
4
4
|
|
5
5
|
def out(text)
|
6
6
|
puts "\n\n#{text}\n"
|
7
7
|
end
|
8
8
|
|
9
|
-
# When
|
10
|
-
# There
|
11
|
-
wax = WAX.new
|
9
|
+
# When nothing is passed to the WAX.write method, XML is written to $stdout.
|
10
|
+
# There is also a WAX.write method that takes an IO object.
|
12
11
|
|
13
|
-
out
|
14
|
-
|
12
|
+
out 'Only a root element:'
|
13
|
+
WAX.write { start 'car' }
|
15
14
|
# <car/>
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
wax.start("car").text("Prius").close
|
16
|
+
out 'A root element with some text inside:'
|
17
|
+
WAX.write do
|
18
|
+
start 'car'
|
19
|
+
text 'Prius'
|
20
|
+
end
|
23
21
|
# <car>Prius</car>
|
24
22
|
|
25
|
-
out
|
26
|
-
|
27
|
-
|
23
|
+
out 'Text inside a child element:'
|
24
|
+
WAX.write do
|
25
|
+
start 'car'
|
26
|
+
start 'model'
|
27
|
+
text 'Prius'
|
28
|
+
end
|
28
29
|
# <car>
|
29
30
|
# <model>Prius</model>
|
30
31
|
# </car>
|
31
32
|
|
32
|
-
out
|
33
|
-
|
34
|
-
|
33
|
+
out 'The same with the \'child\' convenience method:'
|
34
|
+
WAX.write do
|
35
|
+
start 'car'
|
36
|
+
child 'model', 'Prius'
|
37
|
+
end
|
35
38
|
# <car>
|
36
39
|
# <model>Prius</model>
|
37
40
|
# </car>
|
38
41
|
|
39
|
-
out
|
40
|
-
|
41
|
-
|
42
|
+
out 'Text in a CDATA section:'
|
43
|
+
WAX.write do
|
44
|
+
start 'car'
|
45
|
+
start 'model'
|
46
|
+
cdata "1<2>3&4'5\"6"
|
47
|
+
end
|
42
48
|
# <car>
|
43
49
|
# <model>
|
44
50
|
# <![CDATA[1<2>3&4'5\"6]]>
|
45
51
|
# </model>
|
46
52
|
# </car>
|
47
53
|
|
48
|
-
out
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
out 'Without indentation, on a single line:'
|
55
|
+
WAX.write do
|
56
|
+
set_indent nil
|
57
|
+
start 'car'
|
58
|
+
child 'model', 'Prius'
|
59
|
+
end
|
52
60
|
# <car><model>Prius</model></car>
|
53
61
|
|
54
|
-
out
|
55
|
-
|
56
|
-
|
57
|
-
|
62
|
+
out 'Indent with four spaces instead of the default of two:'
|
63
|
+
WAX.write do
|
64
|
+
set_indent ' ' # could also pass 4
|
65
|
+
start 'car'
|
66
|
+
child 'model', 'Prius'
|
67
|
+
end
|
58
68
|
# <car>
|
59
69
|
# <model>Prius</model>
|
60
70
|
# </car>
|
61
71
|
|
62
|
-
out
|
63
|
-
|
64
|
-
|
65
|
-
|
72
|
+
out 'Add an attribute:'
|
73
|
+
WAX.write do
|
74
|
+
start 'car'
|
75
|
+
attr 'year', 2008
|
76
|
+
child 'model', 'Prius'
|
77
|
+
end
|
78
|
+
# <car year='2008'>
|
66
79
|
# <model>Prius</model>
|
67
80
|
# </car>
|
68
81
|
|
69
|
-
out
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
82
|
+
out 'XML declaration:'
|
83
|
+
WAX.write($stdout, '1.0') do
|
84
|
+
start 'car'
|
85
|
+
attr 'year', 2008
|
86
|
+
child 'model', 'Prius'
|
87
|
+
end
|
88
|
+
# <?xml version='1.0' encoding='UTF-8'?>
|
89
|
+
# <car year='2008'>
|
74
90
|
# <model>Prius</model>
|
75
91
|
# </car>
|
76
92
|
|
77
|
-
out
|
93
|
+
out 'Comment:'
|
78
94
|
WAX.write do
|
79
|
-
comment
|
80
|
-
start
|
81
|
-
child
|
95
|
+
comment 'This is a hybrid car.'
|
96
|
+
start 'car'
|
97
|
+
child 'model', 'Prius'
|
82
98
|
end
|
83
99
|
# <!-- This is a hybrid car. -->
|
84
100
|
# <car>
|
85
101
|
# <model>Prius</model>
|
86
102
|
# </car>
|
87
103
|
|
88
|
-
out
|
104
|
+
out 'Processing instruction:'
|
89
105
|
WAX.write do
|
90
|
-
processing_instruction
|
91
|
-
start
|
92
|
-
attr
|
93
|
-
child
|
106
|
+
processing_instruction 'target', 'data'
|
107
|
+
start 'car'
|
108
|
+
attr 'year', 2008
|
109
|
+
child 'model', 'Prius'
|
94
110
|
end
|
95
111
|
# <?target data?>
|
96
|
-
# <car year=
|
112
|
+
# <car year='2008'>
|
97
113
|
# <model>Prius</model>
|
98
114
|
# </car>
|
99
115
|
|
100
|
-
out
|
116
|
+
out 'Associate an XSLT stylesheet:'
|
101
117
|
WAX.write do
|
102
|
-
xslt
|
103
|
-
start
|
104
|
-
attr
|
105
|
-
child
|
118
|
+
xslt 'car.xslt'
|
119
|
+
start 'car'
|
120
|
+
attr 'year', 2008
|
121
|
+
child 'model', 'Prius'
|
106
122
|
end
|
107
|
-
# <?xml-stylesheet type=
|
108
|
-
# <car year=
|
123
|
+
# <?xml-stylesheet type='text/xsl' href='car.xslt'?>
|
124
|
+
# <car year='2008'>
|
109
125
|
# <model>Prius</model>
|
110
126
|
# </car>
|
111
127
|
|
112
|
-
out
|
128
|
+
out 'Associate a default namespace:'
|
113
129
|
WAX.write do
|
114
|
-
xslt
|
115
|
-
start
|
116
|
-
attr
|
117
|
-
namespace
|
118
|
-
child
|
130
|
+
xslt 'car.xslt'
|
131
|
+
start 'car'
|
132
|
+
attr 'year', 2008
|
133
|
+
namespace 'http://www.ociweb.com/cars'
|
134
|
+
child 'model', 'Prius'
|
119
135
|
end
|
120
|
-
# <car year=
|
121
|
-
# xmlns=
|
136
|
+
# <car year='2008'
|
137
|
+
# xmlns='http://www.ociweb.com/cars'>
|
122
138
|
# <model>Prius</model>
|
123
139
|
# </car>
|
124
140
|
|
125
|
-
out
|
126
|
-
prefix =
|
141
|
+
out 'Associate a non-default namespace with the XML:'
|
142
|
+
prefix = 'c'
|
127
143
|
WAX.write do
|
128
|
-
start prefix,
|
129
|
-
attr
|
130
|
-
namespace prefix,
|
131
|
-
child prefix,
|
144
|
+
start prefix, 'car'
|
145
|
+
attr 'year', 2008
|
146
|
+
namespace prefix, 'http://www.ociweb.com/cars'
|
147
|
+
child prefix, 'model', 'Prius'
|
132
148
|
end
|
133
|
-
# <c:car year=
|
134
|
-
# xmlns:c=
|
149
|
+
# <c:car year='2008'
|
150
|
+
# xmlns:c='http://www.ociweb.com/cars'>
|
135
151
|
# <c:model>Prius</c:model>
|
136
152
|
# </c:car>
|
137
153
|
|
138
|
-
out
|
154
|
+
out 'Associate an XML Schema:'
|
139
155
|
WAX.write do
|
140
|
-
start
|
141
|
-
attr
|
142
|
-
namespace nil,
|
143
|
-
child
|
156
|
+
start 'car'
|
157
|
+
attr 'year', 2008
|
158
|
+
namespace nil, 'http://www.ociweb.com/cars', 'car.xsd'
|
159
|
+
child 'model', 'Prius'
|
144
160
|
end
|
145
|
-
# <car year=
|
146
|
-
# xmlns=
|
147
|
-
# xmlns:xsi=
|
148
|
-
# xsi:schemaLocation=
|
161
|
+
# <car year='2008'
|
162
|
+
# xmlns='http://www.ociweb.com/cars'
|
163
|
+
# xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
|
164
|
+
# xsi:schemaLocation='http://www.ociweb.com/cars car.xsd'>
|
149
165
|
# <model>Prius</model>
|
150
166
|
# </car>
|
151
167
|
|
152
|
-
out
|
168
|
+
out 'Associate multiple XML Schemas:'
|
153
169
|
WAX.write do
|
154
|
-
start
|
155
|
-
attr
|
156
|
-
namespace nil,
|
157
|
-
namespace
|
158
|
-
child
|
170
|
+
start 'car'
|
171
|
+
attr 'year', 2008
|
172
|
+
namespace nil, 'http://www.ociweb.com/cars', 'car.xsd'
|
173
|
+
namespace 'm', 'http://www.ociweb.com/model', 'model.xsd'
|
174
|
+
child 'm', 'model', 'Prius'
|
159
175
|
end
|
160
|
-
# <car year=
|
161
|
-
# xmlns=
|
162
|
-
# xmlns:m=
|
163
|
-
# xmlns:xsi=
|
164
|
-
# xsi:schemaLocation=
|
165
|
-
# http://www.ociweb.com/model model.xsd
|
176
|
+
# <car year='2008'
|
177
|
+
# xmlns='http://www.ociweb.com/cars'
|
178
|
+
# xmlns:m='http://www.ociweb.com/model'
|
179
|
+
# xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
|
180
|
+
# xsi:schemaLocation='http://www.ociweb.com/cars car.xsd
|
181
|
+
# http://www.ociweb.com/model model.xsd'>
|
166
182
|
# <m:model>Prius</m:model>
|
167
183
|
# </car>
|
168
184
|
|
169
|
-
out
|
185
|
+
out 'Associate a DTD:'
|
170
186
|
WAX.write do
|
171
|
-
dtd
|
172
|
-
start
|
173
|
-
attr
|
174
|
-
child
|
187
|
+
dtd 'car.dtd'
|
188
|
+
start 'car'
|
189
|
+
attr 'year', 2008
|
190
|
+
child 'model', 'Prius'
|
175
191
|
end
|
176
|
-
# <!DOCTYPE car SYSTEM
|
177
|
-
# <car year=
|
192
|
+
# <!DOCTYPE car SYSTEM 'car.dtd'>
|
193
|
+
# <car year='2008'>
|
178
194
|
# <model>Prius</model>
|
179
195
|
# </car>
|
180
196
|
|
181
|
-
out
|
182
|
-
String url =
|
197
|
+
out 'Entity definitions in DOCTYPE:'
|
198
|
+
String url = 'http://www.ociweb.com/xml/';
|
183
199
|
WAX.write do
|
184
|
-
entity_def
|
185
|
-
external_entity_def
|
186
|
-
start
|
187
|
-
text
|
200
|
+
entity_def 'oci', 'Object Computing, Inc.'
|
201
|
+
external_entity_def 'moreData', url + 'moreData.xml'
|
202
|
+
start 'root'
|
203
|
+
text 'The author works at &oci; in St. Louis, Missouri.',
|
188
204
|
true, false # turning escaping off for entity reference
|
189
|
-
text
|
190
|
-
end
|
205
|
+
text '&moreData;', true, false
|
206
|
+
end
|
207
|
+
# <!DOCTYPE root [
|
208
|
+
# <!ENTITY oci "Object Computing, Inc.">
|
209
|
+
# <!ENTITY moreData SYSTEM "http://www.ociweb.com/xml/moreData.xml">
|
210
|
+
#>
|
211
|
+
#<root>
|
212
|
+
# The author works at &oci; in St. Louis, Missouri.
|
213
|
+
# &moreData;
|
214
|
+
# </root>
|
data/lib/wax.rb
CHANGED
@@ -35,7 +35,7 @@ class WAX
|
|
35
35
|
# Creates a WAX object, invokes the specified block on it
|
36
36
|
# and calls close on the WAX object.
|
37
37
|
# The writer can be a String file path, an IO object such as a File,
|
38
|
-
# or unspecified to
|
38
|
+
# or unspecified to out $stdout.
|
39
39
|
# If the version isn't specified then no XML declaration will be written.
|
40
40
|
def self.write(writer=$stdout, version=nil, &proc)
|
41
41
|
writer = File.new(writer, "w") if writer.kind_of?(String)
|
@@ -94,10 +94,10 @@ class WAX
|
|
94
94
|
if new_line
|
95
95
|
write_indent
|
96
96
|
else
|
97
|
-
|
97
|
+
out ' '
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
out "#{qname}=\"#{value}\""
|
101
101
|
|
102
102
|
self
|
103
103
|
end
|
@@ -123,7 +123,7 @@ class WAX
|
|
123
123
|
end
|
124
124
|
|
125
125
|
# A convenience method that is a shortcut for
|
126
|
-
# start(prefix, name).text(text).
|
126
|
+
# start(prefix, name).text(text).end!().
|
127
127
|
def child(p1, p2, p3=nil)
|
128
128
|
if (p3 == nil)
|
129
129
|
# only specified element name and text
|
@@ -134,7 +134,7 @@ class WAX
|
|
134
134
|
end
|
135
135
|
|
136
136
|
bad_state("child") if @check_me and @state == :after_root
|
137
|
-
start(prefix, name).text(text).
|
137
|
+
start(prefix, name).text(text).end!
|
138
138
|
end
|
139
139
|
|
140
140
|
# Terminates all unterminated elements,
|
@@ -145,7 +145,7 @@ class WAX
|
|
145
145
|
bad_state("close") if @check_me and @state == :in_prolog
|
146
146
|
|
147
147
|
# End all the unended elements.
|
148
|
-
while @parent_stack.size > 0;
|
148
|
+
while @parent_stack.size > 0; end!; end
|
149
149
|
|
150
150
|
if @close_stream
|
151
151
|
@writer.close
|
@@ -167,8 +167,8 @@ class WAX
|
|
167
167
|
terminate_start
|
168
168
|
write_indent if @parent_stack.size > 0
|
169
169
|
|
170
|
-
|
171
|
-
|
170
|
+
out "<!-- #{text} -->"
|
171
|
+
out "\n" if will_indent and @parent_stack.size == 0
|
172
172
|
|
173
173
|
self
|
174
174
|
end
|
@@ -187,7 +187,8 @@ class WAX
|
|
187
187
|
# Terminates the current element.
|
188
188
|
# It does so in the shorthand way (/>) if the element has no content,
|
189
189
|
# and in the long way (</name>) if it does.
|
190
|
-
|
190
|
+
# The name of this method ends in ! because end is a keyword in Ruby.
|
191
|
+
def end!
|
191
192
|
if @check_me
|
192
193
|
bad_state("end") if @state == :in_prolog or @state == :after_root
|
193
194
|
verify_prefixes
|
@@ -203,9 +204,9 @@ class WAX
|
|
203
204
|
|
204
205
|
if @has_content
|
205
206
|
write_indent if @has_indented_content
|
206
|
-
|
207
|
+
out "</#{name}>"
|
207
208
|
else
|
208
|
-
|
209
|
+
out "/>"
|
209
210
|
end
|
210
211
|
|
211
212
|
@has_content = @has_indented_content = true # new setting for parent
|
@@ -290,12 +291,12 @@ class WAX
|
|
290
291
|
if will_indent
|
291
292
|
write_indent
|
292
293
|
else
|
293
|
-
|
294
|
+
out ' '
|
294
295
|
end
|
295
296
|
|
296
|
-
|
297
|
-
|
298
|
-
|
297
|
+
out "xmlns"
|
298
|
+
out(':' + prefix) if has_prefix
|
299
|
+
out "=\"#{uri}\""
|
299
300
|
|
300
301
|
if schema_path != nil
|
301
302
|
@namespace_uri_to_schema_path_map[uri] = schema_path
|
@@ -331,8 +332,8 @@ class WAX
|
|
331
332
|
terminate_start
|
332
333
|
write_indent if @parent_stack.size > 0
|
333
334
|
|
334
|
-
|
335
|
-
|
335
|
+
out "<?#{target} #{data}?>"
|
336
|
+
out("\n") if will_indent and @parent_stack.size == 0
|
336
337
|
|
337
338
|
self
|
338
339
|
end
|
@@ -437,7 +438,7 @@ class WAX
|
|
437
438
|
has_prefix = prefix != nil and prefix.length > 0
|
438
439
|
qname = has_prefix ? prefix + ':' + name : name
|
439
440
|
|
440
|
-
|
441
|
+
out '<' + qname
|
441
442
|
|
442
443
|
@parent_stack.push(qname)
|
443
444
|
|
@@ -455,13 +456,13 @@ class WAX
|
|
455
456
|
verify_prefixes if @check_me
|
456
457
|
return if @state != :in_start_tag
|
457
458
|
write_schema_locations
|
458
|
-
|
459
|
+
out '>'
|
459
460
|
@attr_on_new_line = false # reset
|
460
461
|
@state = :in_element
|
461
462
|
end
|
462
463
|
|
463
464
|
# Writes text inside the content of the current element.
|
464
|
-
def text(
|
465
|
+
def text(obj, newline=false, escape=@check_me)
|
465
466
|
if @check_me
|
466
467
|
bad_state("text") if @state == :in_prolog or @state == :after_root
|
467
468
|
end
|
@@ -470,12 +471,14 @@ class WAX
|
|
470
471
|
@has_indented_content = newline
|
471
472
|
terminate_start
|
472
473
|
|
473
|
-
|
474
|
+
text = obj.to_s if obj
|
475
|
+
|
476
|
+
if obj != nil and text.length > 0
|
474
477
|
write_indent if newline
|
475
478
|
text = XMLUtil.escape(text) if escape
|
476
|
-
|
479
|
+
out text
|
477
480
|
elsif newline
|
478
|
-
|
481
|
+
out "\n"
|
479
482
|
end
|
480
483
|
|
481
484
|
self
|
@@ -500,8 +503,8 @@ class WAX
|
|
500
503
|
end
|
501
504
|
|
502
505
|
# Writes the to_s value of an Object to the writer.
|
503
|
-
def
|
504
|
-
raise "attempting to
|
506
|
+
def out(data)
|
507
|
+
raise "attempting to out XML after close has been called" unless @writer
|
505
508
|
@writer.write(data.to_s)
|
506
509
|
end
|
507
510
|
|
@@ -509,34 +512,34 @@ class WAX
|
|
509
512
|
def write_doctype(root_element_name)
|
510
513
|
return if @dtd_file_path == nil and @entity_defs.empty?
|
511
514
|
|
512
|
-
|
513
|
-
|
515
|
+
out "<!DOCTYPE #{root_element_name}"
|
516
|
+
out " SYSTEM \"#{@dtd_file_path}\"" unless @dtd_file_path == nil
|
514
517
|
|
515
518
|
if not @entity_defs.empty?
|
516
|
-
|
519
|
+
out " ["
|
517
520
|
|
518
521
|
@entity_defs.each do |entity_def|
|
519
|
-
|
520
|
-
|
522
|
+
out "\n" + @indent if will_indent
|
523
|
+
out "<!ENTITY #{entity_def}>"
|
521
524
|
end
|
522
525
|
|
523
|
-
|
524
|
-
|
526
|
+
out "\n" if will_indent
|
527
|
+
out ']'
|
525
528
|
|
526
529
|
@entity_defs.clear
|
527
530
|
end
|
528
531
|
|
529
|
-
|
530
|
-
|
532
|
+
out '>'
|
533
|
+
out "\n" if will_indent
|
531
534
|
end
|
532
535
|
|
533
536
|
# Writes the proper amount of indentation
|
534
537
|
# given the current nesting of elements.
|
535
538
|
def write_indent
|
536
539
|
return unless will_indent
|
537
|
-
|
540
|
+
out "\n"
|
538
541
|
for i in 0...@parent_stack.size
|
539
|
-
|
542
|
+
out @indent
|
540
543
|
end
|
541
544
|
end
|
542
545
|
|
@@ -576,7 +579,7 @@ class WAX
|
|
576
579
|
return if version == nil
|
577
580
|
XMLUtil.verify_version(version) if @check_me
|
578
581
|
|
579
|
-
|
582
|
+
out "<?xml version=\"#{version}\" " +
|
580
583
|
"encoding=\"#{XMLUtil::DEFAULT_ENCODING}\"?>\n"
|
581
584
|
end
|
582
585
|
|
data/test/test_wax.rb
CHANGED
@@ -71,7 +71,7 @@ class WAXTest < Test::Unit::TestCase
|
|
71
71
|
assert_raise(RuntimeError) do
|
72
72
|
WAX.write do
|
73
73
|
start "root"
|
74
|
-
|
74
|
+
end!
|
75
75
|
child "child", "text" # can't call child after root is closed
|
76
76
|
end
|
77
77
|
end
|
@@ -129,7 +129,7 @@ class WAXTest < Test::Unit::TestCase
|
|
129
129
|
|
130
130
|
def test_bad_end
|
131
131
|
assert_raise(RuntimeError) do
|
132
|
-
WAX.write {
|
132
|
+
WAX.write { end! } # haven't called start yet
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -188,7 +188,7 @@ class WAXTest < Test::Unit::TestCase
|
|
188
188
|
start "parent"
|
189
189
|
namespace "foo", "http://www.ociweb.com/foo"
|
190
190
|
child "foo", "child1", "one"
|
191
|
-
|
191
|
+
end!
|
192
192
|
child "foo", "child2", "two"
|
193
193
|
end
|
194
194
|
end
|
@@ -236,7 +236,7 @@ class WAXTest < Test::Unit::TestCase
|
|
236
236
|
nl_text "text #2"
|
237
237
|
start "child2"
|
238
238
|
attr "a1", "v1"
|
239
|
-
|
239
|
+
end!
|
240
240
|
nl_text "text #3"
|
241
241
|
end
|
242
242
|
|
@@ -355,8 +355,8 @@ class WAXTest < Test::Unit::TestCase
|
|
355
355
|
WAX.write do
|
356
356
|
set_indent nil
|
357
357
|
start "root"
|
358
|
-
|
359
|
-
|
358
|
+
end!
|
359
|
+
end!
|
360
360
|
end
|
361
361
|
end
|
362
362
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- R. Mark Volkmann
|
@@ -22,8 +22,11 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README.rdoc
|
24
24
|
files:
|
25
|
+
- lib/address.rb
|
26
|
+
- lib/car.rb
|
25
27
|
- lib/cd_demo.rb
|
26
28
|
- lib/instance_exec.rb
|
29
|
+
- lib/person.rb
|
27
30
|
- lib/tutorial.rb
|
28
31
|
- lib/wax.rb
|
29
32
|
- lib/xml_util.rb
|