builder 2.0.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of builder might be problematic. Click here for more details.
- data/CHANGES +20 -0
- data/README +1 -1
- data/Rakefile +55 -7
- data/doc/releases/builder-2.1.1.rdoc +58 -0
- data/lib/blankslate.rb +111 -0
- data/lib/builder/blankslate.rb +9 -52
- data/lib/builder/xchar.rb +6 -3
- data/lib/builder/xmlbase.rb +26 -31
- data/lib/builder/xmlmarkup.rb +25 -25
- data/test/preload.rb +1 -1
- data/test/testblankslate.rb +136 -11
- metadata +19 -15
data/CHANGES
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
= Change Log
|
2
2
|
|
3
|
+
== Version 2.1.1
|
4
|
+
|
5
|
+
* Fixed typo in XmlMarkup class docs (ident => indent). (from Martin
|
6
|
+
Fowler).
|
7
|
+
* Removed extra directory indirection from legacy CVS to SVN move.
|
8
|
+
* Removed some extraneous tabs from source.
|
9
|
+
* Fixed test on private methods in blankslate to differentiate between
|
10
|
+
targetted and untargetted private methods.
|
11
|
+
* Removed legacy capture of @self in XmlBase (@self was used back when
|
12
|
+
we used instance eval).
|
13
|
+
* Added additional tests for global functions (both direct and included).
|
14
|
+
|
15
|
+
== Version 2.1.0
|
16
|
+
|
17
|
+
* Fixed bug in BlankSlate where including a module into Object could
|
18
|
+
cause methods to leak into BlankSlate.
|
19
|
+
* Made BlankSlate available as its own gem. Currently the builder gem
|
20
|
+
still directly includes the BlankSlate code.
|
21
|
+
* Added reveal capability to BlankSlate.
|
22
|
+
|
3
23
|
== Version 2.0.0
|
4
24
|
|
5
25
|
* Added doc directory
|
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', '~>
|
22
|
+
require_gem 'builder', '~> 2.0'
|
23
23
|
|
24
24
|
builder = Builder::XmlMarkup.new
|
25
25
|
xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
data/Rakefile
CHANGED
@@ -19,7 +19,9 @@ end
|
|
19
19
|
|
20
20
|
# Determine the current version of the software
|
21
21
|
|
22
|
-
|
22
|
+
CLOBBER.include('pkg')
|
23
|
+
|
24
|
+
CURRENT_VERSION = '2.1.1'
|
23
25
|
PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION
|
24
26
|
|
25
27
|
SRC_RB = FileList['lib/**/*.rb']
|
@@ -64,6 +66,11 @@ PKG_FILES = FileList[
|
|
64
66
|
PKG_FILES.exclude('test/testcssbuilder.rb')
|
65
67
|
PKG_FILES.exclude('lib/builder/css.rb')
|
66
68
|
|
69
|
+
BLANKSLATE_FILES = FileList[
|
70
|
+
'lib/blankslate.rb',
|
71
|
+
'test/testblankslate.rb'
|
72
|
+
]
|
73
|
+
|
67
74
|
if ! defined?(Gem)
|
68
75
|
puts "Package Target requires RubyGEMs"
|
69
76
|
else
|
@@ -74,35 +81,76 @@ else
|
|
74
81
|
s.name = 'builder'
|
75
82
|
s.version = PKG_VERSION
|
76
83
|
s.summary = "Builders for MarkUp."
|
77
|
-
s.description =
|
84
|
+
s.description = %{\
|
78
85
|
Builder provides a number of builder objects that make creating structured data
|
79
86
|
simple to do. Currently the following builder objects are supported:
|
80
87
|
|
81
88
|
* XML Markup
|
82
89
|
* XML Events
|
83
|
-
|
90
|
+
}
|
84
91
|
|
85
92
|
s.files = PKG_FILES.to_a
|
86
93
|
s.require_path = 'lib'
|
87
94
|
s.autorequire = 'builder'
|
88
|
-
|
95
|
+
|
89
96
|
s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
|
90
|
-
|
97
|
+
|
91
98
|
s.has_rdoc = true
|
92
99
|
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
|
93
100
|
s.rdoc_options <<
|
94
101
|
'--title' << 'Builder -- Easy XML Building' <<
|
95
102
|
'--main' << 'README' <<
|
96
103
|
'--line-numbers'
|
97
|
-
|
104
|
+
|
98
105
|
s.author = "Jim Weirich"
|
99
106
|
s.email = "jim@weirichhouse.org"
|
100
107
|
s.homepage = "http://onestepback.org"
|
101
108
|
end
|
102
|
-
|
109
|
+
|
110
|
+
blankslate_spec = Gem::Specification.new do |s|
|
111
|
+
|
112
|
+
#### Basic information.
|
113
|
+
|
114
|
+
s.name = 'blankslate'
|
115
|
+
s.version = PKG_VERSION
|
116
|
+
s.summary = "Blank Slate base class."
|
117
|
+
s.description = %{\
|
118
|
+
BlankSlate provides a base class where almost all of the methods from Object and
|
119
|
+
Kernel have been removed. This is useful when providing proxy object and other
|
120
|
+
classes that make heavy use of method_missing.
|
121
|
+
}
|
122
|
+
|
123
|
+
s.files = BLANKSLATE_FILES.to_a
|
124
|
+
s.require_path = 'lib'
|
125
|
+
s.autorequire = 'builder'
|
126
|
+
|
127
|
+
s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
|
128
|
+
|
129
|
+
s.has_rdoc = true
|
130
|
+
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
|
131
|
+
s.rdoc_options <<
|
132
|
+
'--title' << 'BlankSlate -- Base Class for building proxies.' <<
|
133
|
+
'--main' << 'README' <<
|
134
|
+
'--line-numbers'
|
135
|
+
|
136
|
+
s.author = "Jim Weirich"
|
137
|
+
s.email = "jim@weirichhouse.org"
|
138
|
+
s.homepage = "http://onestepback.org"
|
139
|
+
end
|
140
|
+
|
141
|
+
namespace 'builder' do
|
103
142
|
Rake::GemPackageTask.new(spec) do |t|
|
104
143
|
t.need_tar = true
|
105
144
|
end
|
145
|
+
end
|
146
|
+
|
147
|
+
namespace 'blankslate' do
|
148
|
+
Rake::GemPackageTask.new(blankslate_spec) do |t|
|
149
|
+
t.need_tar = true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
task :package => ['builder:package', 'blankslate:package']
|
106
154
|
end
|
107
155
|
|
108
156
|
desc "Look for Debugging print lines"
|
@@ -0,0 +1,58 @@
|
|
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
|
data/lib/blankslate.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Copyright 2004, 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
|
+
|
11
|
+
######################################################################
|
12
|
+
# BlankSlate provides an abstract base class with no predefined
|
13
|
+
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
14
|
+
# BlankSlate is useful as a base class when writing classes that
|
15
|
+
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
16
|
+
#
|
17
|
+
class BlankSlate
|
18
|
+
class << self
|
19
|
+
|
20
|
+
# Hide the method named +name+ in the BlankSlate class. Don't
|
21
|
+
# hide +instance_eval+ or any method beginning with "__".
|
22
|
+
def hide(name)
|
23
|
+
if instance_methods.include?(name.to_s) and
|
24
|
+
name !~ /^(__|instance_eval)/
|
25
|
+
@hidden_methods ||= {}
|
26
|
+
@hidden_methods[name.to_sym] = instance_method(name)
|
27
|
+
undef_method name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_hidden_method(name)
|
32
|
+
@hidden_methods ||= {}
|
33
|
+
@hidden_methods[name] || superclass.find_hidden_method(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def reveal(name)
|
37
|
+
bound_method = nil
|
38
|
+
unbound_method = find_hidden_method(name)
|
39
|
+
fail "Don't know how to reveal method '#{name}'" unless unbound_method
|
40
|
+
define_method(name) do |*args|
|
41
|
+
bound_method ||= unbound_method.bind(self)
|
42
|
+
bound_method.call(*args)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
instance_methods.each { |m| hide(m) }
|
48
|
+
end
|
49
|
+
|
50
|
+
######################################################################
|
51
|
+
# Since Ruby is very dynamic, methods added to the ancestors of
|
52
|
+
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
|
53
|
+
# list of available BlankSlate methods. We handle this by defining a
|
54
|
+
# hook in the Object and Kernel classes that will hide any method
|
55
|
+
# defined after BlankSlate has been loaded.
|
56
|
+
#
|
57
|
+
module Kernel
|
58
|
+
class << self
|
59
|
+
alias_method :blank_slate_method_added, :method_added
|
60
|
+
|
61
|
+
# Detect method additions to Kernel and remove them in the
|
62
|
+
# BlankSlate class.
|
63
|
+
def method_added(name)
|
64
|
+
result = blank_slate_method_added(name)
|
65
|
+
return result if self != Kernel
|
66
|
+
BlankSlate.hide(name)
|
67
|
+
result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
######################################################################
|
73
|
+
# Same as above, except in Object.
|
74
|
+
#
|
75
|
+
class Object
|
76
|
+
class << self
|
77
|
+
alias_method :blank_slate_method_added, :method_added
|
78
|
+
|
79
|
+
# Detect method additions to Object and remove them in the
|
80
|
+
# BlankSlate class.
|
81
|
+
def method_added(name)
|
82
|
+
result = blank_slate_method_added(name)
|
83
|
+
return result if self != Object
|
84
|
+
BlankSlate.hide(name)
|
85
|
+
result
|
86
|
+
end
|
87
|
+
|
88
|
+
def find_hidden_method(name)
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
######################################################################
|
95
|
+
# Also, modules included into Object need to be scanned and have their
|
96
|
+
# instance methods removed from blank slate. In theory, modules
|
97
|
+
# included into Kernel would have to be removed as well, but a
|
98
|
+
# "feature" of Ruby prevents late includes into modules from being
|
99
|
+
# exposed in the first place.
|
100
|
+
#
|
101
|
+
class Module
|
102
|
+
alias blankslate_original_append_features append_features
|
103
|
+
def append_features(mod)
|
104
|
+
result = blankslate_original_append_features(mod)
|
105
|
+
return result if mod != Object
|
106
|
+
instance_methods.each do |name|
|
107
|
+
BlankSlate.hide(name)
|
108
|
+
end
|
109
|
+
result
|
110
|
+
end
|
111
|
+
end
|
data/lib/builder/blankslate.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#--
|
3
|
-
# Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
3
|
+
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
|
4
4
|
# All rights reserved.
|
5
5
|
|
6
6
|
# Permission is granted for use, copying, modification, distribution,
|
@@ -8,56 +8,13 @@
|
|
8
8
|
# above copyright notice is included.
|
9
9
|
#++
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
# BlankSlate provides an abstract base class with no predefined
|
14
|
-
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
15
|
-
# BlankSlate is useful as a base class when writing classes that
|
16
|
-
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
17
|
-
class BlankSlate
|
18
|
-
class << self
|
19
|
-
|
20
|
-
# Hide the method named +name+ in the BlankSlate class. Don't
|
21
|
-
# hide +instance_eval+ or any method beginning with "__".
|
22
|
-
def hide(name)
|
23
|
-
undef_method name if
|
24
|
-
instance_methods.include?(name.to_s) and
|
25
|
-
name !~ /^(__|instance_eval)/
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
instance_methods.each { |m| hide(m) }
|
30
|
-
end
|
31
|
-
end
|
11
|
+
require 'blankslate'
|
32
12
|
|
33
|
-
|
34
|
-
# BlankSlate
|
35
|
-
#
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# Detect method additions to Kernel and remove them in the
|
42
|
-
# BlankSlate class.
|
43
|
-
def method_added(name)
|
44
|
-
blank_slate_method_added(name)
|
45
|
-
return if self != Kernel
|
46
|
-
Builder::BlankSlate.hide(name)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Object
|
52
|
-
class << self
|
53
|
-
alias_method :blank_slate_method_added, :method_added
|
54
|
-
|
55
|
-
# Detect method additions to Object and remove them in the
|
56
|
-
# BlankSlate class.
|
57
|
-
def method_added(name)
|
58
|
-
blank_slate_method_added(name)
|
59
|
-
return if self != Object
|
60
|
-
Builder::BlankSlate.hide(name)
|
61
|
-
end
|
62
|
-
end
|
13
|
+
######################################################################
|
14
|
+
# BlankSlate has been promoted to a top level name and is now
|
15
|
+
# available as a standalone gem. We make the name available in the
|
16
|
+
# Builder namespace for compatibility.
|
17
|
+
#
|
18
|
+
module Builder
|
19
|
+
BlankSlate = ::BlankSlate
|
63
20
|
end
|
data/lib/builder/xchar.rb
CHANGED
@@ -73,7 +73,7 @@ module Builder
|
|
73
73
|
|
74
74
|
# See http://www.w3.org/TR/REC-xml/#charsets for details.
|
75
75
|
VALID = [
|
76
|
-
|
76
|
+
0x9, 0xA, 0xD,
|
77
77
|
(0x20..0xD7FF),
|
78
78
|
(0xE000..0xFFFD),
|
79
79
|
(0x10000..0x10FFFF)
|
@@ -92,8 +92,11 @@ class Fixnum
|
|
92
92
|
# XML escaped version of chr
|
93
93
|
def xchr
|
94
94
|
n = XChar::CP1252[self] || self
|
95
|
-
n
|
96
|
-
|
95
|
+
case n when *XChar::VALID
|
96
|
+
XChar::PREDEFINED[n] or (n<128 ? n.chr : "&##{n};")
|
97
|
+
else
|
98
|
+
'*'
|
99
|
+
end
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
data/lib/builder/xmlbase.rb
CHANGED
@@ -39,37 +39,36 @@ module Builder
|
|
39
39
|
attrs = nil
|
40
40
|
sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
|
41
41
|
args.each do |arg|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
case arg
|
43
|
+
when Hash
|
44
|
+
attrs ||= {}
|
45
|
+
attrs.merge!(arg)
|
46
|
+
else
|
47
|
+
text ||= ''
|
48
|
+
text << arg.to_s
|
49
|
+
end
|
50
50
|
end
|
51
51
|
if block
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
_newline
|
52
|
+
unless text.nil?
|
53
|
+
raise ArgumentError, "XmlMarkup cannot mix a text argument with a block"
|
54
|
+
end
|
55
|
+
_indent
|
56
|
+
_start_tag(sym, attrs)
|
57
|
+
_newline
|
58
|
+
_nested_structures(block)
|
59
|
+
_indent
|
60
|
+
_end_tag(sym)
|
61
|
+
_newline
|
63
62
|
elsif text.nil?
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
_indent
|
64
|
+
_start_tag(sym, attrs, true)
|
65
|
+
_newline
|
67
66
|
else
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
_indent
|
68
|
+
_start_tag(sym, attrs)
|
69
|
+
text! text
|
70
|
+
_end_tag(sym)
|
71
|
+
_newline
|
73
72
|
end
|
74
73
|
@target
|
75
74
|
end
|
@@ -120,10 +119,6 @@ module Builder
|
|
120
119
|
_escape(text).gsub(%r{"}, '"') # " WART
|
121
120
|
end
|
122
121
|
|
123
|
-
def _capture_outer_self(block)
|
124
|
-
@self = eval("self", block)
|
125
|
-
end
|
126
|
-
|
127
122
|
def _newline
|
128
123
|
return if @indent == 0
|
129
124
|
text! "\n"
|
data/lib/builder/xmlmarkup.rb
CHANGED
@@ -117,7 +117,7 @@ module Builder
|
|
117
117
|
#
|
118
118
|
# Example:
|
119
119
|
#
|
120
|
-
# xm = Builder.new(:
|
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)
|
@@ -209,18 +209,18 @@ module Builder
|
|
209
209
|
_indent
|
210
210
|
@target << "<!#{inst}"
|
211
211
|
args.each do |arg|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
212
|
+
case arg
|
213
|
+
when String
|
214
|
+
@target << %{ "#{arg}"} # " WART
|
215
|
+
when Symbol
|
216
|
+
@target << " #{arg}"
|
217
|
+
end
|
218
218
|
end
|
219
219
|
if block_given?
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
220
|
+
@target << " ["
|
221
|
+
_newline
|
222
|
+
_nested_structures(block)
|
223
|
+
@target << "]"
|
224
224
|
end
|
225
225
|
@target << ">"
|
226
226
|
_newline
|
@@ -238,15 +238,15 @@ module Builder
|
|
238
238
|
def instruct!(directive_tag=:xml, attrs={})
|
239
239
|
_ensure_no_block block_given?
|
240
240
|
if directive_tag == :xml
|
241
|
-
|
242
|
-
|
241
|
+
a = { :version=>"1.0", :encoding=>"UTF-8" }
|
242
|
+
attrs = a.merge attrs
|
243
243
|
end
|
244
244
|
_special(
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
245
|
+
"<?#{directive_tag}",
|
246
|
+
"?>",
|
247
|
+
nil,
|
248
|
+
attrs,
|
249
|
+
[:version, :encoding, :standalone])
|
250
250
|
end
|
251
251
|
|
252
252
|
# Insert a CDATA section into the XML markup.
|
@@ -299,27 +299,27 @@ module Builder
|
|
299
299
|
def _insert_attributes(attrs, order=[])
|
300
300
|
return if attrs.nil?
|
301
301
|
order.each do |k|
|
302
|
-
|
303
|
-
|
302
|
+
v = attrs[k]
|
303
|
+
@target << %{ #{k}="#{_attr_value(v)}"} if v # " WART
|
304
304
|
end
|
305
305
|
attrs.each do |k, v|
|
306
|
-
|
306
|
+
@target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k) # " WART
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
310
310
|
def _attr_value(value)
|
311
311
|
case value
|
312
312
|
when Symbol
|
313
|
-
|
313
|
+
value.to_s
|
314
314
|
else
|
315
|
-
|
315
|
+
_escape_quote(value.to_s)
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
319
319
|
def _ensure_no_block(got_block)
|
320
320
|
if got_block
|
321
|
-
|
322
|
-
|
321
|
+
fail IllegalBlockError,
|
322
|
+
"Blocks are not allowed on XML instructions"
|
323
323
|
end
|
324
324
|
end
|
325
325
|
|
data/test/preload.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# We are defining method_added in Kernel and Object so that when
|
4
|
-
# BlankSlate overrides them
|
4
|
+
# BlankSlate overrides them later, we can verify that it correctly
|
5
5
|
# calls the older hooks.
|
6
6
|
|
7
7
|
module Kernel
|
data/test/testblankslate.rb
CHANGED
@@ -4,7 +4,33 @@ require 'test/unit'
|
|
4
4
|
require 'test/preload'
|
5
5
|
require 'builder/blankslate'
|
6
6
|
|
7
|
+
# Methods to be introduced into the Object class late.
|
8
|
+
module LateObject
|
9
|
+
def late_object
|
10
|
+
33
|
11
|
+
end
|
12
|
+
def LateObject.included(mod)
|
13
|
+
# Modules defining an included method should not prevent blank
|
14
|
+
# slate erasure!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Methods to be introduced into the Kernel module late.
|
19
|
+
module LateKernel
|
20
|
+
def late_kernel
|
21
|
+
44
|
22
|
+
end
|
23
|
+
def LateKernel.included(mod)
|
24
|
+
# Modules defining an included method should not prevent blank
|
25
|
+
# slate erasure!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Introduce some late methods (both module and direct) into the Kernel
|
30
|
+
# module.
|
7
31
|
module Kernel
|
32
|
+
include LateKernel
|
33
|
+
|
8
34
|
def late_addition
|
9
35
|
1234
|
10
36
|
end
|
@@ -19,39 +45,138 @@ module Kernel
|
|
19
45
|
end
|
20
46
|
|
21
47
|
|
22
|
-
|
23
|
-
class
|
48
|
+
# Introduce some late methods (both module and direct) into the Object
|
49
|
+
# class.
|
50
|
+
class Object
|
51
|
+
include LateObject
|
24
52
|
def another_late_addition
|
25
53
|
4321
|
26
54
|
end
|
27
55
|
end
|
28
56
|
|
57
|
+
# Introduce some late methods by inclusion.
|
58
|
+
module GlobalModule
|
59
|
+
def global_inclusion
|
60
|
+
42
|
61
|
+
end
|
62
|
+
end
|
63
|
+
include GlobalModule
|
64
|
+
|
65
|
+
def direct_global
|
66
|
+
43
|
67
|
+
end
|
68
|
+
|
69
|
+
######################################################################
|
70
|
+
# Test case for blank slate.
|
71
|
+
#
|
29
72
|
class TestBlankSlate < Test::Unit::TestCase
|
30
73
|
def setup
|
31
|
-
@bs =
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_create
|
35
|
-
assert nil != @bs
|
74
|
+
@bs = BlankSlate.new
|
36
75
|
end
|
37
76
|
|
38
|
-
def
|
77
|
+
def test_undefined_methods_remain_undefined
|
39
78
|
assert_raise(NoMethodError) { @bs.no_such_method }
|
40
79
|
assert_raise(NoMethodError) { @bs.nil? }
|
41
80
|
end
|
42
81
|
|
43
|
-
|
82
|
+
|
83
|
+
# NOTE: NameError is acceptable because the lack of a '.' means that
|
84
|
+
# Ruby can't tell if it is a method or a local variable.
|
85
|
+
def test_undefined_methods_remain_undefined_during_instance_eval
|
86
|
+
assert_raise(NoMethodError, NameError) do
|
87
|
+
@bs.instance_eval do nil? end
|
88
|
+
end
|
89
|
+
assert_raise(NoMethodError, NameError) do
|
90
|
+
@bs.instance_eval do no_such_method end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_private_methods_are_undefined
|
95
|
+
assert_raise(NoMethodError) do
|
96
|
+
@bs.puts "HI"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_targetted_private_methods_are_undefined_during_instance_eval
|
101
|
+
assert_raise(NoMethodError, NameError) do
|
102
|
+
@bs.instance_eval do self.puts "HI" end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_untargetted_private_methods_are_defined_during_instance_eval
|
107
|
+
oldstdout = $stdout
|
108
|
+
$stdout = StringIO.new
|
109
|
+
@bs.instance_eval do
|
110
|
+
puts "HI"
|
111
|
+
end
|
112
|
+
ensure
|
113
|
+
$stdout = oldstdout
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_methods_added_late_to_kernel_remain_undefined
|
117
|
+
assert_equal 1234, nil.late_addition
|
44
118
|
assert_raise(NoMethodError) { @bs.late_addition }
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_methods_added_late_to_object_remain_undefined
|
122
|
+
assert_equal 4321, nil.another_late_addition
|
45
123
|
assert_raise(NoMethodError) { @bs.another_late_addition }
|
46
124
|
end
|
125
|
+
|
126
|
+
def test_methods_added_late_to_global_remain_undefined
|
127
|
+
assert_equal 42, global_inclusion
|
128
|
+
assert_raise(NoMethodError) { @bs.global_inclusion }
|
129
|
+
end
|
47
130
|
|
48
131
|
def test_preload_method_added
|
49
132
|
assert Kernel.k_added_names.include?(:late_addition)
|
50
133
|
assert Object.o_added_names.include?(:another_late_addition)
|
51
134
|
end
|
52
135
|
|
53
|
-
def
|
54
|
-
|
136
|
+
def test_method_defined_late_multiple_times_remain_undefined
|
137
|
+
assert_equal 22, nil.double_late_addition
|
138
|
+
assert_raise(NoMethodError) { @bs.double_late_addition }
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_late_included_module_in_object_is_ok
|
142
|
+
assert_equal 33, 1.late_object
|
143
|
+
assert_raise(NoMethodError) { @bs.late_object }
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_late_included_module_in_kernel_is_ok
|
147
|
+
assert_raise(NoMethodError) { @bs.late_kernel }
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_revealing_previously_hidden_methods_is_ok
|
151
|
+
with_to_s = Class.new(BlankSlate) do
|
152
|
+
reveal :to_s
|
153
|
+
end
|
154
|
+
assert_match /^#<.*>$/, with_to_s.new.to_s
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_revealing_a_hidden_method_twice_is_ok
|
158
|
+
with_to_s = Class.new(BlankSlate) do
|
159
|
+
reveal :to_s
|
160
|
+
reveal :to_s
|
161
|
+
end
|
162
|
+
assert_match /^#<.*>$/, with_to_s.new.to_s
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_revealing_unknown_hidden_method_is_an_error
|
166
|
+
assert_raises(RuntimeError) do
|
167
|
+
Class.new(BlankSlate) do
|
168
|
+
reveal :xyz
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_global_includes_still_work
|
174
|
+
assert_nothing_raised do
|
175
|
+
assert_equal 42, global_inclusion
|
176
|
+
assert_equal 42, Object.new.global_inclusion
|
177
|
+
assert_equal 42, "magic number".global_inclusion
|
178
|
+
assert_equal 43, direct_global
|
179
|
+
end
|
55
180
|
end
|
56
181
|
end
|
57
182
|
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: builder
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.
|
7
|
-
date:
|
6
|
+
version: 2.1.1
|
7
|
+
date: 2007-03-01 00:00:00 -05:00
|
8
8
|
summary: Builders for MarkUp.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -25,32 +25,35 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
25
|
platform: ruby
|
26
26
|
signing_key:
|
27
27
|
cert_chain:
|
28
|
+
post_install_message:
|
28
29
|
authors:
|
29
30
|
- Jim Weirich
|
30
31
|
files:
|
32
|
+
- lib/blankslate.rb
|
31
33
|
- lib/builder.rb
|
32
|
-
- lib/builder/xmlmarkup.rb
|
33
|
-
- lib/builder/xmlbase.rb
|
34
34
|
- lib/builder/blankslate.rb
|
35
|
-
- lib/builder/xmlevents.rb
|
36
35
|
- lib/builder/xchar.rb
|
37
|
-
-
|
38
|
-
-
|
36
|
+
- lib/builder/xmlbase.rb
|
37
|
+
- lib/builder/xmlevents.rb
|
38
|
+
- lib/builder/xmlmarkup.rb
|
39
|
+
- test/performance.rb
|
39
40
|
- test/preload.rb
|
40
41
|
- test/test_xchar.rb
|
42
|
+
- test/testblankslate.rb
|
41
43
|
- test/testeventbuilder.rb
|
42
|
-
- test/
|
44
|
+
- test/testmarkupbuilder.rb
|
43
45
|
- scripts/publish.rb
|
44
|
-
- README
|
45
|
-
- Rakefile
|
46
46
|
- CHANGES
|
47
|
+
- Rakefile
|
48
|
+
- README
|
47
49
|
- doc/releases/builder-1.2.4.rdoc
|
48
50
|
- doc/releases/builder-2.0.0.rdoc
|
51
|
+
- doc/releases/builder-2.1.1.rdoc
|
49
52
|
test_files:
|
50
|
-
- test/testmarkupbuilder.rb
|
51
|
-
- test/testblankslate.rb
|
52
53
|
- test/test_xchar.rb
|
54
|
+
- test/testblankslate.rb
|
53
55
|
- test/testeventbuilder.rb
|
56
|
+
- test/testmarkupbuilder.rb
|
54
57
|
rdoc_options:
|
55
58
|
- --title
|
56
59
|
- Builder -- Easy XML Building
|
@@ -58,11 +61,12 @@ rdoc_options:
|
|
58
61
|
- README
|
59
62
|
- --line-numbers
|
60
63
|
extra_rdoc_files:
|
61
|
-
- README
|
62
|
-
- Rakefile
|
63
64
|
- CHANGES
|
65
|
+
- Rakefile
|
66
|
+
- README
|
64
67
|
- doc/releases/builder-1.2.4.rdoc
|
65
68
|
- doc/releases/builder-2.0.0.rdoc
|
69
|
+
- doc/releases/builder-2.1.1.rdoc
|
66
70
|
executables: []
|
67
71
|
|
68
72
|
extensions: []
|