builder 3.1.4 → 3.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.
- data/lib/builder/version.rb +2 -2
- data/lib/builder/xmlbase.rb +10 -3
- data/lib/builder/xmlmarkup.rb +25 -20
- data/test/performance.rb +2 -1
- data/test/test_markupbuilder.rb +37 -4
- data/test/test_method_caching.rb +1 -1
- data/test/test_xchar.rb +2 -1
- metadata +41 -42
- data/CHANGES +0 -101
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -225
- data/Rakefile +0 -189
- data/doc/releases/builder-1.2.4.rdoc +0 -31
- data/doc/releases/builder-2.0.0.rdoc +0 -46
- data/doc/releases/builder-2.1.1.rdoc +0 -58
data/lib/builder/version.rb
CHANGED
data/lib/builder/xmlbase.rb
CHANGED
@@ -31,6 +31,10 @@ module Builder
|
|
31
31
|
@encoding = encoding.downcase
|
32
32
|
end
|
33
33
|
|
34
|
+
def explicit_nil_handling?
|
35
|
+
@explicit_nil_handling
|
36
|
+
end
|
37
|
+
|
34
38
|
# Create a tag named +sym+. Other than the first argument which
|
35
39
|
# is the tag name, the arguments are the same as the tags
|
36
40
|
# implemented via <tt>method_missing</tt>.
|
@@ -45,7 +49,8 @@ module Builder
|
|
45
49
|
attrs ||= {}
|
46
50
|
attrs.merge!(arg)
|
47
51
|
when nil
|
48
|
-
|
52
|
+
attrs ||= {}
|
53
|
+
attrs.merge!({:nil => true}) if explicit_nil_handling?
|
49
54
|
else
|
50
55
|
text ||= ''
|
51
56
|
text << arg.to_s
|
@@ -180,8 +185,10 @@ module Builder
|
|
180
185
|
# significantly.
|
181
186
|
def cache_method_call(sym)
|
182
187
|
class << self; self; end.class_eval do
|
183
|
-
|
184
|
-
|
188
|
+
unless method_defined?(sym)
|
189
|
+
define_method(sym) do |*args, &block|
|
190
|
+
tag!(sym, *args, &block)
|
191
|
+
end
|
185
192
|
end
|
186
193
|
end
|
187
194
|
end
|
data/lib/builder/xmlmarkup.rb
CHANGED
@@ -47,7 +47,7 @@ module Builder
|
|
47
47
|
# == Notes:
|
48
48
|
#
|
49
49
|
# * The order that attributes are inserted in markup tags is
|
50
|
-
# undefined.
|
50
|
+
# undefined.
|
51
51
|
#
|
52
52
|
# * Sometimes you wish to insert text without enclosing tags. Use
|
53
53
|
# the <tt>text!</tt> method to accomplish this.
|
@@ -78,7 +78,7 @@ module Builder
|
|
78
78
|
# <tt>tag!</tt> will also take text and attribute arguments (after
|
79
79
|
# the tag name) like normal markup methods. (But see the next
|
80
80
|
# bullet item for a better way to handle XML namespaces).
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# * Direct support for XML namespaces is now available. If the
|
83
83
|
# first argument to a tag call is a symbol, it will be joined to
|
84
84
|
# the tag to produce a namespace:tag combination. It is easier to
|
@@ -93,7 +93,7 @@ module Builder
|
|
93
93
|
# * XmlMarkup builds the markup in any object (called a _target_)
|
94
94
|
# that accepts the <tt><<</tt> method. If no target is given,
|
95
95
|
# then XmlMarkup defaults to a string target.
|
96
|
-
#
|
96
|
+
#
|
97
97
|
# Examples:
|
98
98
|
#
|
99
99
|
# xm = Builder::XmlMarkup.new
|
@@ -110,7 +110,7 @@ module Builder
|
|
110
110
|
# xm = Builder::XmlMarkup.new
|
111
111
|
# x2 = Builder::XmlMarkup.new(:target=>xm)
|
112
112
|
# # Markup written to +x2+ will be send to +xm+.
|
113
|
-
#
|
113
|
+
#
|
114
114
|
# * Indentation is enabled by providing the number of spaces to
|
115
115
|
# indent for each level as a second argument to XmlBuilder.new.
|
116
116
|
# Initial indentation may be specified using a third parameter.
|
@@ -119,7 +119,7 @@ module Builder
|
|
119
119
|
#
|
120
120
|
# xm = Builder.new(:indent=>2)
|
121
121
|
# # xm will produce nicely formatted and indented XML.
|
122
|
-
#
|
122
|
+
#
|
123
123
|
# xm = Builder.new(:indent=>2, :margin=>4)
|
124
124
|
# # xm will produce nicely formatted and indented XML with 2
|
125
125
|
# # spaces per indent and an over all indentation level of 4.
|
@@ -162,34 +162,39 @@ module Builder
|
|
162
162
|
# Create an XML markup builder. Parameters are specified by an
|
163
163
|
# option hash.
|
164
164
|
#
|
165
|
-
# :target
|
165
|
+
# :target => <em>target_object</em>::
|
166
166
|
# Object receiving the markup. +target_object+ must respond to
|
167
167
|
# the <tt><<(<em>a_string</em>)</tt> operator and return
|
168
168
|
# itself. The default target is a plain string target.
|
169
|
-
#
|
170
|
-
# :indent
|
169
|
+
#
|
170
|
+
# :indent => <em>indentation</em>::
|
171
171
|
# Number of spaces used for indentation. The default is no
|
172
172
|
# indentation and no line breaks.
|
173
|
-
#
|
174
|
-
# :margin
|
173
|
+
#
|
174
|
+
# :margin => <em>initial_indentation_level</em>::
|
175
175
|
# Amount of initial indentation (specified in levels, not
|
176
176
|
# spaces).
|
177
|
-
#
|
178
|
-
# :
|
177
|
+
#
|
178
|
+
# :quote => <em>:single</em>::
|
179
|
+
# Use single quotes for attributes rather than double quotes.
|
180
|
+
#
|
181
|
+
# :escape_attrs => <em>OBSOLETE</em>::
|
179
182
|
# The :escape_attrs option is no longer supported by builder
|
180
183
|
# (and will be quietly ignored). String attribute values are
|
181
184
|
# now automatically escaped. If you need unescaped attribute
|
182
185
|
# values (perhaps you are using entities in the attribute
|
183
186
|
# values), then give the value as a Symbol. This allows much
|
184
187
|
# finer control over escaping attribute values.
|
185
|
-
#
|
188
|
+
#
|
186
189
|
def initialize(options={})
|
187
190
|
indent = options[:indent] || 0
|
188
191
|
margin = options[:margin] || 0
|
192
|
+
@quote = (options[:quote] == :single) ? "'" : '"'
|
193
|
+
@explicit_nil_handling = options[:explicit_nil_handling]
|
189
194
|
super(indent, margin)
|
190
195
|
@target = options[:target] || ""
|
191
196
|
end
|
192
|
-
|
197
|
+
|
193
198
|
# Return the target of the builder.
|
194
199
|
def target!
|
195
200
|
@target
|
@@ -265,7 +270,7 @@ module Builder
|
|
265
270
|
_ensure_no_block ::Kernel::block_given?
|
266
271
|
_special("<![CDATA[", "]]>", text.gsub(']]>', ']]]]><![CDATA[>'), nil)
|
267
272
|
end
|
268
|
-
|
273
|
+
|
269
274
|
private
|
270
275
|
|
271
276
|
# NOTE: All private methods of a builder object are prefixed when
|
@@ -275,8 +280,8 @@ module Builder
|
|
275
280
|
def _text(text)
|
276
281
|
@target << text
|
277
282
|
end
|
278
|
-
|
279
|
-
# Insert special instruction.
|
283
|
+
|
284
|
+
# Insert special instruction.
|
280
285
|
def _special(open, close, data=nil, attrs=nil, order=[])
|
281
286
|
_indent
|
282
287
|
@target << open
|
@@ -294,7 +299,7 @@ module Builder
|
|
294
299
|
@target << "/" if end_too
|
295
300
|
@target << ">"
|
296
301
|
end
|
297
|
-
|
302
|
+
|
298
303
|
# Insert an ending tag.
|
299
304
|
def _end_tag(sym)
|
300
305
|
@target << "</#{sym}>"
|
@@ -305,10 +310,10 @@ module Builder
|
|
305
310
|
return if attrs.nil?
|
306
311
|
order.each do |k|
|
307
312
|
v = attrs[k]
|
308
|
-
@target << %{ #{k}
|
313
|
+
@target << %{ #{k}=#{@quote}#{_attr_value(v)}#{@quote}} if v
|
309
314
|
end
|
310
315
|
attrs.each do |k, v|
|
311
|
-
@target << %{ #{k}
|
316
|
+
@target << %{ #{k}=#{@quote}#{_attr_value(v)}#{@quote}} unless order.member?(k) # " WART
|
312
317
|
end
|
313
318
|
end
|
314
319
|
|
data/test/performance.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: iso-8859-1
|
2
3
|
|
3
4
|
#--
|
4
5
|
# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
@@ -13,7 +14,7 @@
|
|
13
14
|
require 'builder/xmlmarkup'
|
14
15
|
require 'benchmark'
|
15
16
|
|
16
|
-
text = "This is a test of the new xml markup. I�t�rn�ti�n�liz�ti�n\n" * 10000
|
17
|
+
text = "This is a test of the new xml markup. I�t�rn�ti�n�liz�ti�n\n" * 10000
|
17
18
|
|
18
19
|
include Benchmark # we need the CAPTION and FMTSTR constants
|
19
20
|
include Builder
|
data/test/test_markupbuilder.rb
CHANGED
@@ -59,23 +59,38 @@ class TestMarkup < Test::Unit::TestCase
|
|
59
59
|
assert_equal %{<ref id="12"/>}, @xml.target!
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
62
|
+
def test_single_quotes_for_attrs
|
63
|
+
@xml = Builder::XmlMarkup.new(:quote => :single)
|
64
|
+
@xml.ref(:id => 12)
|
65
|
+
assert_equal %{<ref id='12'/>}, @xml.target!
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_mixed_quotes_for_attrs
|
69
|
+
@xml = Builder::XmlMarkup.new(:quote => :single)
|
70
|
+
x = Builder::XmlMarkup.new(:target=>@xml, :quote => :double)
|
71
|
+
@xml.ref(:id => 12) do
|
72
|
+
x.link(:id => 13)
|
73
|
+
end
|
74
|
+
assert_equal %{<ref id='12'><link id="13"/></ref>}, @xml.target!
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_string_attributes_are_escaped_by_default
|
63
78
|
@xml.ref(:id => "H&R")
|
64
79
|
assert_equal %{<ref id="H&R"/>}, @xml.target!
|
65
80
|
end
|
66
81
|
|
67
|
-
|
82
|
+
def test_symbol_attributes_are_unescaped_by_default
|
68
83
|
@xml.ref(:id => :"H&R")
|
69
84
|
assert_equal %{<ref id="H&R"/>}, @xml.target!
|
70
85
|
end
|
71
86
|
|
72
|
-
def
|
87
|
+
def test_attributes_escaping_can_be_turned_on
|
73
88
|
@xml = Builder::XmlMarkup.new
|
74
89
|
@xml.ref(:id => "<H&R \"block\">")
|
75
90
|
assert_equal %{<ref id="<H&R "block">"/>}, @xml.target!
|
76
91
|
end
|
77
92
|
|
78
|
-
def
|
93
|
+
def test_mixed_attribute_escaping_with_nested_builders
|
79
94
|
x = Builder::XmlMarkup.new(:target=>@xml)
|
80
95
|
@xml.ref(:id=>:"H&R") {
|
81
96
|
x.element(:tag=>"Long&Short")
|
@@ -156,6 +171,24 @@ class TestMarkup < Test::Unit::TestCase
|
|
156
171
|
assert_equal %{<div><hi><em>H&R Block</em></div>}, @xml.target!
|
157
172
|
end
|
158
173
|
|
174
|
+
def test_nil
|
175
|
+
b = Builder::XmlMarkup.new
|
176
|
+
b.tag! "foo", nil
|
177
|
+
assert_equal %{<foo/>}, b.target!
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_nil_without_explicit_nil_handling
|
181
|
+
b = Builder::XmlMarkup.new(:explicit_nil_handling => false)
|
182
|
+
b.tag! "foo", nil
|
183
|
+
assert_equal %{<foo/>}, b.target!
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_nil_with_explicit_nil_handling
|
187
|
+
b = Builder::XmlMarkup.new(:explicit_nil_handling => true)
|
188
|
+
b.tag! "foo", nil
|
189
|
+
assert_equal %{<foo nil="true"/>}, b.target!
|
190
|
+
end
|
191
|
+
|
159
192
|
def test_non_escaping
|
160
193
|
@xml.div("ns:xml"=>:"&xml;") { |x| x << "<h&i>"; x.em("H&R Block") }
|
161
194
|
assert_equal %{<div ns:xml="&xml;"><h&i><em>H&R Block</em></div>}, @xml.target!
|
data/test/test_method_caching.rb
CHANGED
@@ -54,7 +54,7 @@ class TestMethodCaching < Test::Unit::TestCase
|
|
54
54
|
def xml.method_missing(*args)
|
55
55
|
::Kernel.fail StandardError, "SHOULD BE CALLED"
|
56
56
|
end
|
57
|
-
assert_raise(StandardError,
|
57
|
+
assert_raise(StandardError, "SHOULD BE CALLED") do
|
58
58
|
xml.do_not_cache_me
|
59
59
|
end
|
60
60
|
end
|
data/test/test_xchar.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: us-ascii
|
2
3
|
|
3
4
|
#--
|
4
5
|
# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
@@ -67,7 +68,7 @@ class TestXmlEscaping < Test::Unit::TestCase
|
|
67
68
|
assert_equal '’', "\xE2\x80\x99".to_xs # right single quote
|
68
69
|
assert_equal '©', "\xC2\xA9".to_xs # copy
|
69
70
|
end
|
70
|
-
|
71
|
+
|
71
72
|
def test_utf8_verbatim
|
72
73
|
assert_equal "\xE2\x80\x99", "\xE2\x80\x99".to_xs(false) # right single quote
|
73
74
|
assert_equal "\xC2\xA9", "\xC2\xA9".to_xs(false) # copy
|
metadata
CHANGED
@@ -1,47 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: builder
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 3
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 3.2.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Jim Weirich
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
17
|
+
|
18
|
+
date: 2013-02-23 00:00:00 Z
|
13
19
|
dependencies: []
|
14
|
-
description: ! 'Builder provides a number of builder objects that make creating structured
|
15
|
-
data
|
16
20
|
|
21
|
+
description: |
|
22
|
+
Builder provides a number of builder objects that make creating structured data
|
17
23
|
simple to do. Currently the following builder objects are supported:
|
18
|
-
|
19
|
-
|
24
|
+
|
20
25
|
* XML Markup
|
21
|
-
|
22
26
|
* XML Events
|
23
27
|
|
24
|
-
'
|
25
28
|
email: jim.weirich@gmail.com
|
26
29
|
executables: []
|
30
|
+
|
27
31
|
extensions: []
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
- README.rdoc
|
33
|
-
- doc/releases/builder-1.2.4.rdoc
|
34
|
-
- doc/releases/builder-2.0.0.rdoc
|
35
|
-
- doc/releases/builder-2.1.1.rdoc
|
36
|
-
files:
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
37
36
|
- lib/blankslate.rb
|
37
|
+
- lib/builder.rb
|
38
38
|
- lib/builder/blankslate.rb
|
39
39
|
- lib/builder/version.rb
|
40
40
|
- lib/builder/xchar.rb
|
41
41
|
- lib/builder/xmlbase.rb
|
42
42
|
- lib/builder/xmlevents.rb
|
43
43
|
- lib/builder/xmlmarkup.rb
|
44
|
-
- lib/builder.rb
|
45
44
|
- test/performance.rb
|
46
45
|
- test/preload.rb
|
47
46
|
- test/test_blankslate.rb
|
@@ -50,44 +49,44 @@ files:
|
|
50
49
|
- test/test_method_caching.rb
|
51
50
|
- test/test_namecollision.rb
|
52
51
|
- 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
52
|
homepage: http://onestepback.org
|
61
|
-
licenses:
|
53
|
+
licenses:
|
62
54
|
- MIT
|
63
55
|
post_install_message:
|
64
|
-
rdoc_options:
|
56
|
+
rdoc_options:
|
65
57
|
- --title
|
66
58
|
- Builder -- Easy XML Building
|
67
59
|
- --main
|
68
60
|
- README.rdoc
|
69
61
|
- --line-numbers
|
70
|
-
require_paths:
|
62
|
+
require_paths:
|
71
63
|
- lib
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
65
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
74
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
84
82
|
requirements: []
|
83
|
+
|
85
84
|
rubyforge_project:
|
86
85
|
rubygems_version: 1.8.24
|
87
86
|
signing_key:
|
88
87
|
specification_version: 3
|
89
88
|
summary: Builders for MarkUp.
|
90
|
-
test_files:
|
89
|
+
test_files:
|
91
90
|
- test/test_blankslate.rb
|
92
91
|
- test/test_eventbuilder.rb
|
93
92
|
- test/test_markupbuilder.rb
|
data/CHANGES
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
= Change Log
|
2
|
-
|
3
|
-
== Version 3.1.0
|
4
|
-
|
5
|
-
* Included the to_xs arity patch needed for weird Rails compatibility
|
6
|
-
issue.
|
7
|
-
|
8
|
-
* Escaping newlines in attributes now.
|
9
|
-
|
10
|
-
* Allow method caching
|
11
|
-
|
12
|
-
== Version 3.0.0
|
13
|
-
|
14
|
-
* Ruby 1.9 compatiblity issues.
|
15
|
-
|
16
|
-
== Version 2.2.0
|
17
|
-
|
18
|
-
* Applied patch from Thijs van der Vossen to allow UTF-8 encoded
|
19
|
-
output when the encoding is UTF-8 and $KCODE is UTF8.
|
20
|
-
|
21
|
-
== Version 2.1.2
|
22
|
-
|
23
|
-
* Fixed bug where private methods in kernel could leak through using
|
24
|
-
tag!(). Thanks to Hagen Overdick for finding and diagnosing this
|
25
|
-
bug.
|
26
|
-
|
27
|
-
== Version 2.1.1
|
28
|
-
|
29
|
-
* Fixed typo in XmlMarkup class docs (ident => indent). (from Martin
|
30
|
-
Fowler).
|
31
|
-
* Removed extra directory indirection from legacy CVS to SVN move.
|
32
|
-
* Removed some extraneous tabs from source.
|
33
|
-
* Fixed test on private methods in blankslate to differentiate between
|
34
|
-
targetted and untargetted private methods.
|
35
|
-
* Removed legacy capture of @self in XmlBase (@self was used back when
|
36
|
-
we used instance eval).
|
37
|
-
* Added additional tests for global functions (both direct and included).
|
38
|
-
|
39
|
-
== Version 2.1.0
|
40
|
-
|
41
|
-
* Fixed bug in BlankSlate where including a module into Object could
|
42
|
-
cause methods to leak into BlankSlate.
|
43
|
-
* Made BlankSlate available as its own gem. Currently the builder gem
|
44
|
-
still directly includes the BlankSlate code.
|
45
|
-
* Added reveal capability to BlankSlate.
|
46
|
-
|
47
|
-
== Version 2.0.0
|
48
|
-
|
49
|
-
* Added doc directory
|
50
|
-
* Added unit tests for XmlEvents.
|
51
|
-
* Added XChar module and used it in the _escape method.
|
52
|
-
* Attributes are now quoted by default when strings. Use Symbol
|
53
|
-
attribute values for unquoted behavior.
|
54
|
-
|
55
|
-
== Version 1.2.4
|
56
|
-
|
57
|
-
* Added a cdata! command to an XML Builder (from Josh Knowles).
|
58
|
-
|
59
|
-
== Version 1.2.3
|
60
|
-
|
61
|
-
The attributes in the <?xml ... ?> instruction will be ordered:
|
62
|
-
version, encoding, standalone.
|
63
|
-
|
64
|
-
== Version 1.2.2
|
65
|
-
|
66
|
-
Another fix for BlankSlate. The Kernal/Object traps added in 1.2.1
|
67
|
-
failed when a method was defined late more than once. Since the
|
68
|
-
method was already marked as removed, another attempt to undefine it
|
69
|
-
raised an error. The fix was to check the list of instance methods
|
70
|
-
before attempting the undef operation. Thanks to Florian Gross and
|
71
|
-
David Heinemeier Hansson for the patch.
|
72
|
-
|
73
|
-
== Version 1.2.1
|
74
|
-
|
75
|
-
BlankSlate now traps method definitions in Kernel and Object to avoid
|
76
|
-
late method definitions inadvertently becoming part of the definition
|
77
|
-
of BlankSlate as well.
|
78
|
-
|
79
|
-
== Version 1.2.0
|
80
|
-
|
81
|
-
Improved support for entity declarations by allowing nested
|
82
|
-
declarations and removal of the attribute processing.
|
83
|
-
|
84
|
-
Added namespace support.
|
85
|
-
|
86
|
-
== Version 1.1.0
|
87
|
-
|
88
|
-
Added support for comments, entity declarations and processing instructions.
|
89
|
-
|
90
|
-
== Version 1.0.0
|
91
|
-
|
92
|
-
Removed use of <tt>instace_eval</tt> making the use of XmlMarkup much
|
93
|
-
less prone to error.
|
94
|
-
|
95
|
-
== Version 0.1.1
|
96
|
-
|
97
|
-
Bug fix.
|
98
|
-
|
99
|
-
== Version 0.1.0
|
100
|
-
|
101
|
-
Initial version release.
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2003-2012 Jim Weirich (jim.weirich@gmail.com)
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,225 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
= Project: Builder
|
3
|
-
|
4
|
-
== Goal
|
5
|
-
|
6
|
-
Provide a simple way to create XML markup and data structures.
|
7
|
-
|
8
|
-
== Classes
|
9
|
-
|
10
|
-
Builder::XmlMarkup:: Generate XML markup notiation
|
11
|
-
Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
|
12
|
-
|
13
|
-
<b>Notes</b>::
|
14
|
-
|
15
|
-
* An <tt>Builder::XmlTree</tt> class to generate XML tree
|
16
|
-
(i.e. DOM-like) structures is also planned, but not yet implemented.
|
17
|
-
Also, the events builder is currently lagging the markup builder in
|
18
|
-
features.
|
19
|
-
|
20
|
-
== Usage
|
21
|
-
|
22
|
-
require 'rubygems'
|
23
|
-
require_gem 'builder', '~> 2.0'
|
24
|
-
|
25
|
-
builder = Builder::XmlMarkup.new
|
26
|
-
xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
27
|
-
xml #=> <person><name>Jim</name><phone>555-1234</phone></person>
|
28
|
-
|
29
|
-
or
|
30
|
-
|
31
|
-
require 'rubygems'
|
32
|
-
require_gem 'builder'
|
33
|
-
|
34
|
-
builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
|
35
|
-
builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
36
|
-
#
|
37
|
-
# Prints:
|
38
|
-
# <person>
|
39
|
-
# <name>Jim</name>
|
40
|
-
# <phone>555-1234</phone>
|
41
|
-
# </person>
|
42
|
-
|
43
|
-
== Compatibility
|
44
|
-
|
45
|
-
=== Version 2.0.0 Compatibility Changes
|
46
|
-
|
47
|
-
Version 2.0.0 introduces automatically escaped attribute values for
|
48
|
-
the first time. Versions prior to 2.0.0 did not insert escape
|
49
|
-
characters into attribute values in the XML markup. This allowed
|
50
|
-
attribute values to explicitly reference entities, which was
|
51
|
-
occasionally used by a small number of developers. Since strings
|
52
|
-
could always be explicitly escaped by hand, this was not a major
|
53
|
-
restriction in functionality.
|
54
|
-
|
55
|
-
However, it did suprise most users of builder. Since the body text is
|
56
|
-
normally escaped, everybody expected the attribute values to be
|
57
|
-
escaped as well. Escaped attribute values were the number one support
|
58
|
-
request on the 1.x Builder series.
|
59
|
-
|
60
|
-
Starting with Builder version 2.0.0, all attribute values expressed as
|
61
|
-
strings will be processed and the appropriate characters will be
|
62
|
-
escaped (e.g. "&" will be tranlated to "&"). Attribute values
|
63
|
-
that are expressed as Symbol values will not be processed for escaped
|
64
|
-
characters and will be unchanged in output. (Yes, this probably counts
|
65
|
-
as Symbol abuse, but the convention is convenient and flexible).
|
66
|
-
|
67
|
-
Example:
|
68
|
-
|
69
|
-
xml = Builder::XmlMarkup.new
|
70
|
-
xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
|
71
|
-
xml.target! =>
|
72
|
-
<sample escaped="This&That" unescaped="Here&There"/>
|
73
|
-
|
74
|
-
=== Version 1.0.0 Compatibility Changes
|
75
|
-
|
76
|
-
Version 1.0.0 introduces some changes that are not backwards
|
77
|
-
compatible with earlier releases of builder. The main areas of
|
78
|
-
incompatibility are:
|
79
|
-
|
80
|
-
* Keyword based arguments to +new+ (rather than positional based). It
|
81
|
-
was found that a developer would often like to specify indentation
|
82
|
-
without providing an explicit target, or specify a target without
|
83
|
-
indentation. Keyword based arguments handle this situation nicely.
|
84
|
-
|
85
|
-
* Builder must now be an explicit target for markup tags. Instead of
|
86
|
-
writing
|
87
|
-
|
88
|
-
xml_markup = Builder::XmlMarkup.new
|
89
|
-
xml_markup.div { strong("text") }
|
90
|
-
|
91
|
-
you need to write
|
92
|
-
|
93
|
-
xml_markup = Builder::XmlMarkup.new
|
94
|
-
xml_markup.div { xml_markup.strong("text") }
|
95
|
-
|
96
|
-
* The builder object is passed as a parameter to all nested markup
|
97
|
-
blocks. This allows you to create a short alias for the builder
|
98
|
-
object that can be used within the block. For example, the previous
|
99
|
-
example can be written as:
|
100
|
-
|
101
|
-
xml_markup = Builder::XmlMarkup.new
|
102
|
-
xml_markup.div { |xml| xml.strong("text") }
|
103
|
-
|
104
|
-
* If you have both a pre-1.0 and a post-1.0 gem of builder installed,
|
105
|
-
you can choose which version to use through the RubyGems
|
106
|
-
+require_gem+ facility.
|
107
|
-
|
108
|
-
require_gem 'builder', "~> 0.0" # Gets the old version
|
109
|
-
require_gem 'builder', "~> 1.0" # Gets the new version
|
110
|
-
|
111
|
-
== Features
|
112
|
-
|
113
|
-
* XML Comments are supported ...
|
114
|
-
|
115
|
-
xml_markup.comment! "This is a comment"
|
116
|
-
#=> <!-- This is a comment -->
|
117
|
-
|
118
|
-
* XML processing instructions are supported ...
|
119
|
-
|
120
|
-
xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
121
|
-
#=> <?xml version="1.0" encoding="UTF-8"?>
|
122
|
-
|
123
|
-
If the processing instruction is omitted, it defaults to "xml".
|
124
|
-
When the processing instruction is "xml", the defaults attributes
|
125
|
-
are:
|
126
|
-
|
127
|
-
<b>version</b>:: 1.0
|
128
|
-
<b>encoding</b>:: "UTF-8"
|
129
|
-
|
130
|
-
(NOTE: if the encoding is set to "UTF-8" and $KCODE is set to
|
131
|
-
"UTF8", then Builder will emit UTF-8 encoded strings rather than
|
132
|
-
encoding non-ASCII characters as entities.)
|
133
|
-
|
134
|
-
* XML entity declarations are now supported to a small degree.
|
135
|
-
|
136
|
-
xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
|
137
|
-
#=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
|
138
|
-
|
139
|
-
The parameters to a declare! method must be either symbols or
|
140
|
-
strings. Symbols are inserted without quotes, and strings are
|
141
|
-
inserted with double quotes. Attribute-like arguments in hashes are
|
142
|
-
not allowed.
|
143
|
-
|
144
|
-
If you need to have an argument to declare! be inserted without
|
145
|
-
quotes, but the arguement does not conform to the typical Ruby
|
146
|
-
syntax for symbols, then use the :"string" form to specify a symbol.
|
147
|
-
|
148
|
-
For example:
|
149
|
-
|
150
|
-
xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
|
151
|
-
#=> <!ELEMENT chapter (title,para+)>
|
152
|
-
|
153
|
-
Nested entity declarations are allowed. For example:
|
154
|
-
|
155
|
-
@xml_markup.declare! :DOCTYPE, :chapter do |x|
|
156
|
-
x.declare! :ELEMENT, :chapter, :"(title,para+)"
|
157
|
-
x.declare! :ELEMENT, :title, :"(#PCDATA)"
|
158
|
-
x.declare! :ELEMENT, :para, :"(#PCDATA)"
|
159
|
-
end
|
160
|
-
|
161
|
-
#=>
|
162
|
-
|
163
|
-
<!DOCTYPE chapter [
|
164
|
-
<!ELEMENT chapter (title,para+)>
|
165
|
-
<!ELEMENT title (#PCDATA)>
|
166
|
-
<!ELEMENT para (#PCDATA)>
|
167
|
-
]>
|
168
|
-
|
169
|
-
* Some support for XML namespaces is now available. If the first
|
170
|
-
argument to a tag call is a symbol, it will be joined to the tag to
|
171
|
-
produce a namespace:tag combination. It is easier to show this than
|
172
|
-
describe it.
|
173
|
-
|
174
|
-
xml.SOAP :Envelope do ... end
|
175
|
-
|
176
|
-
Just put a space before the colon in a namespace to produce the
|
177
|
-
right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
|
178
|
-
"<tt>xml.SOAP :Envelope</tt>")
|
179
|
-
|
180
|
-
* String attribute values are <em>now</em> escaped by default by
|
181
|
-
Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
|
182
|
-
|
183
|
-
However, occasionally you need to use entities in attribute values.
|
184
|
-
Using a symbols (rather than a string) for an attribute value will
|
185
|
-
cause Builder to not run its quoting/escaping algorithm on that
|
186
|
-
particular value.
|
187
|
-
|
188
|
-
(<b>Note:</b> The +escape_attrs+ option for builder is now
|
189
|
-
obsolete).
|
190
|
-
|
191
|
-
Example:
|
192
|
-
|
193
|
-
xml = Builder::XmlMarkup.new
|
194
|
-
xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
|
195
|
-
xml.target! =>
|
196
|
-
<sample escaped="This&That" unescaped="Here&There"/>
|
197
|
-
|
198
|
-
* UTF-8 Support
|
199
|
-
|
200
|
-
Builder correctly translates UTF-8 characters into valid XML. (New
|
201
|
-
in version 2.0.0). Thanks to Sam Ruby for the translation code.
|
202
|
-
|
203
|
-
You can get UTF-8 encoded output by making sure that the XML
|
204
|
-
encoding is set to "UTF-8" and that the $KCODE variable is set to
|
205
|
-
"UTF8".
|
206
|
-
|
207
|
-
$KCODE = 'UTF8'
|
208
|
-
xml = Builder::Markup.new
|
209
|
-
xml.instruct!(:xml, :encoding => "UTF-8")
|
210
|
-
xml.sample("Iñtërnâtiônàl")
|
211
|
-
xml.target! =>
|
212
|
-
"<sample>Iñtërnâtiônàl</sample>"
|
213
|
-
|
214
|
-
== Links
|
215
|
-
|
216
|
-
Documents :: http://builder.rubyforge.org/
|
217
|
-
Github Clone :: git://github.com/jimweirich/builder.git
|
218
|
-
Issue / Bug Reports :: https://github.com/jimweirich/builder/issues?state=open
|
219
|
-
|
220
|
-
== Contact
|
221
|
-
|
222
|
-
Author:: Jim Weirich
|
223
|
-
Email:: jim.weirich@gmail.com
|
224
|
-
Home Page:: http://onestepback.org
|
225
|
-
License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
|
data/Rakefile
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
# Rakefile for rake -*- ruby -*-
|
2
|
-
|
3
|
-
# Copyright 2004, 2005, 2006 by Jim Weirich (jim@weirichhouse.org).
|
4
|
-
# All rights reserved.
|
5
|
-
|
6
|
-
# Permission is granted for use, copying, modification, distribution,
|
7
|
-
# and distribution of modified versions of this work as long as the
|
8
|
-
# above copyright notice is included.
|
9
|
-
|
10
|
-
require 'rake/clean'
|
11
|
-
require 'rake/testtask'
|
12
|
-
require 'rdoc/task'
|
13
|
-
begin
|
14
|
-
require 'rubygems'
|
15
|
-
require 'rubygems/package_task'
|
16
|
-
rescue Exception
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
|
20
|
-
require './lib/builder/version'
|
21
|
-
|
22
|
-
# Determine the current version of the software
|
23
|
-
|
24
|
-
CLOBBER.include('pkg')
|
25
|
-
CLEAN.include('pkg/builder-*').include('pkg/blankslate-*').exclude('pkg/*.gem')
|
26
|
-
|
27
|
-
PKG_VERSION = Builder::VERSION
|
28
|
-
|
29
|
-
SRC_RB = FileList['lib/**/*.rb']
|
30
|
-
|
31
|
-
# The default task is run if rake is given no explicit arguments.
|
32
|
-
|
33
|
-
desc "Default Task"
|
34
|
-
task :default => :test_all
|
35
|
-
|
36
|
-
# Test Tasks ---------------------------------------------------------
|
37
|
-
|
38
|
-
desc "Run all tests"
|
39
|
-
task :test_all => [:test_units]
|
40
|
-
task :ta => [:test_all]
|
41
|
-
|
42
|
-
task :tu => [:test_units]
|
43
|
-
|
44
|
-
Rake::TestTask.new("test_units") do |t|
|
45
|
-
t.test_files = FileList['test/test*.rb']
|
46
|
-
t.libs << "."
|
47
|
-
t.verbose = false
|
48
|
-
end
|
49
|
-
|
50
|
-
# Create a task to build the RDOC documentation tree.
|
51
|
-
|
52
|
-
rd = RDoc::Task.new("rdoc") { |rdoc|
|
53
|
-
rdoc.rdoc_dir = 'html'
|
54
|
-
rdoc.title = "Builder for Markup"
|
55
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
|
56
|
-
rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc').exclude("TAGS")
|
57
|
-
rdoc.template = 'doc/jamis.rb'
|
58
|
-
}
|
59
|
-
|
60
|
-
# ====================================================================
|
61
|
-
# Create a task that will package the Rake software into distributable
|
62
|
-
# gem files.
|
63
|
-
|
64
|
-
PKG_FILES = FileList[
|
65
|
-
'lib/**/*.rb',
|
66
|
-
'test/**/*.rb',
|
67
|
-
'scripts/**/*.rb'
|
68
|
-
]
|
69
|
-
PKG_FILES.exclude('test/test_cssbuilder.rb')
|
70
|
-
PKG_FILES.exclude('lib/builder/css.rb')
|
71
|
-
PKG_FILES.exclude('TAGS')
|
72
|
-
|
73
|
-
BLANKSLATE_FILES = FileList[
|
74
|
-
'lib/blankslate.rb',
|
75
|
-
'test/test_blankslate.rb'
|
76
|
-
]
|
77
|
-
|
78
|
-
if ! defined?(Gem)
|
79
|
-
puts "Package Target requires RubyGEMs"
|
80
|
-
else
|
81
|
-
spec = Gem::Specification.new do |s|
|
82
|
-
|
83
|
-
#### Basic information.
|
84
|
-
|
85
|
-
s.name = 'builder'
|
86
|
-
s.version = PKG_VERSION
|
87
|
-
s.summary = "Builders for MarkUp."
|
88
|
-
s.description = %{\
|
89
|
-
Builder provides a number of builder objects that make creating structured data
|
90
|
-
simple to do. Currently the following builder objects are supported:
|
91
|
-
|
92
|
-
* XML Markup
|
93
|
-
* XML Events
|
94
|
-
}
|
95
|
-
|
96
|
-
s.files = PKG_FILES.to_a
|
97
|
-
s.require_path = 'lib'
|
98
|
-
|
99
|
-
s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
|
100
|
-
|
101
|
-
s.has_rdoc = true
|
102
|
-
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
|
103
|
-
s.rdoc_options <<
|
104
|
-
'--title' << 'Builder -- Easy XML Building' <<
|
105
|
-
'--main' << 'README.rdoc' <<
|
106
|
-
'--line-numbers'
|
107
|
-
|
108
|
-
s.author = "Jim Weirich"
|
109
|
-
s.email = "jim.weirich@gmail.com"
|
110
|
-
s.homepage = "http://onestepback.org"
|
111
|
-
s.license = 'MIT'
|
112
|
-
end
|
113
|
-
|
114
|
-
blankslate_spec = Gem::Specification.new do |s|
|
115
|
-
|
116
|
-
#### Basic information.
|
117
|
-
|
118
|
-
s.name = 'blankslate'
|
119
|
-
s.version = PKG_VERSION
|
120
|
-
s.summary = "Blank Slate base class."
|
121
|
-
s.description = %{\
|
122
|
-
BlankSlate provides a base class where almost all of the methods from Object and
|
123
|
-
Kernel have been removed. This is useful when providing proxy object and other
|
124
|
-
classes that make heavy use of method_missing.
|
125
|
-
}
|
126
|
-
|
127
|
-
s.files = BLANKSLATE_FILES.to_a
|
128
|
-
s.require_path = 'lib'
|
129
|
-
|
130
|
-
s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
|
131
|
-
|
132
|
-
s.has_rdoc = true
|
133
|
-
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
|
134
|
-
s.rdoc_options <<
|
135
|
-
'--title' << 'BlankSlate -- Base Class for building proxies.' <<
|
136
|
-
'--main' << 'README.rdoc' <<
|
137
|
-
'--line-numbers'
|
138
|
-
|
139
|
-
s.author = "Jim Weirich"
|
140
|
-
s.email = "jim.weirich@gmail.com"
|
141
|
-
s.homepage = "http://onestepback.org"
|
142
|
-
s.license = 'MIT'
|
143
|
-
end
|
144
|
-
|
145
|
-
namespace 'builder' do
|
146
|
-
Gem::PackageTask.new(spec) do |t|
|
147
|
-
t.need_tar = false
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
namespace 'blankslate' do
|
152
|
-
Gem::PackageTask.new(blankslate_spec) do |t|
|
153
|
-
t.need_tar = false
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
task :package => [:remove_tags, 'builder:package', 'blankslate:package']
|
158
|
-
end
|
159
|
-
|
160
|
-
task :remove_tags do
|
161
|
-
rm "TAGS" rescue nil
|
162
|
-
end
|
163
|
-
|
164
|
-
# RCov ---------------------------------------------------------------
|
165
|
-
begin
|
166
|
-
require 'rcov/rcovtask'
|
167
|
-
|
168
|
-
Rcov::RcovTask.new do |t|
|
169
|
-
t.libs << "test"
|
170
|
-
t.rcov_opts = [
|
171
|
-
'-xRakefile', '--text-report'
|
172
|
-
]
|
173
|
-
t.test_files = FileList[
|
174
|
-
'test/test*.rb'
|
175
|
-
]
|
176
|
-
t.output_dir = 'coverage'
|
177
|
-
t.verbose = true
|
178
|
-
end
|
179
|
-
rescue LoadError
|
180
|
-
# No rcov available
|
181
|
-
end
|
182
|
-
|
183
|
-
desc "Install the jamis RDoc template"
|
184
|
-
task :install_jamis_template do
|
185
|
-
require 'rbconfig'
|
186
|
-
dest_dir = File.join(Config::CONFIG['rubylibdir'], "rdoc/generators/template/html")
|
187
|
-
fail "Unabled to write to #{dest_dir}" unless File.writable?(dest_dir)
|
188
|
-
install "doc/jamis.rb", dest_dir, :verbose => true
|
189
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
= Builder 1.2.4 Released.
|
2
|
-
|
3
|
-
Added a "CDATA" method to the XML Markup builder (from Josh Knowles).
|
4
|
-
|
5
|
-
== What is Builder?
|
6
|
-
|
7
|
-
Builder::XmlMarkup allows easy programmatic creation of XML markup.
|
8
|
-
For example:
|
9
|
-
|
10
|
-
builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
|
11
|
-
builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
12
|
-
puts builder.target!
|
13
|
-
|
14
|
-
will generate:
|
15
|
-
|
16
|
-
<person>
|
17
|
-
<name>Jim</name>
|
18
|
-
<phone>555-1234</phone>
|
19
|
-
</person>
|
20
|
-
|
21
|
-
== Availability
|
22
|
-
|
23
|
-
The easiest way to get and install builder is via RubyGems ...
|
24
|
-
|
25
|
-
gem install builder (you may need root/admin privileges)
|
26
|
-
|
27
|
-
== Thanks
|
28
|
-
|
29
|
-
* Josh Knowles for the cdata! patch.
|
30
|
-
|
31
|
-
-- Jim Weirich
|
@@ -1,46 +0,0 @@
|
|
1
|
-
= Builder 2.0.0 Released.
|
2
|
-
|
3
|
-
== Changes in 2.0.0
|
4
|
-
|
5
|
-
* UTF-8 characters in data are now correctly translated to their XML
|
6
|
-
equivalents. (Thanks to Sam Ruby)
|
7
|
-
|
8
|
-
* Attribute values are now escaped by default. See the README
|
9
|
-
file for details.
|
10
|
-
|
11
|
-
<b>NOTE:</b> The escaping attribute values by default is different
|
12
|
-
than in previous releases of Builder. This makes version 2.0.0
|
13
|
-
somewhat incompatible with the 1.x series of Builder. If you use "&",
|
14
|
-
"<", or ">" in attributes values, you may have to change your
|
15
|
-
code. (Essentially you remove the manual escaping. The new way is
|
16
|
-
easier, believe me).
|
17
|
-
|
18
|
-
== What is Builder?
|
19
|
-
|
20
|
-
Builder::XmlMarkup is a library that allows easy programmatic creation
|
21
|
-
of XML markup. For example:
|
22
|
-
|
23
|
-
builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
|
24
|
-
builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
25
|
-
|
26
|
-
will generate:
|
27
|
-
|
28
|
-
<person>
|
29
|
-
<name>Jim</name>
|
30
|
-
<phone>555-1234</phone>
|
31
|
-
</person>
|
32
|
-
|
33
|
-
== Availability
|
34
|
-
|
35
|
-
The easiest way to get and install builder is via RubyGems ...
|
36
|
-
|
37
|
-
gem install builder (you may need root/admin privileges)
|
38
|
-
|
39
|
-
== Thanks
|
40
|
-
|
41
|
-
* Sam Ruby for the XChar module and the related UTF-8 translation
|
42
|
-
tools.
|
43
|
-
* Also to Sam Ruby for gently persuading me to start quoting attribute
|
44
|
-
values.
|
45
|
-
|
46
|
-
-- Jim Weirich
|
@@ -1,58 +0,0 @@
|
|
1
|
-
= Builder 2.1.1 Released.
|
2
|
-
|
3
|
-
Release 2.1.1 of Builder is mainly a bug fix release.
|
4
|
-
|
5
|
-
== Changes in 2.1.1
|
6
|
-
|
7
|
-
* Added <tt>reveal</tt> capability to BlankSlate.
|
8
|
-
|
9
|
-
* Fixed a bug in BlankSlate where including a module into Object could
|
10
|
-
cause methods to leak into BlankSlate.
|
11
|
-
|
12
|
-
* Fixed typo in XmlMarkup class docs (from Martin Fowler).
|
13
|
-
|
14
|
-
* Fixed test on private methods to differentiate between targetted and
|
15
|
-
untargetted private methods.
|
16
|
-
|
17
|
-
* Removed legacy capture of @self in XmlBase (@self was used back when
|
18
|
-
we used instance eval).
|
19
|
-
|
20
|
-
* Added additional tests for global functions (both direct and
|
21
|
-
included).
|
22
|
-
|
23
|
-
* Several misc internal cleanups, including rearranging the source
|
24
|
-
code tree.
|
25
|
-
|
26
|
-
<b>NOTE:</b> The escaping attribute values by default is different
|
27
|
-
than in previous releases of Builder. This makes version 2.0.x
|
28
|
-
somewhat incompatible with the 1.x series of Builder. If you use "&",
|
29
|
-
"<", or ">" in attributes values, you may have to change your
|
30
|
-
code. (Essentially you remove the manual escaping. The new way is
|
31
|
-
easier, believe me).
|
32
|
-
|
33
|
-
== What is Builder?
|
34
|
-
|
35
|
-
Builder::XmlMarkup is a library that allows easy programmatic creation
|
36
|
-
of XML markup. For example:
|
37
|
-
|
38
|
-
builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
|
39
|
-
builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
40
|
-
|
41
|
-
will generate:
|
42
|
-
|
43
|
-
<person>
|
44
|
-
<name>Jim</name>
|
45
|
-
<phone>555-1234</phone>
|
46
|
-
</person>
|
47
|
-
|
48
|
-
== Availability
|
49
|
-
|
50
|
-
The easiest way to get and install builder is via RubyGems ...
|
51
|
-
|
52
|
-
gem install builder (you may need root/admin privileges)
|
53
|
-
|
54
|
-
== Thanks
|
55
|
-
|
56
|
-
* Martin Fowler for spotting some typos in the documentation.
|
57
|
-
|
58
|
-
-- Jim Weirich
|