builder 3.1.4 → 3.2.4
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/CHANGES +18 -0
- data/{README.rdoc → README.md} +59 -26
- data/Rakefile +18 -13
- data/builder.blurb +27 -0
- data/builder.gemspec +45 -0
- data/doc/jamis.rb +592 -0
- data/lib/blankslate.rb +1 -0
- data/lib/builder.rb +1 -0
- data/lib/builder/blankslate.rb +1 -0
- data/lib/builder/version.rb +2 -1
- data/lib/builder/xchar.rb +5 -4
- data/lib/builder/xmlbase.rb +20 -12
- data/lib/builder/xmlevents.rb +1 -0
- data/lib/builder/xmlmarkup.rb +32 -21
- data/rakelib/publish.rake +21 -0
- data/rakelib/tags.rake +63 -0
- data/rakelib/testing.rake +8 -0
- data/test/helper.rb +13 -0
- data/test/performance.rb +3 -1
- data/test/preload.rb +1 -0
- data/test/test_blankslate.rb +4 -13
- data/test/test_eventbuilder.rb +4 -3
- data/test/test_markupbuilder.rb +57 -18
- data/test/test_method_caching.rb +5 -4
- data/test/test_namecollision.rb +3 -2
- data/test/test_xchar.rb +17 -9
- metadata +30 -29
data/test/test_eventbuilder.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
#--
|
4
5
|
# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
@@ -10,12 +11,12 @@
|
|
10
11
|
# above copyright notice is included.
|
11
12
|
#++
|
12
13
|
|
13
|
-
require '
|
14
|
-
require '
|
14
|
+
require 'helper'
|
15
|
+
require 'preload'
|
15
16
|
require 'builder'
|
16
17
|
require 'builder/xmlevents'
|
17
18
|
|
18
|
-
class TestEvents < Test
|
19
|
+
class TestEvents < Builder::Test
|
19
20
|
|
20
21
|
class Target
|
21
22
|
attr_reader :events
|
data/test/test_markupbuilder.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
#--
|
4
5
|
# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
@@ -10,12 +11,12 @@
|
|
10
11
|
# above copyright notice is included.
|
11
12
|
#++
|
12
13
|
|
13
|
-
require '
|
14
|
-
require '
|
14
|
+
require 'helper'
|
15
|
+
require 'preload'
|
15
16
|
require 'builder'
|
16
17
|
require 'builder/xmlmarkup'
|
17
18
|
|
18
|
-
class TestMarkup < Test
|
19
|
+
class TestMarkup < Builder::Test
|
19
20
|
def setup
|
20
21
|
@xml = Builder::XmlMarkup.new
|
21
22
|
end
|
@@ -59,23 +60,38 @@ class TestMarkup < Test::Unit::TestCase
|
|
59
60
|
assert_equal %{<ref id="12"/>}, @xml.target!
|
60
61
|
end
|
61
62
|
|
62
|
-
def
|
63
|
+
def test_single_quotes_for_attrs
|
64
|
+
@xml = Builder::XmlMarkup.new(:quote => :single)
|
65
|
+
@xml.ref(:id => 12)
|
66
|
+
assert_equal %{<ref id='12'/>}, @xml.target!
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_mixed_quotes_for_attrs
|
70
|
+
@xml = Builder::XmlMarkup.new(:quote => :single)
|
71
|
+
x = Builder::XmlMarkup.new(:target=>@xml, :quote => :double)
|
72
|
+
@xml.ref(:id => 12) do
|
73
|
+
x.link(:id => 13)
|
74
|
+
end
|
75
|
+
assert_equal %{<ref id='12'><link id="13"/></ref>}, @xml.target!
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_string_attributes_are_escaped_by_default
|
63
79
|
@xml.ref(:id => "H&R")
|
64
80
|
assert_equal %{<ref id="H&R"/>}, @xml.target!
|
65
81
|
end
|
66
82
|
|
67
|
-
def
|
83
|
+
def test_symbol_attributes_are_unescaped_by_default
|
68
84
|
@xml.ref(:id => :"H&R")
|
69
85
|
assert_equal %{<ref id="H&R"/>}, @xml.target!
|
70
86
|
end
|
71
87
|
|
72
|
-
def
|
88
|
+
def test_attributes_escaping_can_be_turned_on
|
73
89
|
@xml = Builder::XmlMarkup.new
|
74
90
|
@xml.ref(:id => "<H&R \"block\">")
|
75
91
|
assert_equal %{<ref id="<H&R "block">"/>}, @xml.target!
|
76
92
|
end
|
77
93
|
|
78
|
-
def
|
94
|
+
def test_mixed_attribute_escaping_with_nested_builders
|
79
95
|
x = Builder::XmlMarkup.new(:target=>@xml)
|
80
96
|
@xml.ref(:id=>:"H&R") {
|
81
97
|
x.element(:tag=>"Long&Short")
|
@@ -129,7 +145,7 @@ class TestMarkup < Test::Unit::TestCase
|
|
129
145
|
end
|
130
146
|
|
131
147
|
def test_reference_methods
|
132
|
-
@xml.title { |x| x.a { x.b(
|
148
|
+
@xml.title { |x| x.a { x.b(_name) } }
|
133
149
|
assert_equal "<title><a><b>bob</b></a></title>", @xml.target!
|
134
150
|
end
|
135
151
|
|
@@ -156,6 +172,24 @@ class TestMarkup < Test::Unit::TestCase
|
|
156
172
|
assert_equal %{<div><hi><em>H&R Block</em></div>}, @xml.target!
|
157
173
|
end
|
158
174
|
|
175
|
+
def test_nil
|
176
|
+
b = Builder::XmlMarkup.new
|
177
|
+
b.tag! "foo", nil
|
178
|
+
assert_equal %{<foo/>}, b.target!
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_nil_without_explicit_nil_handling
|
182
|
+
b = Builder::XmlMarkup.new(:explicit_nil_handling => false)
|
183
|
+
b.tag! "foo", nil
|
184
|
+
assert_equal %{<foo/>}, b.target!
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_nil_with_explicit_nil_handling
|
188
|
+
b = Builder::XmlMarkup.new(:explicit_nil_handling => true)
|
189
|
+
b.tag! "foo", nil
|
190
|
+
assert_equal %{<foo nil="true"/>}, b.target!
|
191
|
+
end
|
192
|
+
|
159
193
|
def test_non_escaping
|
160
194
|
@xml.div("ns:xml"=>:"&xml;") { |x| x << "<h&i>"; x.em("H&R Block") }
|
161
195
|
assert_equal %{<div ns:xml="&xml;"><h&i><em>H&R Block</em></div>}, @xml.target!
|
@@ -172,12 +206,12 @@ class TestMarkup < Test::Unit::TestCase
|
|
172
206
|
assert_equal "<div><span><a href=\"ref\">text</a></span></div>", @xml.target!
|
173
207
|
end
|
174
208
|
|
175
|
-
def
|
209
|
+
def _name
|
176
210
|
"bob"
|
177
211
|
end
|
178
212
|
end
|
179
213
|
|
180
|
-
class TestAttributeEscaping < Test
|
214
|
+
class TestAttributeEscaping < Builder::Test
|
181
215
|
|
182
216
|
def setup
|
183
217
|
@xml = Builder::XmlMarkup.new
|
@@ -215,7 +249,7 @@ class TestAttributeEscaping < Test::Unit::TestCase
|
|
215
249
|
|
216
250
|
end
|
217
251
|
|
218
|
-
class TestNameSpaces < Test
|
252
|
+
class TestNameSpaces < Builder::Test
|
219
253
|
def setup
|
220
254
|
@xml = Builder::XmlMarkup.new(:indent=>2)
|
221
255
|
end
|
@@ -267,7 +301,7 @@ class TestNameSpaces < Test::Unit::TestCase
|
|
267
301
|
end
|
268
302
|
end
|
269
303
|
|
270
|
-
class TestDeclarations < Test
|
304
|
+
class TestDeclarations < Builder::Test
|
271
305
|
def setup
|
272
306
|
@xml = Builder::XmlMarkup.new(:indent=>2)
|
273
307
|
end
|
@@ -324,7 +358,7 @@ class TestDeclarations < Test::Unit::TestCase
|
|
324
358
|
end
|
325
359
|
|
326
360
|
|
327
|
-
class TestSpecialMarkup < Test
|
361
|
+
class TestSpecialMarkup < Builder::Test
|
328
362
|
def setup
|
329
363
|
@xml = Builder::XmlMarkup.new(:indent=>2)
|
330
364
|
end
|
@@ -384,6 +418,11 @@ class TestSpecialMarkup < Test::Unit::TestCase
|
|
384
418
|
assert_equal "<![CDATA[TEST]]>\n", @xml.target!
|
385
419
|
end
|
386
420
|
|
421
|
+
def test_cdata_value
|
422
|
+
@xml.cdata_value!("content:encoded", "<p>TEST</p>")
|
423
|
+
assert_equal "<content:encoded><![CDATA[<p>TEST</p>]]></content:encoded>\n", @xml.target!
|
424
|
+
end
|
425
|
+
|
387
426
|
def test_cdata_with_ampersand
|
388
427
|
@xml.cdata!("TEST&CHECK")
|
389
428
|
assert_equal "<![CDATA[TEST&CHECK]]>\n", @xml.target!
|
@@ -395,7 +434,7 @@ class TestSpecialMarkup < Test::Unit::TestCase
|
|
395
434
|
end
|
396
435
|
end
|
397
436
|
|
398
|
-
class TestIndentedXmlMarkup < Test
|
437
|
+
class TestIndentedXmlMarkup < Builder::Test
|
399
438
|
def setup
|
400
439
|
@xml = Builder::XmlMarkup.new(:indent=>2)
|
401
440
|
end
|
@@ -419,7 +458,7 @@ class TestIndentedXmlMarkup < Test::Unit::TestCase
|
|
419
458
|
assert_equal " <name>\n <first>Jim</first>\n </name>\n", @xml.target!
|
420
459
|
end
|
421
460
|
|
422
|
-
class TestUtfMarkup < Test
|
461
|
+
class TestUtfMarkup < Builder::Test
|
423
462
|
if ! String.method_defined?(:encode)
|
424
463
|
def setup
|
425
464
|
@old_kcode = $KCODE
|
@@ -466,7 +505,7 @@ class TestIndentedXmlMarkup < Test::Unit::TestCase
|
|
466
505
|
$KCODE = encoding
|
467
506
|
string
|
468
507
|
elsif encoding == 'UTF8'
|
469
|
-
string.force_encoding('UTF-8')
|
508
|
+
string.dup.force_encoding('UTF-8')
|
470
509
|
else
|
471
510
|
string
|
472
511
|
end
|
@@ -507,7 +546,7 @@ class TestIndentedXmlMarkup < Test::Unit::TestCase
|
|
507
546
|
end
|
508
547
|
end
|
509
548
|
|
510
|
-
class TestXmlEvents < Test
|
549
|
+
class TestXmlEvents < Builder::Test
|
511
550
|
def setup
|
512
551
|
@handler = EventHandler.new
|
513
552
|
@xe = Builder::XmlEvents.new(:target=>@handler)
|
@@ -547,7 +586,7 @@ class TestIndentedXmlMarkup < Test::Unit::TestCase
|
|
547
586
|
end
|
548
587
|
|
549
588
|
def pop_text
|
550
|
-
result = ''
|
589
|
+
result = ''.dup
|
551
590
|
while ! @handler.events.empty? && @handler.events[0][0] == :text
|
552
591
|
result << @handler.events[0][1]
|
553
592
|
@handler.events.shift
|
data/test/test_method_caching.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
#--
|
4
5
|
# Portions copyright 2011 by Bart ten Brinke (info@retrosync.com).
|
@@ -9,11 +10,11 @@
|
|
9
10
|
# above copyright notice is included.
|
10
11
|
#++
|
11
12
|
|
12
|
-
require '
|
13
|
-
require '
|
13
|
+
require 'helper'
|
14
|
+
require 'preload'
|
14
15
|
require 'builder'
|
15
16
|
|
16
|
-
class TestMethodCaching < Test
|
17
|
+
class TestMethodCaching < Builder::Test
|
17
18
|
|
18
19
|
# We can directly ask if xml object responds to the cache_me or
|
19
20
|
# do_not_cache_me methods because xml is derived from BasicObject
|
@@ -54,7 +55,7 @@ class TestMethodCaching < Test::Unit::TestCase
|
|
54
55
|
def xml.method_missing(*args)
|
55
56
|
::Kernel.fail StandardError, "SHOULD BE CALLED"
|
56
57
|
end
|
57
|
-
assert_raise(StandardError,
|
58
|
+
assert_raise(StandardError, "SHOULD BE CALLED") do
|
58
59
|
xml.do_not_cache_me
|
59
60
|
end
|
60
61
|
end
|
data/test/test_namecollision.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
#--
|
4
5
|
# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
@@ -10,10 +11,10 @@
|
|
10
11
|
# above copyright notice is included.
|
11
12
|
#++
|
12
13
|
|
13
|
-
require '
|
14
|
+
require 'helper'
|
14
15
|
require 'builder/xchar'
|
15
16
|
|
16
|
-
class TestNameCollisions < Test
|
17
|
+
class TestNameCollisions < Builder::Test
|
17
18
|
module Collide
|
18
19
|
def xchr
|
19
20
|
end
|
data/test/test_xchar.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# encoding: us-ascii
|
2
4
|
|
3
5
|
#--
|
4
6
|
# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
@@ -12,7 +14,7 @@
|
|
12
14
|
|
13
15
|
#!/usr/bin/env ruby
|
14
16
|
|
15
|
-
require '
|
17
|
+
require 'helper'
|
16
18
|
require 'builder/xchar'
|
17
19
|
|
18
20
|
if String.method_defined?(:encode)
|
@@ -21,9 +23,9 @@ if String.method_defined?(:encode)
|
|
21
23
|
|
22
24
|
# shim method for testing purposes
|
23
25
|
def to_xs(escape=true)
|
24
|
-
raise NameError.new('to_xs') unless caller[0].index(__FILE__)
|
26
|
+
# raise NameError.new('to_xs') unless caller[0].index(__FILE__)
|
25
27
|
|
26
|
-
result = Builder::XChar.encode(self)
|
28
|
+
result = Builder::XChar.encode(self.dup)
|
27
29
|
if escape
|
28
30
|
result.gsub(/[^\u0000-\u007F]/) {|c| "&##{c.ord};"}
|
29
31
|
else
|
@@ -34,7 +36,7 @@ if String.method_defined?(:encode)
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
class TestXmlEscaping < Test
|
39
|
+
class TestXmlEscaping < Builder::Test
|
38
40
|
REPLACEMENT_CHAR = Builder::XChar::REPLACEMENT_CHAR.to_xs
|
39
41
|
|
40
42
|
def test_ascii
|
@@ -67,11 +69,17 @@ class TestXmlEscaping < Test::Unit::TestCase
|
|
67
69
|
assert_equal '’', "\xE2\x80\x99".to_xs # right single quote
|
68
70
|
assert_equal '©', "\xC2\xA9".to_xs # copy
|
69
71
|
end
|
70
|
-
|
72
|
+
|
71
73
|
def test_utf8_verbatim
|
72
|
-
assert_equal "\xE2\x80\x99", "\xE2\x80\x99".to_xs(false) # right single quote
|
73
|
-
assert_equal "\xC2\xA9", "\xC2\xA9".to_xs(false) # copy
|
74
|
-
assert_equal "\xC2\xA9&\xC2\xA9",
|
75
|
-
"\xC2\xA9&\xC2\xA9".to_xs(false)
|
74
|
+
assert_equal binary("\xE2\x80\x99"), "\xE2\x80\x99".to_xs(false) # right single quote
|
75
|
+
assert_equal binary("\xC2\xA9"), "\xC2\xA9".to_xs(false) # copy
|
76
|
+
assert_equal binary("\xC2\xA9&\xC2\xA9"),
|
77
|
+
"\xC2\xA9&\xC2\xA9".to_xs(false) # copy with ampersand
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def binary(string)
|
83
|
+
string.dup.force_encoding(Encoding::BINARY)
|
76
84
|
end
|
77
85
|
end
|
metadata
CHANGED
@@ -1,47 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
5
|
-
prerelease:
|
4
|
+
version: 3.2.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jim Weirich
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description:
|
15
|
-
data
|
16
|
-
|
13
|
+
description: |
|
14
|
+
Builder provides a number of builder objects that make creating structured data
|
17
15
|
simple to do. Currently the following builder objects are supported:
|
18
16
|
|
19
|
-
|
20
17
|
* XML Markup
|
21
|
-
|
22
18
|
* XML Events
|
23
|
-
|
24
|
-
'
|
25
19
|
email: jim.weirich@gmail.com
|
26
20
|
executables: []
|
27
21
|
extensions: []
|
28
22
|
extra_rdoc_files:
|
29
23
|
- CHANGES
|
30
24
|
- MIT-LICENSE
|
25
|
+
- README.md
|
31
26
|
- Rakefile
|
32
|
-
-
|
27
|
+
- builder.blurb
|
28
|
+
- builder.gemspec
|
33
29
|
- doc/releases/builder-1.2.4.rdoc
|
34
30
|
- doc/releases/builder-2.0.0.rdoc
|
35
31
|
- doc/releases/builder-2.1.1.rdoc
|
36
32
|
files:
|
33
|
+
- CHANGES
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- builder.blurb
|
38
|
+
- builder.gemspec
|
39
|
+
- doc/jamis.rb
|
40
|
+
- doc/releases/builder-1.2.4.rdoc
|
41
|
+
- doc/releases/builder-2.0.0.rdoc
|
42
|
+
- doc/releases/builder-2.1.1.rdoc
|
37
43
|
- lib/blankslate.rb
|
44
|
+
- lib/builder.rb
|
38
45
|
- lib/builder/blankslate.rb
|
39
46
|
- lib/builder/version.rb
|
40
47
|
- lib/builder/xchar.rb
|
41
48
|
- lib/builder/xmlbase.rb
|
42
49
|
- lib/builder/xmlevents.rb
|
43
50
|
- lib/builder/xmlmarkup.rb
|
44
|
-
-
|
51
|
+
- rakelib/publish.rake
|
52
|
+
- rakelib/tags.rake
|
53
|
+
- rakelib/testing.rake
|
54
|
+
- test/helper.rb
|
45
55
|
- test/performance.rb
|
46
56
|
- test/preload.rb
|
47
57
|
- test/test_blankslate.rb
|
@@ -50,42 +60,33 @@ files:
|
|
50
60
|
- test/test_method_caching.rb
|
51
61
|
- test/test_namecollision.rb
|
52
62
|
- test/test_xchar.rb
|
53
|
-
- CHANGES
|
54
|
-
- MIT-LICENSE
|
55
|
-
- Rakefile
|
56
|
-
- README.rdoc
|
57
|
-
- doc/releases/builder-1.2.4.rdoc
|
58
|
-
- doc/releases/builder-2.0.0.rdoc
|
59
|
-
- doc/releases/builder-2.1.1.rdoc
|
60
63
|
homepage: http://onestepback.org
|
61
64
|
licenses:
|
62
65
|
- MIT
|
66
|
+
metadata: {}
|
63
67
|
post_install_message:
|
64
68
|
rdoc_options:
|
65
|
-
- --title
|
69
|
+
- "--title"
|
66
70
|
- Builder -- Easy XML Building
|
67
|
-
- --main
|
71
|
+
- "--main"
|
68
72
|
- README.rdoc
|
69
|
-
- --line-numbers
|
73
|
+
- "--line-numbers"
|
70
74
|
require_paths:
|
71
75
|
- lib
|
72
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
77
|
requirements:
|
75
|
-
- -
|
78
|
+
- - ">="
|
76
79
|
- !ruby/object:Gem::Version
|
77
80
|
version: '0'
|
78
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
82
|
requirements:
|
81
|
-
- -
|
83
|
+
- - ">="
|
82
84
|
- !ruby/object:Gem::Version
|
83
85
|
version: '0'
|
84
86
|
requirements: []
|
85
|
-
|
86
|
-
rubygems_version: 1.8.24
|
87
|
+
rubygems_version: 3.1.0.pre3
|
87
88
|
signing_key:
|
88
|
-
specification_version:
|
89
|
+
specification_version: 4
|
89
90
|
summary: Builders for MarkUp.
|
90
91
|
test_files:
|
91
92
|
- test/test_blankslate.rb
|