builder 3.1.4 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #--
3
4
  # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
4
5
  # All rights reserved.
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  #--
4
5
  # Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #--
3
4
  # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
4
5
  # All rights reserved.
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  module Builder
2
3
  VERSION_NUMBERS = [
3
4
  VERSION_MAJOR = 3,
4
- VERSION_MINOR = 1,
5
+ VERSION_MINOR = 2,
5
6
  VERSION_BUILD = 4,
6
7
  ]
7
8
  VERSION = VERSION_NUMBERS.join(".")
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # The XChar library is provided courtesy of Sam Ruby (See
4
5
  # http://intertwingly.net/stories/2005/09/28/xchar.rb)
@@ -19,7 +20,7 @@ end
19
20
 
20
21
  if ! defined?(Builder::XChar) and ! String.method_defined?(:encode)
21
22
  Builder.check_for_name_collision(String, "to_xs")
22
- Builder.check_for_name_collision(Fixnum, "xchr")
23
+ Builder.check_for_name_collision(Integer, "xchr")
23
24
  end
24
25
 
25
26
  ######################################################################
@@ -108,7 +109,7 @@ if String.method_defined?(:encode)
108
109
  INVALID_XML_CHAR = Regexp.new('[^'+
109
110
  Builder::XChar::VALID.map { |item|
110
111
  case item
111
- when Fixnum
112
+ when Integer
112
113
  [item].pack('U').force_encoding('utf-8')
113
114
  when Range
114
115
  [item.first, '-'.ord, item.last].pack('UUU').force_encoding('utf-8')
@@ -160,9 +161,9 @@ if String.method_defined?(:encode)
160
161
  else
161
162
 
162
163
  ######################################################################
163
- # Enhance the Fixnum class with a XML escaped character conversion.
164
+ # Enhance the Integer class with a XML escaped character conversion.
164
165
  #
165
- class Fixnum
166
+ class Integer
166
167
  XChar = Builder::XChar if ! defined?(XChar)
167
168
 
168
169
  # XML escaped version of chr. When <tt>escape</tt> is set to false
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'builder/blankslate'
4
5
 
@@ -17,20 +18,24 @@ module Builder
17
18
 
18
19
  # Create an XML markup builder.
19
20
  #
20
- # out:: Object receiving the markup. +out+ must respond to
21
- # <tt><<</tt>.
22
- # indent:: Number of spaces used for indentation (0 implies no
23
- # indentation and no line breaks).
24
- # initial:: Level of initial indentation.
25
- # encoding:: When <tt>encoding</tt> and $KCODE are set to 'utf-8'
26
- # characters aren't converted to character entities in
27
- # the output stream.
21
+ # out :: Object receiving the markup. +out+ must respond to
22
+ # <tt><<</tt>.
23
+ # indent :: Number of spaces used for indentation (0 implies no
24
+ # indentation and no line breaks).
25
+ # initial :: Level of initial indentation.
26
+ # encoding :: When <tt>encoding</tt> and $KCODE are set to 'utf-8'
27
+ # characters aren't converted to character entities in
28
+ # the output stream.
28
29
  def initialize(indent=0, initial=0, encoding='utf-8')
29
30
  @indent = indent
30
31
  @level = initial
31
32
  @encoding = encoding.downcase
32
33
  end
33
34
 
35
+ def explicit_nil_handling?
36
+ @explicit_nil_handling
37
+ end
38
+
34
39
  # Create a tag named +sym+. Other than the first argument which
35
40
  # is the tag name, the arguments are the same as the tags
36
41
  # implemented via <tt>method_missing</tt>.
@@ -45,9 +50,10 @@ module Builder
45
50
  attrs ||= {}
46
51
  attrs.merge!(arg)
47
52
  when nil
48
- # do nothing
53
+ attrs ||= {}
54
+ attrs.merge!({:nil => true}) if explicit_nil_handling?
49
55
  else
50
- text ||= ''
56
+ text ||= ''.dup
51
57
  text << arg.to_s
52
58
  end
53
59
  end
@@ -180,8 +186,10 @@ module Builder
180
186
  # significantly.
181
187
  def cache_method_call(sym)
182
188
  class << self; self; end.class_eval do
183
- define_method(sym) do |*args, &block|
184
- tag!(sym, *args, &block)
189
+ unless method_defined?(sym)
190
+ define_method(sym) do |*args, &block|
191
+ tag!(sym, *args, &block)
192
+ end
185
193
  end
186
194
  end
187
195
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  #--
4
5
  # Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #--
3
4
  # Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org).
4
5
  # All rights reserved.
@@ -47,7 +48,7 @@ module Builder
47
48
  # == Notes:
48
49
  #
49
50
  # * The order that attributes are inserted in markup tags is
50
- # undefined.
51
+ # undefined.
51
52
  #
52
53
  # * Sometimes you wish to insert text without enclosing tags. Use
53
54
  # the <tt>text!</tt> method to accomplish this.
@@ -78,7 +79,7 @@ module Builder
78
79
  # <tt>tag!</tt> will also take text and attribute arguments (after
79
80
  # the tag name) like normal markup methods. (But see the next
80
81
  # bullet item for a better way to handle XML namespaces).
81
- #
82
+ #
82
83
  # * Direct support for XML namespaces is now available. If the
83
84
  # first argument to a tag call is a symbol, it will be joined to
84
85
  # the tag to produce a namespace:tag combination. It is easier to
@@ -93,7 +94,7 @@ module Builder
93
94
  # * XmlMarkup builds the markup in any object (called a _target_)
94
95
  # that accepts the <tt><<</tt> method. If no target is given,
95
96
  # then XmlMarkup defaults to a string target.
96
- #
97
+ #
97
98
  # Examples:
98
99
  #
99
100
  # xm = Builder::XmlMarkup.new
@@ -110,7 +111,7 @@ module Builder
110
111
  # xm = Builder::XmlMarkup.new
111
112
  # x2 = Builder::XmlMarkup.new(:target=>xm)
112
113
  # # Markup written to +x2+ will be send to +xm+.
113
- #
114
+ #
114
115
  # * Indentation is enabled by providing the number of spaces to
115
116
  # indent for each level as a second argument to XmlBuilder.new.
116
117
  # Initial indentation may be specified using a third parameter.
@@ -119,7 +120,7 @@ module Builder
119
120
  #
120
121
  # xm = Builder.new(:indent=>2)
121
122
  # # xm will produce nicely formatted and indented XML.
122
- #
123
+ #
123
124
  # xm = Builder.new(:indent=>2, :margin=>4)
124
125
  # # xm will produce nicely formatted and indented XML with 2
125
126
  # # spaces per indent and an over all indentation level of 4.
@@ -162,34 +163,39 @@ module Builder
162
163
  # Create an XML markup builder. Parameters are specified by an
163
164
  # option hash.
164
165
  #
165
- # :target=><em>target_object</em>::
166
+ # :target => <em>target_object</em>::
166
167
  # Object receiving the markup. +target_object+ must respond to
167
168
  # the <tt><<(<em>a_string</em>)</tt> operator and return
168
169
  # itself. The default target is a plain string target.
169
- #
170
- # :indent=><em>indentation</em>::
170
+ #
171
+ # :indent => <em>indentation</em>::
171
172
  # Number of spaces used for indentation. The default is no
172
173
  # indentation and no line breaks.
173
- #
174
- # :margin=><em>initial_indentation_level</em>::
174
+ #
175
+ # :margin => <em>initial_indentation_level</em>::
175
176
  # Amount of initial indentation (specified in levels, not
176
177
  # spaces).
177
- #
178
- # :escape_attrs=><em>OBSOLETE</em>::
178
+ #
179
+ # :quote => <em>:single</em>::
180
+ # Use single quotes for attributes rather than double quotes.
181
+ #
182
+ # :escape_attrs => <em>OBSOLETE</em>::
179
183
  # The :escape_attrs option is no longer supported by builder
180
184
  # (and will be quietly ignored). String attribute values are
181
185
  # now automatically escaped. If you need unescaped attribute
182
186
  # values (perhaps you are using entities in the attribute
183
187
  # values), then give the value as a Symbol. This allows much
184
188
  # finer control over escaping attribute values.
185
- #
189
+ #
186
190
  def initialize(options={})
187
191
  indent = options[:indent] || 0
188
192
  margin = options[:margin] || 0
193
+ @quote = (options[:quote] == :single) ? "'" : '"'
194
+ @explicit_nil_handling = options[:explicit_nil_handling]
189
195
  super(indent, margin)
190
- @target = options[:target] || ""
196
+ @target = options[:target] || "".dup
191
197
  end
192
-
198
+
193
199
  # Return the target of the builder.
194
200
  def target!
195
201
  @target
@@ -265,7 +271,12 @@ module Builder
265
271
  _ensure_no_block ::Kernel::block_given?
266
272
  _special("<![CDATA[", "]]>", text.gsub(']]>', ']]]]><![CDATA[>'), nil)
267
273
  end
268
-
274
+
275
+ def cdata_value!(open, text)
276
+ _ensure_no_block ::Kernel::block_given?
277
+ _special("<#{open}>", "</#{open}>", "<![CDATA[#{text.gsub(']]>', ']]]]><![CDATA[>')}]]>", nil)
278
+ end
279
+
269
280
  private
270
281
 
271
282
  # NOTE: All private methods of a builder object are prefixed when
@@ -275,8 +286,8 @@ module Builder
275
286
  def _text(text)
276
287
  @target << text
277
288
  end
278
-
279
- # Insert special instruction.
289
+
290
+ # Insert special instruction.
280
291
  def _special(open, close, data=nil, attrs=nil, order=[])
281
292
  _indent
282
293
  @target << open
@@ -294,7 +305,7 @@ module Builder
294
305
  @target << "/" if end_too
295
306
  @target << ">"
296
307
  end
297
-
308
+
298
309
  # Insert an ending tag.
299
310
  def _end_tag(sym)
300
311
  @target << "</#{sym}>"
@@ -305,10 +316,10 @@ module Builder
305
316
  return if attrs.nil?
306
317
  order.each do |k|
307
318
  v = attrs[k]
308
- @target << %{ #{k}="#{_attr_value(v)}"} if v # " WART
319
+ @target << %{ #{k}=#{@quote}#{_attr_value(v)}#{@quote}} if v
309
320
  end
310
321
  attrs.each do |k, v|
311
- @target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k) # " WART
322
+ @target << %{ #{k}=#{@quote}#{_attr_value(v)}#{@quote}} unless order.member?(k) # " WART
312
323
  end
313
324
  end
314
325
 
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ # Optional publish task for Rake
3
+
4
+ begin
5
+ require 'rake/contrib/sshpublisher'
6
+ require 'rake/contrib/rubyforgepublisher'
7
+
8
+ publisher = Rake::CompositePublisher.new
9
+ publisher.add Rake::RubyForgePublisher.new('builder', 'jimweirich')
10
+ publisher.add Rake::SshFilePublisher.new(
11
+ 'linode',
12
+ 'htdocs/software/builder',
13
+ '.',
14
+ 'builder.blurb')
15
+
16
+ desc "Publish the Documentation to RubyForge."
17
+ task :publish => [:rdoc] do
18
+ publisher.upload
19
+ end
20
+ rescue LoadError
21
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ module Tags
5
+ extend Rake::DSL if defined?(Rake::DSL)
6
+
7
+ PROG = ENV['TAGS'] || 'ctags'
8
+
9
+ RAKEFILES = FileList['Rakefile', '**/*.rake']
10
+
11
+ FILES = FileList['**/*.rb', '**/*.js'] + RAKEFILES
12
+ FILES.exclude('pkg', 'dist')
13
+
14
+ PROJECT_DIR = ['.']
15
+
16
+ RVM_GEMDIR = File.join(`rvm gemdir`.strip, "gems") rescue nil
17
+ SYSTEM_DIRS = RVM_GEMDIR && File.exists?(RVM_GEMDIR) ? RVM_GEMDIR : []
18
+
19
+ module_function
20
+
21
+ # Convert key_word to --key-word.
22
+ def keyword(key)
23
+ k = key.to_s.gsub(/_/, '-')
24
+ (k.length == 1) ? "-#{k}" : "--#{k}"
25
+ end
26
+
27
+ # Run ctags command
28
+ def run(*args)
29
+ opts = {
30
+ :e => true,
31
+ :totals => true,
32
+ :recurse => true,
33
+ }
34
+ opts = opts.merge(args.pop) if args.last.is_a?(Hash)
35
+ command_args = opts.map { |k, v|
36
+ (v == true) ? keyword(k) : "#{keyword(k)}=#{v}"
37
+ }.join(" ")
38
+ sh %{#{Tags::PROG} #{command_args} #{args.join(' ')}}
39
+ end
40
+ end
41
+
42
+ namespace "tags" do
43
+ desc "Generate an Emacs TAGS file"
44
+ task :emacs, [:all] => Tags::FILES do |t, args|
45
+ puts "Making Emacs TAGS file"
46
+ verbose(true) do
47
+ Tags.run(Tags::PROJECT_DIR)
48
+ Tags.run(Tags::RAKEFILES,
49
+ :language_force => "ruby",
50
+ :append => true)
51
+ if args.all
52
+ Tags::SYSTEM_DIRS.each do |dir|
53
+ Tags.run(dir,
54
+ :language_force => "ruby",
55
+ :append => true)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ desc "Generate the TAGS file"
63
+ task :tags, [:all] => ["tags:emacs"]
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/test*.rb']
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ require 'minitest/autorun'
3
+
4
+ module Builder
5
+ class Test < Minitest::Test
6
+ alias :assert_raise :assert_raises
7
+ alias :assert_not_nil :refute_nil
8
+
9
+ def assert_nothing_raised
10
+ yield
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ # encoding: iso-8859-1
2
4
 
3
5
  #--
4
6
  # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
@@ -13,7 +15,7 @@
13
15
  require 'builder/xmlmarkup'
14
16
  require 'benchmark'
15
17
 
16
- text = "This is a test of the new xml markup. Itrntinliztin\n" * 10000
18
+ text = "This is a test of the new xml markup. I�t�rn�ti�n�liz�ti�n\n" * 10000
17
19
 
18
20
  include Benchmark # we need the CAPTION and FMTSTR constants
19
21
  include Builder
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  #--
4
5
  # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  #--
4
5
  # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
@@ -10,8 +11,8 @@
10
11
  # above copyright notice is included.
11
12
  #++
12
13
 
13
- require 'test/unit'
14
- require 'test/preload'
14
+ require 'helper'
15
+ require 'preload'
15
16
  require 'blankslate'
16
17
  require 'stringio'
17
18
 
@@ -46,10 +47,6 @@ module Kernel
46
47
  1234
47
48
  end
48
49
 
49
- def double_late_addition
50
- 11
51
- end
52
-
53
50
  def double_late_addition
54
51
  22
55
52
  end
@@ -80,7 +77,7 @@ end
80
77
  ######################################################################
81
78
  # Test case for blank slate.
82
79
  #
83
- class TestBlankSlate < Test::Unit::TestCase
80
+ class TestBlankSlate < Builder::Test
84
81
  def setup
85
82
  @bs = BlankSlate.new
86
83
  end
@@ -108,12 +105,6 @@ class TestBlankSlate < Test::Unit::TestCase
108
105
  end
109
106
  end
110
107
 
111
- def test_targetted_private_methods_are_undefined_during_instance_eval
112
- assert_raise(NoMethodError, NameError) do
113
- @bs.instance_eval do self.puts "HI" end
114
- end
115
- end
116
-
117
108
  def test_untargetted_private_methods_are_defined_during_instance_eval
118
109
  oldstdout = $stdout
119
110
  $stdout = StringIO.new