builder 2.1.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,12 +1,16 @@
1
1
  = Change Log
2
2
 
3
+ == Version 2.2.0
4
+
5
+ * Applied patch from Thijs van der Vossen to allow UTF-8 encoded
6
+ output when the encoding is UTF-8 and $KCODE is UTF8.
7
+
3
8
  == Version 2.1.2
4
9
 
5
10
  * Fixed bug where private methods in kernel could leak through using
6
11
  tag!(). Thanks to Hagen Overdick for finding and diagnosing this
7
12
  bug.
8
13
 
9
-
10
14
  == Version 2.1.1
11
15
 
12
16
  * Fixed typo in XmlMarkup class docs (ident => indent). (from Martin
data/README CHANGED
@@ -19,7 +19,7 @@ Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
19
19
  == Usage
20
20
 
21
21
  require 'rubygems'
22
- require_gem 'builder', '~> 2.0'
22
+ require_gem 'builder', '~> 3.0'
23
23
 
24
24
  builder = Builder::XmlMarkup.new
25
25
  xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
@@ -41,6 +41,10 @@ or
41
41
 
42
42
  == Compatibility
43
43
 
44
+ === Version 3.0.0
45
+
46
+ Version 3 adds Ruby 1.9.2 compatibility.
47
+
44
48
  === Version 2.0.0 Compatibility Changes
45
49
 
46
50
  Version 2.0.0 introduces automatically escaped attribute values for
@@ -126,6 +130,10 @@ incompatibility are:
126
130
  <b>version</b>:: 1.0
127
131
  <b>encoding</b>:: "UTF-8"
128
132
 
133
+ (NOTE: if the encoding is set to "UTF-8" and $KCODE is set to
134
+ "UTF8", then Builder will emit UTF-8 encoded strings rather than
135
+ encoding non-ASCII characters as entities.)
136
+
129
137
  * XML entity declarations are now supported to a small degree.
130
138
 
131
139
  xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
@@ -202,6 +210,17 @@ incompatibility are:
202
210
  xml.target! =>
203
211
  "<sample>I&#241;t&#235;rn&#226;ti&#244;n&#224;l</sample>"
204
212
 
213
+ You can get UTF-8 encoded output by making sure that the XML
214
+ encoding is set to "UTF-8" and that the $KCODE variable is set to
215
+ "UTF8".
216
+
217
+ $KCODE = 'UTF8'
218
+ xml = Builder::Markup.new
219
+ xml.instruct!(:xml, :encoding => "UTF-8")
220
+ xml.sample("I�t�rn�ti�n�l")
221
+ xml.target! =>
222
+ "<sample>I�t�rn�ti�n�l</sample>"
223
+
205
224
  == Contact
206
225
 
207
226
  Author:: Jim Weirich
@@ -0,0 +1,232 @@
1
+ = Project: Builder
2
+
3
+ == Goal
4
+
5
+ Provide a simple way to create XML markup and data structures.
6
+
7
+ == Classes
8
+
9
+ Builder::XmlMarkup:: Generate XML markup notiation
10
+ Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
11
+
12
+ <b>Notes</b>::
13
+
14
+ * An <tt>Builder::XmlTree</tt> class to generate XML tree
15
+ (i.e. DOM-like) structures is also planned, but not yet implemented.
16
+ Also, the events builder is currently lagging the markup builder in
17
+ features.
18
+
19
+ == Usage
20
+
21
+ require 'rubygems'
22
+ require_gem 'builder', '~> 2.0'
23
+
24
+ builder = Builder::XmlMarkup.new
25
+ xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
26
+ xml #=> <person><name>Jim</name><phone>555-1234</phone></person>
27
+
28
+ or
29
+
30
+ require 'rubygems'
31
+ require_gem 'builder'
32
+
33
+ builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
34
+ builder.person { |b| b.name("Jim"); b.phone("555-1234") }
35
+ #
36
+ # Prints:
37
+ # <person>
38
+ # <name>Jim</name>
39
+ # <phone>555-1234</phone>
40
+ # </person>
41
+
42
+ == Compatibility
43
+
44
+ === Version 2.0.0 Compatibility Changes
45
+
46
+ Version 2.0.0 introduces automatically escaped attribute values for
47
+ the first time. Versions prior to 2.0.0 did not insert escape
48
+ characters into attribute values in the XML markup. This allowed
49
+ attribute values to explicitly reference entities, which was
50
+ occasionally used by a small number of developers. Since strings
51
+ could always be explicitly escaped by hand, this was not a major
52
+ restriction in functionality.
53
+
54
+ However, it did suprise most users of builder. Since the body text is
55
+ normally escaped, everybody expected the attribute values to be
56
+ escaped as well. Escaped attribute values were the number one support
57
+ request on the 1.x Builder series.
58
+
59
+ Starting with Builder version 2.0.0, all attribute values expressed as
60
+ strings will be processed and the appropriate characters will be
61
+ escaped (e.g. "&" will be tranlated to "&amp;"). Attribute values
62
+ that are expressed as Symbol values will not be processed for escaped
63
+ characters and will be unchanged in output. (Yes, this probably counts
64
+ as Symbol abuse, but the convention is convenient and flexible).
65
+
66
+ Example:
67
+
68
+ xml = Builder::XmlMarkup.new
69
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&amp;There")
70
+ xml.target! =>
71
+ <sample escaped="This&amp;That" unescaped="Here&amp;There"/>
72
+
73
+ === Version 1.0.0 Compatibility Changes
74
+
75
+ Version 1.0.0 introduces some changes that are not backwards
76
+ compatible with earlier releases of builder. The main areas of
77
+ incompatibility are:
78
+
79
+ * Keyword based arguments to +new+ (rather than positional based). It
80
+ was found that a developer would often like to specify indentation
81
+ without providing an explicit target, or specify a target without
82
+ indentation. Keyword based arguments handle this situation nicely.
83
+
84
+ * Builder must now be an explicit target for markup tags. Instead of
85
+ writing
86
+
87
+ xml_markup = Builder::XmlMarkup.new
88
+ xml_markup.div { strong("text") }
89
+
90
+ you need to write
91
+
92
+ xml_markup = Builder::XmlMarkup.new
93
+ xml_markup.div { xml_markup.strong("text") }
94
+
95
+ * The builder object is passed as a parameter to all nested markup
96
+ blocks. This allows you to create a short alias for the builder
97
+ object that can be used within the block. For example, the previous
98
+ example can be written as:
99
+
100
+ xml_markup = Builder::XmlMarkup.new
101
+ xml_markup.div { |xml| xml.strong("text") }
102
+
103
+ * If you have both a pre-1.0 and a post-1.0 gem of builder installed,
104
+ you can choose which version to use through the RubyGems
105
+ +require_gem+ facility.
106
+
107
+ require_gem 'builder', "~> 0.0" # Gets the old version
108
+ require_gem 'builder', "~> 1.0" # Gets the new version
109
+
110
+ == Features
111
+
112
+ * XML Comments are supported ...
113
+
114
+ xml_markup.comment! "This is a comment"
115
+ #=> <!-- This is a comment -->
116
+
117
+ * XML processing instructions are supported ...
118
+
119
+ xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
120
+ #=> <?xml version="1.0" encoding="UTF-8"?>
121
+
122
+ If the processing instruction is omitted, it defaults to "xml".
123
+ When the processing instruction is "xml", the defaults attributes
124
+ are:
125
+
126
+ <b>version</b>:: 1.0
127
+ <b>encoding</b>:: "UTF-8"
128
+
129
+ (NOTE: if the encoding is set to "UTF-8" and $KCODE is set to
130
+ "UTF8", then Builder will emit UTF-8 encoded strings rather than
131
+ encoding non-ASCII characters as entities.)
132
+
133
+ * XML entity declarations are now supported to a small degree.
134
+
135
+ xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
136
+ #=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
137
+
138
+ The parameters to a declare! method must be either symbols or
139
+ strings. Symbols are inserted without quotes, and strings are
140
+ inserted with double quotes. Attribute-like arguments in hashes are
141
+ not allowed.
142
+
143
+ If you need to have an argument to declare! be inserted without
144
+ quotes, but the arguement does not conform to the typical Ruby
145
+ syntax for symbols, then use the :"string" form to specify a symbol.
146
+
147
+ For example:
148
+
149
+ xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
150
+ #=> <!ELEMENT chapter (title,para+)>
151
+
152
+ Nested entity declarations are allowed. For example:
153
+
154
+ @xml_markup.declare! :DOCTYPE, :chapter do |x|
155
+ x.declare! :ELEMENT, :chapter, :"(title,para+)"
156
+ x.declare! :ELEMENT, :title, :"(#PCDATA)"
157
+ x.declare! :ELEMENT, :para, :"(#PCDATA)"
158
+ end
159
+
160
+ #=>
161
+
162
+ <!DOCTYPE chapter [
163
+ <!ELEMENT chapter (title,para+)>
164
+ <!ELEMENT title (#PCDATA)>
165
+ <!ELEMENT para (#PCDATA)>
166
+ ]>
167
+
168
+ * Some support for XML namespaces is now available. If the first
169
+ argument to a tag call is a symbol, it will be joined to the tag to
170
+ produce a namespace:tag combination. It is easier to show this than
171
+ describe it.
172
+
173
+ xml.SOAP :Envelope do ... end
174
+
175
+ Just put a space before the colon in a namespace to produce the
176
+ right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
177
+ "<tt>xml.SOAP :Envelope</tt>")
178
+
179
+ * String attribute values are <em>now</em> escaped by default by
180
+ Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
181
+
182
+ However, occasionally you need to use entities in attribute values.
183
+ Using a symbols (rather than a string) for an attribute value will
184
+ cause Builder to not run its quoting/escaping algorithm on that
185
+ particular value.
186
+
187
+ (<b>Note:</b> The +escape_attrs+ option for builder is now
188
+ obsolete).
189
+
190
+ Example:
191
+
192
+ xml = Builder::XmlMarkup.new
193
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&amp;There")
194
+ xml.target! =>
195
+ <sample escaped="This&amp;That" unescaped="Here&amp;There"/>
196
+
197
+ * UTF-8 Support
198
+
199
+ Builder correctly translates UTF-8 characters into valid XML. (New
200
+ in version 2.0.0). Thanks to Sam Ruby for the translation code.
201
+
202
+ Example:
203
+
204
+ xml = Builder::Markup.new
205
+ xml.sample("I�t�rn�ti�n�l")
206
+ xml.target! =>
207
+ "<sample>I&#241;t&#235;rn&#226;ti&#244;n&#224;l</sample>"
208
+
209
+ You can get UTF-8 encoded output by making sure that the XML
210
+ encoding is set to "UTF-8" and that the $KCODE variable is set to
211
+ "UTF8".
212
+
213
+ $KCODE = 'UTF8'
214
+ xml = Builder::Markup.new
215
+ xml.instruct!(:xml, :encoding => "UTF-8")
216
+ xml.sample("I�t�rn�ti�n�l")
217
+ xml.target! =>
218
+ "<sample>I�t�rn�ti�n�l</sample>"
219
+
220
+ == Links
221
+
222
+ Documents:: http://builder.rubyforge.org/
223
+ Github Clone:: git://github.com/jimweirich/builder.git
224
+ Issue Tracking:: http://www.pivotaltracker.com/projects/29210
225
+ Bug Reports:: http://onestepback.org/cgi-bin/bugs.cgi?project=builder
226
+
227
+ == Contact
228
+
229
+ Author:: Jim Weirich
230
+ Email:: jim@weirichhouse.org
231
+ Home Page:: http://onestepback.org
232
+ License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ end
21
21
 
22
22
  CLOBBER.include('pkg')
23
23
 
24
- CURRENT_VERSION = '2.1.2'
24
+ CURRENT_VERSION = '3.0.0'
25
25
  PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION
26
26
 
27
27
  SRC_RB = FileList['lib/**/*.rb']
@@ -41,6 +41,7 @@ task :tu => [:test_units]
41
41
 
42
42
  Rake::TestTask.new("test_units") do |t|
43
43
  t.test_files = FileList['test/test*.rb']
44
+ t.libs << "."
44
45
  t.verbose = false
45
46
  end
46
47
 
@@ -49,7 +50,7 @@ end
49
50
  rd = Rake::RDocTask.new("rdoc") { |rdoc|
50
51
  rdoc.rdoc_dir = 'html'
51
52
  rdoc.title = "Builder for Markup"
52
- rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
53
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
53
54
  rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc')
54
55
  rdoc.template = 'doc/jamis.rb'
55
56
  }
@@ -59,7 +60,7 @@ rd = Rake::RDocTask.new("rdoc") { |rdoc|
59
60
  # gem files.
60
61
 
61
62
  PKG_FILES = FileList[
62
- 'lib/**/*.rb',
63
+ 'lib/**/*.rb',
63
64
  'test/**/*.rb',
64
65
  'scripts/**/*.rb'
65
66
  ]
@@ -68,14 +69,14 @@ PKG_FILES.exclude('lib/builder/css.rb')
68
69
 
69
70
  BLANKSLATE_FILES = FileList[
70
71
  'lib/blankslate.rb',
71
- 'test/testblankslate.rb'
72
+ 'test/test_blankslate.rb'
72
73
  ]
73
74
 
74
75
  if ! defined?(Gem)
75
76
  puts "Package Target requires RubyGEMs"
76
77
  else
77
78
  spec = Gem::Specification.new do |s|
78
-
79
+
79
80
  #### Basic information.
80
81
 
81
82
  s.name = 'builder'
@@ -92,58 +93,58 @@ simple to do. Currently the following builder objects are supported:
92
93
  s.files = PKG_FILES.to_a
93
94
  s.require_path = 'lib'
94
95
  s.autorequire = 'builder'
95
-
96
+
96
97
  s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
97
-
98
+
98
99
  s.has_rdoc = true
99
100
  s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
100
101
  s.rdoc_options <<
101
102
  '--title' << 'Builder -- Easy XML Building' <<
102
- '--main' << 'README' <<
103
+ '--main' << 'README.rdoc' <<
103
104
  '--line-numbers'
104
-
105
+
105
106
  s.author = "Jim Weirich"
106
107
  s.email = "jim@weirichhouse.org"
107
108
  s.homepage = "http://onestepback.org"
108
109
  end
109
-
110
+
110
111
  blankslate_spec = Gem::Specification.new do |s|
111
-
112
+
112
113
  #### Basic information.
113
-
114
+
114
115
  s.name = 'blankslate'
115
116
  s.version = PKG_VERSION
116
117
  s.summary = "Blank Slate base class."
117
118
  s.description = %{\
118
119
  BlankSlate provides a base class where almost all of the methods from Object and
119
120
  Kernel have been removed. This is useful when providing proxy object and other
120
- classes that make heavy use of method_missing.
121
+ classes that make heavy use of method_missing.
121
122
  }
122
-
123
+
123
124
  s.files = BLANKSLATE_FILES.to_a
124
125
  s.require_path = 'lib'
125
126
  s.autorequire = 'builder'
126
-
127
+
127
128
  s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
128
-
129
+
129
130
  s.has_rdoc = true
130
131
  s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
131
132
  s.rdoc_options <<
132
133
  '--title' << 'BlankSlate -- Base Class for building proxies.' <<
133
- '--main' << 'README' <<
134
+ '--main' << 'README.rdoc' <<
134
135
  '--line-numbers'
135
-
136
+
136
137
  s.author = "Jim Weirich"
137
138
  s.email = "jim@weirichhouse.org"
138
139
  s.homepage = "http://onestepback.org"
139
140
  end
140
-
141
+
141
142
  namespace 'builder' do
142
143
  Rake::GemPackageTask.new(spec) do |t|
143
144
  t.need_tar = true
144
145
  end
145
146
  end
146
-
147
+
147
148
  namespace 'blankslate' do
148
149
  Rake::GemPackageTask.new(blankslate_spec) do |t|
149
150
  t.need_tar = true
@@ -157,7 +158,41 @@ desc "Look for Debugging print lines"
157
158
  task :dbg do
158
159
  FileList['**/*.rb'].egrep /\bDBG|\bbreakpoint\b/
159
160
  end
160
-
161
+
162
+
163
+ # RCov ---------------------------------------------------------------
164
+ begin
165
+ require 'rcov/rcovtask'
166
+
167
+ Rcov::RcovTask.new do |t|
168
+ t.libs << "test"
169
+ t.rcov_opts = [
170
+ '-xRakefile', '--text-report'
171
+ ]
172
+ t.test_files = FileList[
173
+ 'test/test*.rb'
174
+ ]
175
+ t.output_dir = 'coverage'
176
+ t.verbose = true
177
+ end
178
+ rescue LoadError
179
+ # No rcov available
180
+ end
181
+
182
+ # Tags file ----------------------------------------------------------
183
+
184
+ namespace "tags" do
185
+ desc "Create a TAGS file"
186
+ task :emacs => "TAGS"
187
+
188
+ TAGS = 'xctags -e'
189
+
190
+ file "TAGS" => SRC_RB do
191
+ puts "Makings TAGS"
192
+ sh "#{TAGS} #{SRC_RB}", :verbose => false
193
+ end
194
+ end
195
+
161
196
  # --------------------------------------------------------------------
162
197
  # Creating a release
163
198
 
@@ -173,23 +208,23 @@ task :release => [
173
208
  :update_version,
174
209
  :package,
175
210
  :tag] do
176
-
177
- announce
211
+
212
+ announce
178
213
  announce "**************************************************************"
179
214
  announce "* Release #{PKG_VERSION} Complete."
180
215
  announce "* Packages ready to upload."
181
216
  announce "**************************************************************"
182
- announce
217
+ announce
183
218
  end
184
219
 
185
220
  # Validate that everything is ready to go for a release.
186
221
  task :prerelease do
187
- announce
222
+ announce
188
223
  announce "**************************************************************"
189
224
  announce "* Making RubyGem Release #{PKG_VERSION}"
190
225
  announce "* (current version #{CURRENT_VERSION})"
191
226
  announce "**************************************************************"
192
- announce
227
+ announce
193
228
 
194
229
  # Is a release number supplied?
195
230
  unless ENV['REL']
@@ -235,7 +270,7 @@ task :update_version => [:prerelease] do
235
270
  if ENV['RELTEST']
236
271
  announce "Release Task Testing, skipping commiting of new version"
237
272
  else
238
- sh %{cvs commit -m "Updated to version #{PKG_VERSION}" Rakefile}
273
+ sh "cvs commit -m \"Updated to version #{PKG_VERSION}\" Rakefile"
239
274
  end
240
275
  end
241
276
  end
@@ -259,5 +294,3 @@ task :install_jamis_template do
259
294
  fail "Unabled to write to #{dest_dir}" unless File.writable?(dest_dir)
260
295
  install "doc/jamis.rb", dest_dir, :verbose => true
261
296
  end
262
-
263
- require 'scripts/publish'