builder 3.1.0 → 3.1.1

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.
@@ -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.
@@ -10,7 +10,7 @@ Provide a simple way to create XML markup and data structures.
10
10
  Builder::XmlMarkup:: Generate XML markup notiation
11
11
  Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
12
12
 
13
- <b>Notes</b>::
13
+ <b>Notes</b>::
14
14
 
15
15
  * An <tt>Builder::XmlTree</tt> class to generate XML tree
16
16
  (i.e. DOM-like) structures is also planned, but not yet implemented.
@@ -19,7 +19,7 @@ Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
19
19
 
20
20
  == Usage
21
21
 
22
- require 'rubygems'
22
+ require 'rubygems'
23
23
  require_gem 'builder', '~> 2.0'
24
24
 
25
25
  builder = Builder::XmlMarkup.new
@@ -28,7 +28,7 @@ Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
28
28
 
29
29
  or
30
30
 
31
- require 'rubygems'
31
+ require 'rubygems'
32
32
  require_gem 'builder'
33
33
 
34
34
  builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
@@ -119,11 +119,11 @@ incompatibility are:
119
119
 
120
120
  xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
121
121
  #=> <?xml version="1.0" encoding="UTF-8"?>
122
-
122
+
123
123
  If the processing instruction is omitted, it defaults to "xml".
124
124
  When the processing instruction is "xml", the defaults attributes
125
125
  are:
126
-
126
+
127
127
  <b>version</b>:: 1.0
128
128
  <b>encoding</b>:: "UTF-8"
129
129
 
@@ -200,13 +200,6 @@ incompatibility are:
200
200
  Builder correctly translates UTF-8 characters into valid XML. (New
201
201
  in version 2.0.0). Thanks to Sam Ruby for the translation code.
202
202
 
203
- Example:
204
-
205
- xml = Builder::Markup.new
206
- xml.sample("I$-1¶Æt(5k(Brn¶¨ti¶Én¶¦l")-A
207
- xml.target! =>
208
- "<sample>I&#241;t&#235;rn&#226;ti&#244;n&#224;l</sample>"
209
-
210
203
  You can get UTF-8 encoded output by making sure that the XML
211
204
  encoding is set to "UTF-8" and that the $KCODE variable is set to
212
205
  "UTF8".
@@ -220,10 +213,9 @@ incompatibility are:
220
213
 
221
214
  == Links
222
215
 
223
- Documents:: http://builder.rubyforge.org/
224
- Github Clone:: git://github.com/jimweirich/builder.git
225
- Issue Tracking:: http://www.pivotaltracker.com/projects/29210
226
- Bug Reports:: http://onestepback.org/cgi-bin/bugs.cgi?project=builder
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
227
219
 
228
220
  == Contact
229
221
 
data/Rakefile CHANGED
@@ -17,13 +17,14 @@ rescue Exception
17
17
  nil
18
18
  end
19
19
 
20
+ require './lib/builder/version'
21
+
20
22
  # Determine the current version of the software
21
23
 
22
24
  CLOBBER.include('pkg')
23
25
  CLEAN.include('pkg/builder-*').include('pkg/blankslate-*').exclude('pkg/*.gem')
24
26
 
25
- CURRENT_VERSION = '3.1.0'
26
- PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION
27
+ PKG_VERSION = Builder::VERSION
27
28
 
28
29
  SRC_RB = FileList['lib/**/*.rb']
29
30
 
@@ -52,7 +53,7 @@ rd = RDoc::Task.new("rdoc") { |rdoc|
52
53
  rdoc.rdoc_dir = 'html'
53
54
  rdoc.title = "Builder for Markup"
54
55
  rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
55
- rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc')
56
+ rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc').exclude("TAGS")
56
57
  rdoc.template = 'doc/jamis.rb'
57
58
  }
58
59
 
@@ -65,8 +66,9 @@ PKG_FILES = FileList[
65
66
  'test/**/*.rb',
66
67
  'scripts/**/*.rb'
67
68
  ]
68
- PKG_FILES.exclude('test/testcssbuilder.rb')
69
+ PKG_FILES.exclude('test/test_cssbuilder.rb')
69
70
  PKG_FILES.exclude('lib/builder/css.rb')
71
+ PKG_FILES.exclude('TAGS')
70
72
 
71
73
  BLANKSLATE_FILES = FileList[
72
74
  'lib/blankslate.rb',
@@ -104,8 +106,9 @@ simple to do. Currently the following builder objects are supported:
104
106
  '--line-numbers'
105
107
 
106
108
  s.author = "Jim Weirich"
107
- s.email = "jim@weirichhouse.org"
109
+ s.email = "jim.weirich@gmail.com"
108
110
  s.homepage = "http://onestepback.org"
111
+ s.license = 'MIT'
109
112
  end
110
113
 
111
114
  blankslate_spec = Gem::Specification.new do |s|
@@ -134,31 +137,30 @@ classes that make heavy use of method_missing.
134
137
  '--line-numbers'
135
138
 
136
139
  s.author = "Jim Weirich"
137
- s.email = "jim@weirichhouse.org"
140
+ s.email = "jim.weirich@gmail.com"
138
141
  s.homepage = "http://onestepback.org"
142
+ s.license = 'MIT'
139
143
  end
140
144
 
141
145
  namespace 'builder' do
142
146
  Gem::PackageTask.new(spec) do |t|
143
- t.need_tar = true
147
+ t.need_tar = false
144
148
  end
145
149
  end
146
150
 
147
151
  namespace 'blankslate' do
148
152
  Gem::PackageTask.new(blankslate_spec) do |t|
149
- t.need_tar = true
153
+ t.need_tar = false
150
154
  end
151
155
  end
152
156
 
153
- task :package => ['builder:package', 'blankslate:package']
157
+ task :package => [:remove_tags, 'builder:package', 'blankslate:package']
154
158
  end
155
159
 
156
- desc "Look for Debugging print lines"
157
- task :dbg do
158
- FileList['**/*.rb'].egrep /\bDBG|\bbreakpoint\b/
160
+ task :remove_tags do
161
+ rm "TAGS" rescue nil
159
162
  end
160
163
 
161
-
162
164
  # RCov ---------------------------------------------------------------
163
165
  begin
164
166
  require 'rcov/rcovtask'
@@ -178,114 +180,6 @@ rescue LoadError
178
180
  # No rcov available
179
181
  end
180
182
 
181
- # Tags file ----------------------------------------------------------
182
-
183
- namespace "tags" do
184
- desc "Create a TAGS file"
185
- task :emacs => "TAGS"
186
-
187
- TAGS = ENV['TAGS'] || 'ctags'
188
-
189
- file "TAGS" => SRC_RB do
190
- puts "Making TAGS"
191
- sh "#{TAGS} -e #{SRC_RB}", :verbose => false
192
- end
193
- end
194
-
195
- # --------------------------------------------------------------------
196
- # Creating a release
197
-
198
- def announce(msg='')
199
- STDERR.puts msg
200
- end
201
-
202
- desc "Make a new release"
203
- task :release => [
204
- :prerelease,
205
- :clobber,
206
- :test_all,
207
- :update_version,
208
- :package,
209
- :tag] do
210
-
211
- announce
212
- announce "**************************************************************"
213
- announce "* Release #{PKG_VERSION} Complete."
214
- announce "* Packages ready to upload."
215
- announce "**************************************************************"
216
- announce
217
- end
218
-
219
- # Validate that everything is ready to go for a release.
220
- task :prerelease do
221
- announce
222
- announce "**************************************************************"
223
- announce "* Making RubyGem Release #{PKG_VERSION}"
224
- announce "* (current version #{CURRENT_VERSION})"
225
- announce "**************************************************************"
226
- announce
227
-
228
- # Is a release number supplied?
229
- unless ENV['REL']
230
- fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
231
- end
232
-
233
- # Is the release different than the current release.
234
- # (or is REUSE set?)
235
- if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
236
- fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
237
- end
238
-
239
- # Are all source files checked in?
240
- if ENV['RELTEST']
241
- announce "Release Task Testing, skipping checked-in file test"
242
- else
243
- announce "Checking for unchecked-in files..."
244
- data = `cvs -q update`
245
- unless data =~ /^$/
246
- fail "CVS update is not clean ... do you have unchecked-in files?"
247
- end
248
- announce "No outstanding checkins found ... OK"
249
- end
250
- end
251
-
252
- task :update_version => [:prerelease] do
253
- if PKG_VERSION == CURRENT_VERSION
254
- announce "No version change ... skipping version update"
255
- else
256
- announce "Updating Builder version to #{PKG_VERSION}"
257
- open("Rakefile") do |rakein|
258
- open("Rakefile.new", "w") do |rakeout|
259
- rakein.each do |line|
260
- if line =~ /^CURRENT_VERSION\s*=\s*/
261
- rakeout.puts "CURRENT_VERSION = '#{PKG_VERSION}'"
262
- else
263
- rakeout.puts line
264
- end
265
- end
266
- end
267
- end
268
- mv "Rakefile.new", "Rakefile"
269
- if ENV['RELTEST']
270
- announce "Release Task Testing, skipping commiting of new version"
271
- else
272
- sh "cvs commit -m \"Updated to version #{PKG_VERSION}\" Rakefile"
273
- end
274
- end
275
- end
276
-
277
- desc "Tag all the CVS files with the latest release number (REL=x.y.z)"
278
- task :tag => [:prerelease] do
279
- reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
280
- reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE']
281
- announce "Tagging CVS with [#{reltag}]"
282
- if ENV['RELTEST']
283
- announce "Release Task Testing, skipping CVS tagging"
284
- else
285
- sh %{cvs tag #{reltag}}
286
- end
287
- end
288
-
289
183
  desc "Install the jamis RDoc template"
290
184
  task :install_jamis_template do
291
185
  require 'rbconfig'
@@ -8,6 +8,30 @@
8
8
  # above copyright notice is included.
9
9
  #++
10
10
 
11
+ class String
12
+ if instance_methods.first.is_a?(Symbol)
13
+ def _blankslate_as_name
14
+ to_sym
15
+ end
16
+ else
17
+ def _blankslate_as_name
18
+ self
19
+ end
20
+ end
21
+ end
22
+
23
+ class Symbol
24
+ if instance_methods.first.is_a?(Symbol)
25
+ def _blankslate_as_name
26
+ self
27
+ end
28
+ else
29
+ def _blankslate_as_name
30
+ to_s
31
+ end
32
+ end
33
+ end
34
+
11
35
  ######################################################################
12
36
  # BlankSlate provides an abstract base class with no predefined
13
37
  # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
@@ -16,12 +40,12 @@
16
40
  #
17
41
  class BlankSlate
18
42
  class << self
19
-
43
+
20
44
  # Hide the method named +name+ in the BlankSlate class. Don't
21
45
  # hide +instance_eval+ or any method beginning with "__".
22
46
  def hide(name)
23
- if instance_methods.include?(name.to_s) and
24
- name !~ /^(__|instance_eval)/
47
+ if instance_methods.include?(name._blankslate_as_name) and
48
+ name !~ /^(__|instance_eval$)/
25
49
  @hidden_methods ||= {}
26
50
  @hidden_methods[name.to_sym] = instance_method(name)
27
51
  undef_method name
@@ -41,7 +65,7 @@ class BlankSlate
41
65
  define_method(name, hidden_method)
42
66
  end
43
67
  end
44
-
68
+
45
69
  instance_methods.each { |m| hide(m) }
46
70
  end
47
71
 
@@ -106,4 +130,4 @@ class Module
106
130
  end
107
131
  result
108
132
  end
109
- end
133
+ end
@@ -0,0 +1,8 @@
1
+ module Builder
2
+ VERSION_NUMBERS = [
3
+ VERSION_MAJOR = 3,
4
+ VERSION_MINOR = 1,
5
+ VERSION_BUILD = 1,
6
+ ]
7
+ VERSION = VERSION_NUMBERS.join(".")
8
+ end
@@ -64,7 +64,7 @@ module Builder
64
64
  _end_tag(sym)
65
65
  _newline
66
66
  end
67
- elsif text.nil?
67
+ elsif text.nil? || text.empty?
68
68
  _indent
69
69
  _start_tag(sym, attrs, true)
70
70
  _newline
@@ -128,7 +128,9 @@ module Builder
128
128
  def _escape(text)
129
129
  result = XChar.encode(text)
130
130
  begin
131
- result.encode(@encoding)
131
+ encoding = ::Encoding::find(@encoding)
132
+ raise Exception if encoding.dummy?
133
+ result.encode(encoding)
132
134
  rescue
133
135
  # if the encoding can't be supported, use numeric character references
134
136
  result.
@@ -263,7 +263,7 @@ module Builder
263
263
  #
264
264
  def cdata!(text)
265
265
  _ensure_no_block ::Kernel::block_given?
266
- _special("<![CDATA[", "]]>", text, nil)
266
+ _special("<![CDATA[", "]]>", text.gsub(']]>', ']]]]><![CDATA[>'), nil)
267
267
  end
268
268
 
269
269
  private
@@ -12,7 +12,7 @@
12
12
 
13
13
  require 'test/unit'
14
14
  require 'test/preload'
15
- require 'builder/blankslate'
15
+ require 'blankslate'
16
16
  require 'stringio'
17
17
 
18
18
  # Methods to be introduced into the Object class late.
@@ -81,24 +81,11 @@ end
81
81
  # Test case for blank slate.
82
82
  #
83
83
  class TestBlankSlate < Test::Unit::TestCase
84
- if Object::const_defined?(:BasicObject)
85
- def skipping?
86
- true
87
- end
88
- else
89
- def skipping?
90
- false
91
- end
92
- end
93
-
94
84
  def setup
95
- return if skipping?
96
- @skip = Object::const_defined?(:BasicObject)
97
85
  @bs = BlankSlate.new
98
86
  end
99
87
 
100
88
  def test_undefined_methods_remain_undefined
101
- return if skipping?
102
89
  assert_raise(NoMethodError) { @bs.no_such_method }
103
90
  assert_raise(NoMethodError) { @bs.nil? }
104
91
  end
@@ -107,7 +94,6 @@ class TestBlankSlate < Test::Unit::TestCase
107
94
  # NOTE: NameError is acceptable because the lack of a '.' means that
108
95
  # Ruby can't tell if it is a method or a local variable.
109
96
  def test_undefined_methods_remain_undefined_during_instance_eval
110
- return if skipping?
111
97
  assert_raise(NoMethodError, NameError) do
112
98
  @bs.instance_eval do nil? end
113
99
  end
@@ -117,14 +103,12 @@ class TestBlankSlate < Test::Unit::TestCase
117
103
  end
118
104
 
119
105
  def test_private_methods_are_undefined
120
- return if skipping?
121
106
  assert_raise(NoMethodError) do
122
107
  @bs.puts "HI"
123
108
  end
124
109
  end
125
110
 
126
111
  def test_targetted_private_methods_are_undefined_during_instance_eval
127
- return if skipping?
128
112
  assert_raise(NoMethodError, NameError) do
129
113
  @bs.instance_eval do self.puts "HI" end
130
114
  end
@@ -132,7 +116,6 @@ class TestBlankSlate < Test::Unit::TestCase
132
116
 
133
117
  def test_untargetted_private_methods_are_defined_during_instance_eval
134
118
  oldstdout = $stdout
135
- return if skipping?
136
119
  $stdout = StringIO.new
137
120
  @bs.instance_eval do
138
121
  puts "HI"
@@ -142,56 +125,47 @@ class TestBlankSlate < Test::Unit::TestCase
142
125
  end
143
126
 
144
127
  def test_methods_added_late_to_kernel_remain_undefined
145
- return if skipping?
146
128
  assert_equal 1234, nil.late_addition
147
129
  assert_raise(NoMethodError) { @bs.late_addition }
148
130
  end
149
131
 
150
132
  def test_methods_added_late_to_object_remain_undefined
151
- return if skipping?
152
133
  assert_equal 4321, nil.another_late_addition
153
134
  assert_raise(NoMethodError) { @bs.another_late_addition }
154
135
  end
155
136
 
156
137
  def test_methods_added_late_to_global_remain_undefined
157
- return if skipping?
158
138
  assert_equal 42, global_inclusion
159
139
  assert_raise(NoMethodError) { @bs.global_inclusion }
160
140
  end
161
141
 
162
142
  def test_preload_method_added
163
- return if skipping?
164
143
  assert Kernel.k_added_names.include?(:late_addition)
165
144
  assert Object.o_added_names.include?(:another_late_addition)
166
145
  end
167
146
 
168
147
  def test_method_defined_late_multiple_times_remain_undefined
169
- return if skipping?
170
148
  assert_equal 22, nil.double_late_addition
171
149
  assert_raise(NoMethodError) { @bs.double_late_addition }
172
150
  end
173
151
 
174
152
  def test_late_included_module_in_object_is_ok
175
- return if skipping?
176
153
  assert_equal 33, 1.late_object
177
154
  assert_raise(NoMethodError) { @bs.late_object }
178
155
  end
179
156
 
180
157
  def test_late_included_module_in_kernel_is_ok
181
- return if skipping?
182
158
  assert_raise(NoMethodError) { @bs.late_kernel }
183
159
  end
184
160
 
185
161
  def test_revealing_previously_hidden_methods_are_callable
186
- return if skipping?
187
162
  with_to_s = Class.new(BlankSlate) do
188
163
  reveal :to_s
189
164
  end
190
- assert_match /^#<.*>$/, with_to_s.new.to_s
165
+ assert_match(/^#<.*>$/, with_to_s.new.to_s)
191
166
  end
192
167
 
193
168
  def test_revealing_previously_hidden_methods_are_callable_with_block
194
- return if skipping?
195
169
  Object.class_eval <<-EOS
196
170
  def given_block(&block)
197
171
  block
@@ -205,16 +179,14 @@ class TestBlankSlate < Test::Unit::TestCase
205
179
  end
206
180
 
207
181
  def test_revealing_a_hidden_method_twice_is_ok
208
- return if skipping?
209
182
  with_to_s = Class.new(BlankSlate) do
210
183
  reveal :to_s
211
184
  reveal :to_s
212
185
  end
213
- assert_match /^#<.*>$/, with_to_s.new.to_s
186
+ assert_match(/^#<.*>$/, with_to_s.new.to_s)
214
187
  end
215
188
 
216
189
  def test_revealing_unknown_hidden_method_is_an_error
217
- return if skipping?
218
190
  assert_raises(RuntimeError) do
219
191
  Class.new(BlankSlate) do
220
192
  reveal :xyz
@@ -223,7 +195,6 @@ class TestBlankSlate < Test::Unit::TestCase
223
195
  end
224
196
 
225
197
  def test_global_includes_still_work
226
- return if skipping?
227
198
  assert_nothing_raised do
228
199
  assert_equal 42, global_inclusion
229
200
  assert_equal 42, Object.new.global_inclusion
@@ -233,7 +204,6 @@ class TestBlankSlate < Test::Unit::TestCase
233
204
  end
234
205
 
235
206
  def test_reveal_should_not_bind_to_an_instance
236
- return if skipping?
237
207
  with_object_id = Class.new(BlankSlate) do
238
208
  reveal(:object_id)
239
209
  end
@@ -245,4 +215,3 @@ class TestBlankSlate < Test::Unit::TestCase
245
215
  "Revealed methods should not be bound to a particular instance"
246
216
  end
247
217
  end
248
-
@@ -34,6 +34,16 @@ class TestMarkup < Test::Unit::TestCase
34
34
  assert_equal "<value>hi</value>", @xml.target!
35
35
  end
36
36
 
37
+ def test_empty_value
38
+ @xml.value("")
39
+ assert_equal "<value/>", @xml.target!
40
+ end
41
+
42
+ def test_nil_value
43
+ @xml.value(nil)
44
+ assert_equal "<value/>", @xml.target!
45
+ end
46
+
37
47
  def test_nested
38
48
  @xml.outer { |x| x.inner("x") }
39
49
  assert_equal "<outer><inner>x</inner></outer>", @xml.target!
@@ -127,8 +137,8 @@ class TestMarkup < Test::Unit::TestCase
127
137
  ex = assert_raise(ArgumentError) {
128
138
  @xml.h1("data1") { b }
129
139
  }
130
- assert_match /\btext\b/, ex.message
131
- assert_match /\bblock\b/, ex.message
140
+ assert_match(/\btext\b/, ex.message)
141
+ assert_match(/\bblock\b/, ex.message)
132
142
  end
133
143
 
134
144
  def test_capitalized_method
@@ -228,10 +238,10 @@ class TestNameSpaces < Test::Unit::TestCase
228
238
  end
229
239
  end
230
240
  end
231
- assert_match /^<\?xml/, xml.target!
232
- assert_match /\n<rdf:RDF/m, xml.target!
233
- assert_match /xmlns:rdf="&rdf;"/m, xml.target!
234
- assert_match /<owl:Restriction>/m, xml.target!
241
+ assert_match(/^<\?xml/, xml.target!)
242
+ assert_match(/\n<rdf:RDF/m, xml.target!)
243
+ assert_match(/xmlns:rdf="&rdf;"/m, xml.target!)
244
+ assert_match(/<owl:Restriction>/m, xml.target!)
235
245
  end
236
246
 
237
247
  def test_ensure
@@ -342,17 +352,17 @@ class TestSpecialMarkup < Test::Unit::TestCase
342
352
 
343
353
  def test_xml_instruct
344
354
  @xml.instruct!
345
- assert_match /^<\?xml version="1.0" encoding="UTF-8"\?>$/, @xml.target!
355
+ assert_match(/^<\?xml version="1.0" encoding="UTF-8"\?>$/, @xml.target!)
346
356
  end
347
357
 
348
358
  def test_xml_instruct_with_overrides
349
359
  @xml.instruct! :xml, :encoding=>"UCS-2"
350
- assert_match /^<\?xml version="1.0" encoding="UCS-2"\?>$/, @xml.target!
360
+ assert_match(/^<\?xml version="1.0" encoding="UCS-2"\?>$/, @xml.target!)
351
361
  end
352
362
 
353
363
  def test_xml_instruct_with_standalong
354
364
  @xml.instruct! :xml, :encoding=>"UCS-2", :standalone=>"yes"
355
- assert_match /^<\?xml version="1.0" encoding="UCS-2" standalone="yes"\?>$/, @xml.target!
365
+ assert_match(/^<\?xml version="1.0" encoding="UCS-2" standalone="yes"\?>$/, @xml.target!)
356
366
  end
357
367
 
358
368
  def test_no_blocks
@@ -373,6 +383,11 @@ class TestSpecialMarkup < Test::Unit::TestCase
373
383
  @xml.cdata!("TEST&CHECK")
374
384
  assert_equal "<![CDATA[TEST&CHECK]]>\n", @xml.target!
375
385
  end
386
+
387
+ def test_cdata_with_included_close
388
+ @xml.cdata!("TEST]]>CHECK")
389
+ assert_equal "<![CDATA[TEST]]]]><![CDATA[>CHECK]]>\n", @xml.target!
390
+ end
376
391
  end
377
392
 
378
393
  class TestIndentedXmlMarkup < Test::Unit::TestCase
@@ -452,14 +467,20 @@ class TestIndentedXmlMarkup < Test::Unit::TestCase
452
467
  end
453
468
  end
454
469
 
455
- # PENDING: Until we figure out how to gsub on non-UTF-8 text.
456
- def xtest_use_entities_if_kcode_is_utf_but_encoding_is_something_else
470
+ def test_use_entities_if_kcode_is_utf_but_encoding_is_dummy_encoding
457
471
  xml = Builder::XmlMarkup.new
458
472
  xml.instruct!(:xml, :encoding => 'UTF-16')
459
473
  xml.p(encode("\xE2\x80\x99", 'UTF8'))
460
474
  assert_match(%r(<p>&#8217;</p>), xml.target!) #
461
475
  end
462
476
 
477
+ def test_use_entities_if_kcode_is_utf_but_encoding_is_unsupported_encoding
478
+ xml = Builder::XmlMarkup.new
479
+ xml.instruct!(:xml, :encoding => 'UCS-2')
480
+ xml.p(encode("\xE2\x80\x99", 'UTF8'))
481
+ assert_match(%r(<p>&#8217;</p>), xml.target!) #
482
+ end
483
+
463
484
  def test_use_utf8_if_encoding_defaults_and_kcode_is_utf8
464
485
  xml = Builder::XmlMarkup.new
465
486
  xml.p(encode("\xE2\x80\x99",'UTF8'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -22,21 +22,21 @@ description: ! 'Builder provides a number of builder objects that make creating
22
22
  * XML Events
23
23
 
24
24
  '
25
- email: jim@weirichhouse.org
25
+ email: jim.weirich@gmail.com
26
26
  executables: []
27
27
  extensions: []
28
28
  extra_rdoc_files:
29
29
  - CHANGES
30
+ - MIT-LICENSE
30
31
  - Rakefile
31
- - README
32
32
  - README.rdoc
33
- - TAGS
34
33
  - doc/releases/builder-1.2.4.rdoc
35
34
  - doc/releases/builder-2.0.0.rdoc
36
35
  - doc/releases/builder-2.1.1.rdoc
37
36
  files:
38
37
  - lib/blankslate.rb
39
38
  - lib/builder/blankslate.rb
39
+ - lib/builder/version.rb
40
40
  - lib/builder/xchar.rb
41
41
  - lib/builder/xmlbase.rb
42
42
  - lib/builder/xmlevents.rb
@@ -45,22 +45,21 @@ files:
45
45
  - test/performance.rb
46
46
  - test/preload.rb
47
47
  - test/test_blankslate.rb
48
- - test/test_cssbuilder.rb
49
48
  - test/test_eventbuilder.rb
50
49
  - test/test_markupbuilder.rb
51
50
  - test/test_method_caching.rb
52
51
  - test/test_namecollision.rb
53
52
  - test/test_xchar.rb
54
53
  - CHANGES
54
+ - MIT-LICENSE
55
55
  - Rakefile
56
- - README
57
56
  - README.rdoc
58
- - TAGS
59
57
  - doc/releases/builder-1.2.4.rdoc
60
58
  - doc/releases/builder-2.0.0.rdoc
61
59
  - doc/releases/builder-2.1.1.rdoc
62
60
  homepage: http://onestepback.org
63
- licenses: []
61
+ licenses:
62
+ - MIT
64
63
  post_install_message:
65
64
  rdoc_options:
66
65
  - --title
@@ -90,7 +89,6 @@ specification_version: 3
90
89
  summary: Builders for MarkUp.
91
90
  test_files:
92
91
  - test/test_blankslate.rb
93
- - test/test_cssbuilder.rb
94
92
  - test/test_eventbuilder.rb
95
93
  - test/test_markupbuilder.rb
96
94
  - test/test_method_caching.rb
data/README DELETED
@@ -1,230 +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', '~> 3.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 3.0.0
46
-
47
- Version 3 adds Ruby 1.9.2 compatibility.
48
-
49
- === Version 2.0.0 Compatibility Changes
50
-
51
- Version 2.0.0 introduces automatically escaped attribute values for
52
- the first time. Versions prior to 2.0.0 did not insert escape
53
- characters into attribute values in the XML markup. This allowed
54
- attribute values to explicitly reference entities, which was
55
- occasionally used by a small number of developers. Since strings
56
- could always be explicitly escaped by hand, this was not a major
57
- restriction in functionality.
58
-
59
- However, it did suprise most users of builder. Since the body text is
60
- normally escaped, everybody expected the attribute values to be
61
- escaped as well. Escaped attribute values were the number one support
62
- request on the 1.x Builder series.
63
-
64
- Starting with Builder version 2.0.0, all attribute values expressed as
65
- strings will be processed and the appropriate characters will be
66
- escaped (e.g. "&" will be tranlated to "&amp;"). Attribute values
67
- that are expressed as Symbol values will not be processed for escaped
68
- characters and will be unchanged in output. (Yes, this probably counts
69
- as Symbol abuse, but the convention is convenient and flexible).
70
-
71
- Example:
72
-
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
- === Version 1.0.0 Compatibility Changes
79
-
80
- Version 1.0.0 introduces some changes that are not backwards
81
- compatible with earlier releases of builder. The main areas of
82
- incompatibility are:
83
-
84
- * Keyword based arguments to +new+ (rather than positional based). It
85
- was found that a developer would often like to specify indentation
86
- without providing an explicit target, or specify a target without
87
- indentation. Keyword based arguments handle this situation nicely.
88
-
89
- * Builder must now be an explicit target for markup tags. Instead of
90
- writing
91
-
92
- xml_markup = Builder::XmlMarkup.new
93
- xml_markup.div { strong("text") }
94
-
95
- you need to write
96
-
97
- xml_markup = Builder::XmlMarkup.new
98
- xml_markup.div { xml_markup.strong("text") }
99
-
100
- * The builder object is passed as a parameter to all nested markup
101
- blocks. This allows you to create a short alias for the builder
102
- object that can be used within the block. For example, the previous
103
- example can be written as:
104
-
105
- xml_markup = Builder::XmlMarkup.new
106
- xml_markup.div { |xml| xml.strong("text") }
107
-
108
- * If you have both a pre-1.0 and a post-1.0 gem of builder installed,
109
- you can choose which version to use through the RubyGems
110
- +require_gem+ facility.
111
-
112
- require_gem 'builder', "~> 0.0" # Gets the old version
113
- require_gem 'builder', "~> 1.0" # Gets the new version
114
-
115
- == Features
116
-
117
- * XML Comments are supported ...
118
-
119
- xml_markup.comment! "This is a comment"
120
- #=> <!-- This is a comment -->
121
-
122
- * XML processing instructions are supported ...
123
-
124
- xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
125
- #=> <?xml version="1.0" encoding="UTF-8"?>
126
-
127
- If the processing instruction is omitted, it defaults to "xml".
128
- When the processing instruction is "xml", the defaults attributes
129
- are:
130
-
131
- <b>version</b>:: 1.0
132
- <b>encoding</b>:: "UTF-8"
133
-
134
- (NOTE: if the encoding is set to "UTF-8" and $KCODE is set to
135
- "UTF8", then Builder will emit UTF-8 encoded strings rather than
136
- encoding non-ASCII characters as entities.)
137
-
138
- * XML entity declarations are now supported to a small degree.
139
-
140
- xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
141
- #=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
142
-
143
- The parameters to a declare! method must be either symbols or
144
- strings. Symbols are inserted without quotes, and strings are
145
- inserted with double quotes. Attribute-like arguments in hashes are
146
- not allowed.
147
-
148
- If you need to have an argument to declare! be inserted without
149
- quotes, but the arguement does not conform to the typical Ruby
150
- syntax for symbols, then use the :"string" form to specify a symbol.
151
-
152
- For example:
153
-
154
- xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
155
- #=> <!ELEMENT chapter (title,para+)>
156
-
157
- Nested entity declarations are allowed. For example:
158
-
159
- @xml_markup.declare! :DOCTYPE, :chapter do |x|
160
- x.declare! :ELEMENT, :chapter, :"(title,para+)"
161
- x.declare! :ELEMENT, :title, :"(#PCDATA)"
162
- x.declare! :ELEMENT, :para, :"(#PCDATA)"
163
- end
164
-
165
- #=>
166
-
167
- <!DOCTYPE chapter [
168
- <!ELEMENT chapter (title,para+)>
169
- <!ELEMENT title (#PCDATA)>
170
- <!ELEMENT para (#PCDATA)>
171
- ]>
172
-
173
- * Some support for XML namespaces is now available. If the first
174
- argument to a tag call is a symbol, it will be joined to the tag to
175
- produce a namespace:tag combination. It is easier to show this than
176
- describe it.
177
-
178
- xml.SOAP :Envelope do ... end
179
-
180
- Just put a space before the colon in a namespace to produce the
181
- right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
182
- "<tt>xml.SOAP :Envelope</tt>")
183
-
184
- * String attribute values are <em>now</em> escaped by default by
185
- Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
186
-
187
- However, occasionally you need to use entities in attribute values.
188
- Using a symbols (rather than a string) for an attribute value will
189
- cause Builder to not run its quoting/escaping algorithm on that
190
- particular value.
191
-
192
- (<b>Note:</b> The +escape_attrs+ option for builder is now
193
- obsolete).
194
-
195
- Example:
196
-
197
- xml = Builder::XmlMarkup.new
198
- xml.sample(:escaped=>"This&That", :unescaped=>:"Here&amp;There")
199
- xml.target! =>
200
- <sample escaped="This&amp;That" unescaped="Here&amp;There"/>
201
-
202
- * UTF-8 Support
203
-
204
- Builder correctly translates UTF-8 characters into valid XML. (New
205
- in version 2.0.0). Thanks to Sam Ruby for the translation code.
206
-
207
- Example:
208
-
209
- xml = Builder::Markup.new
210
- xml.sample("Iñtërnâtiônàl")
211
- xml.target! =>
212
- "<sample>I&#241;t&#235;rn&#226;ti&#244;n&#224;l</sample>"
213
-
214
- You can get UTF-8 encoded output by making sure that the XML
215
- encoding is set to "UTF-8" and that the $KCODE variable is set to
216
- "UTF8".
217
-
218
- $KCODE = 'UTF8'
219
- xml = Builder::Markup.new
220
- xml.instruct!(:xml, :encoding => "UTF-8")
221
- xml.sample("Iñtërnâtiônàl")
222
- xml.target! =>
223
- "<sample>Iñtërnâtiônàl</sample>"
224
-
225
- == Contact
226
-
227
- Author:: Jim Weirich
228
- Email:: jim@weirichhouse.org
229
- Home Page:: http://onestepback.org
230
- License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
data/TAGS DELETED
@@ -1,102 +0,0 @@
1
-
2
- (null),455
3
- class BlankSlateBlankSlate17,621
4
- def hide(name)hide22,788
5
- def find_hidden_method(name)find_hidden_method31,1032
6
- def reveal(name)reveal38,1268
7
- module KernelKernel55,1902
8
- def method_added(name)method_added61,2078
9
- class ObjectObject73,2357
10
- def method_added(name)method_added79,2532
11
- def find_hidden_method(name)find_hidden_method86,2693
12
- class ModuleModule99,3124
13
- def append_features(mod)append_features101,3197
14
-
15
- lib/builder/blankslate.rb,30
16
- module BuilderBuilder16,533
17
-
18
- lib/builder/css.rb,1102
19
- module BuilderBuilder23,757
20
- class CSS < BlankSlateCSS92,2139
21
- def initialize(indent=2)initialize101,2424
22
- def +(part)+108,2562
23
- def >>(part)>>113,2623
24
- def >(part)>118,2684
25
- def |(part)|123,2745
26
- def target!target!129,2845
27
- def comment!(comment_text)comment!134,2934
28
- def id!(arg, &block)id!138,3017
29
- def class!(arg, &block)class!145,3179
30
- def store!(sym, &block)store!152,3344
31
- def group!(*args, &block)group!156,3417
32
- def method_missing(sym, *args, &block)method_missing171,3730
33
- def nil?nil?190,4236
34
- def _unify_block_unify_block195,4282
35
- def _join_with_op!(op)_join_with_op!200,4363
36
- def _text(text)_text205,4484
37
- def _css_block(block)_css_block209,4534
38
- def _end_block_end_block216,4654
39
- def _newline_newline221,4716
40
- def _indent_indent225,4763
41
- def _nested_structures(block)_nested_structures229,4814
42
- def _start_container(sym, atts = {}, with_bracket = true)_start_container235,4937
43
- def _end_container_end_container242,5212
44
- def _css_line(sym, *args)_css_line246,5264
45
-
46
- lib/builder/xchar.rb,523
47
- module BuilderBuilder11,321
48
- def self.check_for_name_collision(klass, method_name, defined_constant=nil)check_for_name_collision12,336
49
- module BuilderBuilder26,826
50
- module XChar # :nodoc:XChar32,1025
51
- module BuilderBuilder97,3103
52
- module XChar # :nodoc:XChar98,3120
53
- def XChar.unicode(string)unicode125,4081
54
- def XChar.encode(string)encode151,4755
55
- class FixnumFixnum165,5150
56
- def xchr(escape=true)xchr171,5393
57
- class StringString187,5824
58
- def to_xs(escape=true)to_xs191,6017
59
-
60
- lib/builder/xmlbase.rb,748
61
- module BuilderBuilder5,51
62
- class IllegalBlockError < RuntimeError; endIllegalBlockError8,97
63
- class XmlBase < BlankSlateXmlBase12,264
64
- def initialize(indent=0, initial=0, encoding='utf-8')initialize28,844
65
- def tag!(sym, *args, &block)tag!37,1172
66
- def method_missing(sym, *args, &block)method_missing84,2344
67
- def text!(text)text!93,2680
68
- def <<(text)<<110,3336
69
- def nil?nil?120,3763
70
- def _escape(text)_escape128,3879
71
- def _escape(text)_escape140,4227
72
- def _escape_attribute(text)_escape_attribute149,4425
73
- def _newline_newline154,4566
74
- def _indent_indent159,4638
75
- def _nested_structures(block)_nested_structures164,4745
76
- def cache_method_call(sym)cache_method_call177,5233
77
-
78
- lib/builder/xmlevents.rb,216
79
- module BuilderBuilder14,315
80
- class XmlEvents < XmlMarkupXmlEvents48,1598
81
- def text!(text)text!49,1628
82
- def _start_tag(sym, attrs, end_too=false)_start_tag53,1682
83
- def _end_tag(sym)_end_tag58,1804
84
-
85
- lib/builder/xmlmarkup.rb,776
86
- module BuilderBuilder16,425
87
- class XmlMarkup < XmlBaseXmlMarkup160,5942
88
- def initialize(options={})initialize186,7059
89
- def target!target!194,7284
90
- def comment!(comment_text)comment!198,7323
91
- def declare!(inst, *args, &block)declare!209,7629
92
- def instruct!(directive_tag=:xml, attrs={})instruct!242,8521
93
- def cdata!(text)cdata!264,9115
94
- def _text(text)_text275,9449
95
- def _special(open, close, data=nil, attrs=nil, order=[])_special280,9539
96
- def _start_tag(sym, attrs, end_too=false)_start_tag291,9873
97
- def _end_tag(sym)_end_tag299,10072
98
- def _insert_attributes(attrs, order=[])_insert_attributes304,10181
99
- def _attr_value(value)_attr_value315,10496
100
- def _ensure_no_block(got_block)_ensure_no_block324,10647
101
-
102
- pjw_94jc0000gn/T//tags.pR7PYt,0
@@ -1,125 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #--
4
- # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
5
- # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
6
- # All rights reserved.
7
-
8
- # Permission is granted for use, copying, modification, distribution,
9
- # and distribution of modified versions of this work as long as the
10
- # above copyright notice is included.
11
- #++
12
-
13
- require 'test/unit'
14
- require 'test/preload'
15
- require 'builder'
16
- require 'builder/css'
17
-
18
- class TestCSS < Test::Unit::TestCase
19
- def setup
20
- @css = Builder::CSS.new
21
- end
22
-
23
- def test_create
24
- assert_not_nil @css
25
- end
26
-
27
- def test_no_block
28
- @css.body
29
- assert_equal 'body', @css.target!
30
- end
31
-
32
- def test_block
33
- @css.body {
34
- color 'green'
35
- }
36
- assert_equal "body {\n color: green;\n}\n\n", @css.target!
37
- end
38
-
39
- def test_id
40
- @css.id!('nav') { color 'green' }
41
- assert_equal "#nav {\n color: green;\n}\n\n", @css.target!
42
- end
43
-
44
- def test_class
45
- @css.class!('nav') { color 'green' }
46
- assert_equal ".nav {\n color: green;\n}\n\n", @css.target!
47
- end
48
-
49
- def test_elem_with_id
50
- @css.div(:id => 'nav') { color 'green' }
51
- assert_equal "div#nav {\n color: green;\n}\n\n", @css.target!
52
- end
53
-
54
- def test_elem_with_class
55
- @css.div(:class => 'nav') { color 'green' }
56
- assert_equal "div.nav {\n color: green;\n}\n\n", @css.target!
57
- end
58
-
59
- def test_comment
60
- @css.comment!('foo')
61
- assert_equal "/* foo */\n", @css.target!
62
- end
63
-
64
- def test_selector
65
- @css.a(:hover) { color 'green' }
66
- assert_equal "a:hover {\n color: green;\n}\n\n", @css.target!
67
- end
68
-
69
- def test_plus
70
- @css.h1 + @css.span
71
- assert_equal "h1 + span", @css.target!
72
- end
73
-
74
- def test_plus_with_block
75
- @css.h1 + @css.span { color 'green' }
76
- assert_equal "h1 + span {\n color: green;\n}\n\n", @css.target!
77
- end
78
-
79
- def test_contextual
80
- @css.h1 >> @css.span
81
- assert_equal "h1 span", @css.target!
82
- end
83
-
84
- def test_contextual_with_block
85
- @css.h1 >> @css.span { color 'green' }
86
- assert_equal "h1 span {\n color: green;\n}\n\n", @css.target!
87
- end
88
-
89
- def test_child
90
- @css.h1 > @css.span
91
- assert_equal "h1 > span", @css.target!
92
- end
93
-
94
- def test_child_with_block
95
- @css.h1 > @css.span { color 'green' }
96
- assert_equal "h1 > span {\n color: green;\n}\n\n", @css.target!
97
- end
98
-
99
- def test_multiple_op
100
- @css.h1 + @css.span + @css.span
101
- assert_equal "h1 + span + span", @css.target!
102
- end
103
-
104
- def test_all
105
- @css.h1 | @css.h2 { color 'green' }
106
- assert_equal "h1 , h2 {\n color: green;\n}\n\n", @css.target!
107
- end
108
-
109
- def test_all_with_atts
110
- @css.h1(:class => 'foo') | @css.h2(:class => 'bar') { color 'green' }
111
- assert_equal "h1.foo , h2.bar {\n color: green;\n}\n\n", @css.target!
112
- end
113
-
114
- def test_multiple_basic
115
- @css.body { color 'green' }
116
- @css.h1 { color 'green' }
117
- assert_equal "body {\n color: green;\n}\n\nh1 {\n color: green;\n}\n\n", @css.target!
118
- end
119
-
120
- def test_multiple_ops
121
- @css.body { color 'green' }
122
- @css.body > @css.h1 { color 'green' }
123
- assert_equal "body {\n color: green;\n}\n\nbody > h1 {\n color: green;\n}\n\n", @css.target!
124
- end
125
- end