builder 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,107 @@
1
+ = Change Log
2
+
3
+ == Version 3.2.0
4
+
5
+ * Ruby 2.0 compatibility changes.
6
+
7
+ * Allow single quoted attributes.
8
+
9
+ == Version 3.1.0
10
+
11
+ * Included the to_xs arity patch needed for weird Rails compatibility
12
+ issue.
13
+
14
+ * Escaping newlines in attributes now.
15
+
16
+ * Allow method caching
17
+
18
+ == Version 3.0.0
19
+
20
+ * Ruby 1.9 compatiblity issues.
21
+
22
+ == Version 2.2.0
23
+
24
+ * Applied patch from Thijs van der Vossen to allow UTF-8 encoded
25
+ output when the encoding is UTF-8 and $KCODE is UTF8.
26
+
27
+ == Version 2.1.2
28
+
29
+ * Fixed bug where private methods in kernel could leak through using
30
+ tag!(). Thanks to Hagen Overdick for finding and diagnosing this
31
+ bug.
32
+
33
+ == Version 2.1.1
34
+
35
+ * Fixed typo in XmlMarkup class docs (ident => indent). (from Martin
36
+ Fowler).
37
+ * Removed extra directory indirection from legacy CVS to SVN move.
38
+ * Removed some extraneous tabs from source.
39
+ * Fixed test on private methods in blankslate to differentiate between
40
+ targetted and untargetted private methods.
41
+ * Removed legacy capture of @self in XmlBase (@self was used back when
42
+ we used instance eval).
43
+ * Added additional tests for global functions (both direct and included).
44
+
45
+ == Version 2.1.0
46
+
47
+ * Fixed bug in BlankSlate where including a module into Object could
48
+ cause methods to leak into BlankSlate.
49
+ * Made BlankSlate available as its own gem. Currently the builder gem
50
+ still directly includes the BlankSlate code.
51
+ * Added reveal capability to BlankSlate.
52
+
53
+ == Version 2.0.0
54
+
55
+ * Added doc directory
56
+ * Added unit tests for XmlEvents.
57
+ * Added XChar module and used it in the _escape method.
58
+ * Attributes are now quoted by default when strings. Use Symbol
59
+ attribute values for unquoted behavior.
60
+
61
+ == Version 1.2.4
62
+
63
+ * Added a cdata! command to an XML Builder (from Josh Knowles).
64
+
65
+ == Version 1.2.3
66
+
67
+ The attributes in the <?xml ... ?> instruction will be ordered:
68
+ version, encoding, standalone.
69
+
70
+ == Version 1.2.2
71
+
72
+ Another fix for BlankSlate. The Kernal/Object traps added in 1.2.1
73
+ failed when a method was defined late more than once. Since the
74
+ method was already marked as removed, another attempt to undefine it
75
+ raised an error. The fix was to check the list of instance methods
76
+ before attempting the undef operation. Thanks to Florian Gross and
77
+ David Heinemeier Hansson for the patch.
78
+
79
+ == Version 1.2.1
80
+
81
+ BlankSlate now traps method definitions in Kernel and Object to avoid
82
+ late method definitions inadvertently becoming part of the definition
83
+ of BlankSlate as well.
84
+
85
+ == Version 1.2.0
86
+
87
+ Improved support for entity declarations by allowing nested
88
+ declarations and removal of the attribute processing.
89
+
90
+ Added namespace support.
91
+
92
+ == Version 1.1.0
93
+
94
+ Added support for comments, entity declarations and processing instructions.
95
+
96
+ == Version 1.0.0
97
+
98
+ Removed use of <tt>instace_eval</tt> making the use of XmlMarkup much
99
+ less prone to error.
100
+
101
+ == Version 0.1.1
102
+
103
+ Bug fix.
104
+
105
+ == Version 0.1.0
106
+
107
+ Initial version release.
@@ -0,0 +1,20 @@
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.
@@ -0,0 +1,258 @@
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 notation
10
+ Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
11
+
12
+ **Notes:**
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
+ ```ruby
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
+
30
+ or
31
+
32
+ ```ruby
33
+ require 'rubygems'
34
+ require_gem 'builder'
35
+
36
+ builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
37
+ builder.person { |b| b.name("Jim"); b.phone("555-1234") }
38
+ #
39
+ # Prints:
40
+ # <person>
41
+ # <name>Jim</name>
42
+ # <phone>555-1234</phone>
43
+ # </person>
44
+ ```
45
+
46
+ ## Compatibility
47
+
48
+ ### Version 2.0.0 Compatibility Changes
49
+
50
+ Version 2.0.0 introduces automatically escaped attribute values for
51
+ the first time. Versions prior to 2.0.0 did not insert escape
52
+ characters into attribute values in the XML markup. This allowed
53
+ attribute values to explicitly reference entities, which was
54
+ occasionally used by a small number of developers. Since strings
55
+ could always be explicitly escaped by hand, this was not a major
56
+ restriction in functionality.
57
+
58
+ However, it did surprise most users of builder. Since the body text is
59
+ normally escaped, everybody expected the attribute values to be
60
+ escaped as well. Escaped attribute values were the number one support
61
+ request on the 1.x Builder series.
62
+
63
+ Starting with Builder version 2.0.0, all attribute values expressed as
64
+ strings will be processed and the appropriate characters will be
65
+ escaped (e.g. "&" will be translated to "&amp;"). Attribute values
66
+ that are expressed as Symbol values will not be processed for escaped
67
+ characters and will be unchanged in output. (Yes, this probably counts
68
+ as Symbol abuse, but the convention is convenient and flexible).
69
+
70
+ Example:
71
+
72
+ ```ruby
73
+ xml = Builder::XmlMarkup.new
74
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&amp;There")
75
+ xml.target! =>
76
+ <sample escaped="This&amp;That" unescaped="Here&amp;There"/>
77
+ ```
78
+
79
+ ### Version 1.0.0 Compatibility Changes
80
+
81
+ Version 1.0.0 introduces some changes that are not backwards
82
+ compatible with earlier releases of builder. The main areas of
83
+ incompatibility are:
84
+
85
+ * Keyword based arguments to +new+ (rather than positional based). It
86
+ was found that a developer would often like to specify indentation
87
+ without providing an explicit target, or specify a target without
88
+ indentation. Keyword based arguments handle this situation nicely.
89
+
90
+ * Builder must now be an explicit target for markup tags. Instead of
91
+ writing
92
+
93
+ ```ruby
94
+ xml_markup = Builder::XmlMarkup.new
95
+ xml_markup.div { strong("text") }
96
+ ```
97
+
98
+ you need to write
99
+
100
+ ```ruby
101
+ xml_markup = Builder::XmlMarkup.new
102
+ xml_markup.div { xml_markup.strong("text") }
103
+ ```
104
+
105
+ * The builder object is passed as a parameter to all nested markup
106
+ blocks. This allows you to create a short alias for the builder
107
+ object that can be used within the block. For example, the previous
108
+ example can be written as:
109
+
110
+ ```ruby
111
+ xml_markup = Builder::XmlMarkup.new
112
+ xml_markup.div { |xml| xml.strong("text") }
113
+ ```
114
+
115
+ * If you have both a pre-1.0 and a post-1.0 gem of builder installed,
116
+ you can choose which version to use through the RubyGems
117
+ +require_gem+ facility.
118
+
119
+ ```ruby
120
+ require_gem 'builder', "~> 0.0" # Gets the old version
121
+ require_gem 'builder', "~> 1.0" # Gets the new version
122
+ ```
123
+
124
+ ## Features
125
+
126
+ * XML Comments are supported ...
127
+
128
+ ```ruby
129
+ xml_markup.comment! "This is a comment"
130
+ #=> <!-- This is a comment -->
131
+ ```
132
+
133
+ * XML processing instructions are supported ...
134
+
135
+ ```ruby
136
+ xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
137
+ #=> <?xml version="1.0" encoding="UTF-8"?>
138
+ ```
139
+
140
+ If the processing instruction is omitted, it defaults to "xml".
141
+ When the processing instruction is "xml", the defaults attributes
142
+ are:
143
+
144
+ <b>version</b>: 1.0
145
+ <b>encoding</b>: "UTF-8"
146
+
147
+ (NOTE: if the encoding is set to "UTF-8" and $KCODE is set to
148
+ "UTF8", then Builder will emit UTF-8 encoded strings rather than
149
+ encoding non-ASCII characters as entities.)
150
+
151
+ * XML entity declarations are now supported to a small degree.
152
+
153
+ ```ruby
154
+ xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
155
+ #=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
156
+ ```
157
+
158
+ The parameters to a declare! method must be either symbols or
159
+ strings. Symbols are inserted without quotes, and strings are
160
+ inserted with double quotes. Attribute-like arguments in hashes are
161
+ not allowed.
162
+
163
+ If you need to have an argument to declare! be inserted without
164
+ quotes, but the argument does not conform to the typical Ruby
165
+ syntax for symbols, then use the :"string" form to specify a symbol.
166
+
167
+ For example:
168
+
169
+ ```ruby
170
+ xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
171
+ #=> <!ELEMENT chapter (title,para+)>
172
+ ```
173
+
174
+ Nested entity declarations are allowed. For example:
175
+
176
+ ```ruby
177
+ @xml_markup.declare! :DOCTYPE, :chapter do |x|
178
+ x.declare! :ELEMENT, :chapter, :"(title,para+)"
179
+ x.declare! :ELEMENT, :title, :"(#PCDATA)"
180
+ x.declare! :ELEMENT, :para, :"(#PCDATA)"
181
+ end
182
+
183
+ #=>
184
+
185
+ <!DOCTYPE chapter [
186
+ <!ELEMENT chapter (title,para+)>
187
+ <!ELEMENT title (#PCDATA)>
188
+ <!ELEMENT para (#PCDATA)>
189
+ ]>
190
+ ```
191
+
192
+ * Some support for XML namespaces is now available. If the first
193
+ argument to a tag call is a symbol, it will be joined to the tag to
194
+ produce a namespace:tag combination. It is easier to show this than
195
+ describe it.
196
+
197
+ ```ruby
198
+ xml.SOAP :Envelope do ... end
199
+ ```
200
+
201
+ Just put a space before the colon in a namespace to produce the
202
+ right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
203
+ "<tt>xml.SOAP :Envelope</tt>")
204
+
205
+ * String attribute values are <em>now</em> escaped by default by
206
+ Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
207
+
208
+ However, occasionally you need to use entities in attribute values.
209
+ Using a symbol (rather than a string) for an attribute value will
210
+ cause Builder to not run its quoting/escaping algorithm on that
211
+ particular value.
212
+
213
+ (<b>Note:</b> The +escape_attrs+ option for builder is now
214
+ obsolete).
215
+
216
+ Example:
217
+
218
+ ```ruby
219
+ xml = Builder::XmlMarkup.new
220
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&amp;There")
221
+ xml.target! =>
222
+ <sample escaped="This&amp;That" unescaped="Here&amp;There"/>
223
+ ```
224
+
225
+ * UTF-8 Support
226
+
227
+ Builder correctly translates UTF-8 characters into valid XML. (New
228
+ in version 2.0.0). Thanks to Sam Ruby for the translation code.
229
+
230
+ You can get UTF-8 encoded output by making sure that the XML
231
+ encoding is set to "UTF-8" and that the $KCODE variable is set to
232
+ "UTF8".
233
+
234
+ ```ruby
235
+ $KCODE = 'UTF8'
236
+ xml = Builder::Markup.new
237
+ xml.instruct!(:xml, :encoding => "UTF-8")
238
+ xml.sample("Iñtërnâtiônàl")
239
+ xml.target! =>
240
+ "<sample>Iñtërnâtiônàl</sample>"
241
+ ```
242
+
243
+ ## Links
244
+
245
+ | Description | Link |
246
+ | :----: | :----: |
247
+ | Documents | http://builder.rubyforge.org/ |
248
+ | Github Clone | git://github.com/jimweirich/builder.git |
249
+ | Issue / Bug Reports | https://github.com/jimweirich/builder/issues?state=open |
250
+
251
+ ## Contact
252
+
253
+ | Description | Value |
254
+ | :----: | :----: |
255
+ | Author | Jim Weirich |
256
+ | Email | jim.weirich@gmail.com |
257
+ | Home Page | http://onestepback.org |
258
+ | License | MIT Licence (http://www.opensource.org/licenses/mit-license.html) |
@@ -0,0 +1,195 @@
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
+ begin
13
+ require 'rubygems'
14
+ require 'rubygems/package_task'
15
+ # require 'rdoc/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
+ if defined?(RDoc)
53
+ rd = RDoc::Task.new("rdoc") { |rdoc|
54
+ rdoc.rdoc_dir = 'html'
55
+ rdoc.title = "Builder for Markup"
56
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
57
+ rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc').exclude("TAGS")
58
+ rdoc.template = 'doc/jamis.rb'
59
+ }
60
+ else
61
+ rd = Struct.new(:rdoc_files).new([])
62
+ end
63
+
64
+ # ====================================================================
65
+ # Create a task that will package the Rake software into distributable
66
+ # gem files.
67
+
68
+ PKG_FILES = FileList[
69
+ '[A-Z]*',
70
+ 'doc/**/*',
71
+ 'lib/**/*.rb',
72
+ 'test/**/*.rb',
73
+ 'rakelib/**/*'
74
+ ]
75
+ PKG_FILES.exclude('test/test_cssbuilder.rb')
76
+ PKG_FILES.exclude('lib/builder/css.rb')
77
+ PKG_FILES.exclude('TAGS')
78
+
79
+ BLANKSLATE_FILES = FileList[
80
+ 'lib/blankslate.rb',
81
+ 'test/test_blankslate.rb'
82
+ ]
83
+
84
+ if ! defined?(Gem)
85
+ puts "Package Target requires RubyGEMs"
86
+ else
87
+ spec = Gem::Specification.new do |s|
88
+
89
+ #### Basic information.
90
+
91
+ s.name = 'builder'
92
+ s.version = PKG_VERSION
93
+ s.summary = "Builders for MarkUp."
94
+ s.description = %{\
95
+ Builder provides a number of builder objects that make creating structured data
96
+ simple to do. Currently the following builder objects are supported:
97
+
98
+ * XML Markup
99
+ * XML Events
100
+ }
101
+
102
+ s.files = PKG_FILES.to_a
103
+ s.require_path = 'lib'
104
+
105
+ s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
106
+
107
+ s.has_rdoc = true
108
+ s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
109
+ s.rdoc_options <<
110
+ '--title' << 'Builder -- Easy XML Building' <<
111
+ '--main' << 'README.rdoc' <<
112
+ '--line-numbers'
113
+
114
+ s.author = "Jim Weirich"
115
+ s.email = "jim.weirich@gmail.com"
116
+ s.homepage = "http://onestepback.org"
117
+ s.license = 'MIT'
118
+ end
119
+
120
+ blankslate_spec = Gem::Specification.new do |s|
121
+
122
+ #### Basic information.
123
+
124
+ s.name = 'blankslate'
125
+ s.version = PKG_VERSION
126
+ s.summary = "Blank Slate base class."
127
+ s.description = %{\
128
+ BlankSlate provides a base class where almost all of the methods from Object and
129
+ Kernel have been removed. This is useful when providing proxy object and other
130
+ classes that make heavy use of method_missing.
131
+ }
132
+
133
+ s.files = BLANKSLATE_FILES.to_a
134
+ s.require_path = 'lib'
135
+
136
+ s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
137
+
138
+ s.has_rdoc = true
139
+ s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
140
+ s.rdoc_options <<
141
+ '--title' << 'BlankSlate -- Base Class for building proxies.' <<
142
+ '--main' << 'README.rdoc' <<
143
+ '--line-numbers'
144
+
145
+ s.author = "Jim Weirich"
146
+ s.email = "jim.weirich@gmail.com"
147
+ s.homepage = "http://onestepback.org"
148
+ s.license = 'MIT'
149
+ end
150
+
151
+ namespace 'builder' do
152
+ Gem::PackageTask.new(spec) do |t|
153
+ t.need_tar = false
154
+ end
155
+ end
156
+
157
+ namespace 'blankslate' do
158
+ Gem::PackageTask.new(blankslate_spec) do |t|
159
+ t.need_tar = false
160
+ end
161
+ end
162
+
163
+ task :package => [:remove_tags, 'builder:package', 'blankslate:package']
164
+ end
165
+
166
+ task :remove_tags do
167
+ rm "TAGS" rescue nil
168
+ end
169
+
170
+ # RCov ---------------------------------------------------------------
171
+ begin
172
+ require 'rcov/rcovtask'
173
+
174
+ Rcov::RcovTask.new do |t|
175
+ t.libs << "test"
176
+ t.rcov_opts = [
177
+ '-xRakefile', '--text-report'
178
+ ]
179
+ t.test_files = FileList[
180
+ 'test/test*.rb'
181
+ ]
182
+ t.output_dir = 'coverage'
183
+ t.verbose = true
184
+ end
185
+ rescue LoadError
186
+ # No rcov available
187
+ end
188
+
189
+ desc "Install the jamis RDoc template"
190
+ task :install_jamis_template do
191
+ require 'rbconfig'
192
+ dest_dir = File.join(Config::CONFIG['rubylibdir'], "rdoc/generators/template/html")
193
+ fail "Unabled to write to #{dest_dir}" unless File.writable?(dest_dir)
194
+ install "doc/jamis.rb", dest_dir, :verbose => true
195
+ end