builder 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ # Optional publish task for Rake
2
+
3
+ begin
4
+ require 'rake/contrib/sshpublisher'
5
+ require 'rake/contrib/rubyforgepublisher'
6
+
7
+ publisher = Rake::CompositePublisher.new
8
+ publisher.add Rake::RubyForgePublisher.new('builder', 'jimweirich')
9
+ publisher.add Rake::SshFilePublisher.new(
10
+ 'linode',
11
+ 'htdocs/software/builder',
12
+ '.',
13
+ 'builder.blurb')
14
+
15
+ desc "Publish the Documentation to RubyForge."
16
+ task :publish => [:rdoc] do
17
+ publisher.upload
18
+ end
19
+ rescue LoadError
20
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Tags
4
+ extend Rake::DSL if defined?(Rake::DSL)
5
+
6
+ PROG = ENV['TAGS'] || 'ctags'
7
+
8
+ RAKEFILES = FileList['Rakefile', '**/*.rake']
9
+
10
+ FILES = FileList['**/*.rb', '**/*.js'] + RAKEFILES
11
+ FILES.exclude('pkg', 'dist')
12
+
13
+ PROJECT_DIR = ['.']
14
+
15
+ RVM_GEMDIR = File.join(`rvm gemdir`.strip, "gems") rescue nil
16
+ SYSTEM_DIRS = RVM_GEMDIR && File.exists?(RVM_GEMDIR) ? RVM_GEMDIR : []
17
+
18
+ module_function
19
+
20
+ # Convert key_word to --key-word.
21
+ def keyword(key)
22
+ k = key.to_s.gsub(/_/, '-')
23
+ (k.length == 1) ? "-#{k}" : "--#{k}"
24
+ end
25
+
26
+ # Run ctags command
27
+ def run(*args)
28
+ opts = {
29
+ :e => true,
30
+ :totals => true,
31
+ :recurse => true,
32
+ }
33
+ opts = opts.merge(args.pop) if args.last.is_a?(Hash)
34
+ command_args = opts.map { |k, v|
35
+ (v == true) ? keyword(k) : "#{keyword(k)}=#{v}"
36
+ }.join(" ")
37
+ sh %{#{Tags::PROG} #{command_args} #{args.join(' ')}}
38
+ end
39
+ end
40
+
41
+ namespace "tags" do
42
+ desc "Generate an Emacs TAGS file"
43
+ task :emacs, [:all] => Tags::FILES do |t, args|
44
+ puts "Making Emacs TAGS file"
45
+ verbose(true) do
46
+ Tags.run(Tags::PROJECT_DIR)
47
+ Tags.run(Tags::RAKEFILES,
48
+ :language_force => "ruby",
49
+ :append => true)
50
+ if args.all
51
+ Tags::SYSTEM_DIRS.each do |dir|
52
+ Tags.run(dir,
53
+ :language_force => "ruby",
54
+ :append => true)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ desc "Generate the TAGS file"
62
+ task :tags, [:all] => ["tags:emacs"]
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/test*.rb']
6
+ t.verbose = true
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+
3
+ module Builder
4
+ class Test < Minitest::Test
5
+ alias :assert_raise :assert_raises
6
+ alias :assert_not_nil :refute_nil
7
+
8
+ def assert_nothing_raised
9
+ yield
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: iso-8859-1
3
+
4
+ #--
5
+ # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
6
+ # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
7
+ # All rights reserved.
8
+
9
+ # Permission is granted for use, copying, modification, distribution,
10
+ # and distribution of modified versions of this work as long as the
11
+ # above copyright notice is included.
12
+ #++
13
+
14
+ require 'builder/xmlmarkup'
15
+ require 'benchmark'
16
+
17
+ text = "This is a test of the new xml markup. I�t�rn�ti�n�liz�ti�n\n" * 10000
18
+
19
+ include Benchmark # we need the CAPTION and FMTSTR constants
20
+ include Builder
21
+ n = 50
22
+ Benchmark.benchmark do |bm|
23
+ tf = bm.report("base") {
24
+ n.times do
25
+ x = XmlMarkup.new
26
+ x.text(text)
27
+ x.target!
28
+ end
29
+ }
30
+ def XmlMarkup._escape(text)
31
+ text.to_xs
32
+ end
33
+ tf = bm.report("to_xs") {
34
+ n.times do
35
+ x = XmlMarkup.new
36
+ x.text(text)
37
+ x.target!
38
+ end
39
+ }
40
+ end
41
+
@@ -0,0 +1,39 @@
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
+ # We are defining method_added in Kernel and Object so that when
14
+ # BlankSlate overrides them later, we can verify that it correctly
15
+ # calls the older hooks.
16
+
17
+ module Kernel
18
+ class << self
19
+ attr_reader :k_added_names
20
+ alias_method :preload_method_added, :method_added
21
+ def method_added(name)
22
+ preload_method_added(name)
23
+ @k_added_names ||= []
24
+ @k_added_names << name
25
+ end
26
+ end
27
+ end
28
+
29
+ class Object
30
+ class << self
31
+ attr_reader :o_added_names
32
+ alias_method :preload_method_added, :method_added
33
+ def method_added(name)
34
+ preload_method_added(name)
35
+ @o_added_names ||= []
36
+ @o_added_names << name
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,213 @@
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 'helper'
14
+ require 'preload'
15
+ require 'blankslate'
16
+ require 'stringio'
17
+
18
+ # Methods to be introduced into the Object class late.
19
+ module LateObject
20
+ def late_object
21
+ 33
22
+ end
23
+ def LateObject.included(mod)
24
+ # Modules defining an included method should not prevent blank
25
+ # slate erasure!
26
+ end
27
+ end
28
+
29
+ # Methods to be introduced into the Kernel module late.
30
+ module LateKernel
31
+ def late_kernel
32
+ 44
33
+ end
34
+ def LateKernel.included(mod)
35
+ # Modules defining an included method should not prevent blank
36
+ # slate erasure!
37
+ end
38
+ end
39
+
40
+ # Introduce some late methods (both module and direct) into the Kernel
41
+ # module.
42
+ module Kernel
43
+ include LateKernel
44
+
45
+ def late_addition
46
+ 1234
47
+ end
48
+
49
+ def double_late_addition
50
+ 22
51
+ end
52
+ end
53
+
54
+
55
+ # Introduce some late methods (both module and direct) into the Object
56
+ # class.
57
+ class Object
58
+ include LateObject
59
+ def another_late_addition
60
+ 4321
61
+ end
62
+ end
63
+
64
+ # Introduce some late methods by inclusion.
65
+ module GlobalModule
66
+ def global_inclusion
67
+ 42
68
+ end
69
+ end
70
+ include GlobalModule
71
+
72
+ def direct_global
73
+ 43
74
+ end
75
+
76
+ ######################################################################
77
+ # Test case for blank slate.
78
+ #
79
+ class TestBlankSlate < Builder::Test
80
+ def setup
81
+ @bs = BlankSlate.new
82
+ end
83
+
84
+ def test_undefined_methods_remain_undefined
85
+ assert_raise(NoMethodError) { @bs.no_such_method }
86
+ assert_raise(NoMethodError) { @bs.nil? }
87
+ end
88
+
89
+
90
+ # NOTE: NameError is acceptable because the lack of a '.' means that
91
+ # Ruby can't tell if it is a method or a local variable.
92
+ def test_undefined_methods_remain_undefined_during_instance_eval
93
+ assert_raise(NoMethodError, NameError) do
94
+ @bs.instance_eval do nil? end
95
+ end
96
+ assert_raise(NoMethodError, NameError) do
97
+ @bs.instance_eval do no_such_method end
98
+ end
99
+ end
100
+
101
+ def test_private_methods_are_undefined
102
+ assert_raise(NoMethodError) do
103
+ @bs.puts "HI"
104
+ end
105
+ end
106
+
107
+ def test_targetted_private_methods_are_undefined_during_instance_eval
108
+ assert_raise(NoMethodError, NameError) do
109
+ @bs.instance_eval do self.puts "HI" end
110
+ end
111
+ end
112
+
113
+ def test_untargetted_private_methods_are_defined_during_instance_eval
114
+ oldstdout = $stdout
115
+ $stdout = StringIO.new
116
+ @bs.instance_eval do
117
+ puts "HI"
118
+ end
119
+ ensure
120
+ $stdout = oldstdout
121
+ end
122
+
123
+ def test_methods_added_late_to_kernel_remain_undefined
124
+ assert_equal 1234, nil.late_addition
125
+ assert_raise(NoMethodError) { @bs.late_addition }
126
+ end
127
+
128
+ def test_methods_added_late_to_object_remain_undefined
129
+ assert_equal 4321, nil.another_late_addition
130
+ assert_raise(NoMethodError) { @bs.another_late_addition }
131
+ end
132
+
133
+ def test_methods_added_late_to_global_remain_undefined
134
+ assert_equal 42, global_inclusion
135
+ assert_raise(NoMethodError) { @bs.global_inclusion }
136
+ end
137
+
138
+ def test_preload_method_added
139
+ assert Kernel.k_added_names.include?(:late_addition)
140
+ assert Object.o_added_names.include?(:another_late_addition)
141
+ end
142
+
143
+ def test_method_defined_late_multiple_times_remain_undefined
144
+ assert_equal 22, nil.double_late_addition
145
+ assert_raise(NoMethodError) { @bs.double_late_addition }
146
+ end
147
+
148
+ def test_late_included_module_in_object_is_ok
149
+ assert_equal 33, 1.late_object
150
+ assert_raise(NoMethodError) { @bs.late_object }
151
+ end
152
+
153
+ def test_late_included_module_in_kernel_is_ok
154
+ assert_raise(NoMethodError) { @bs.late_kernel }
155
+ end
156
+
157
+ def test_revealing_previously_hidden_methods_are_callable
158
+ with_to_s = Class.new(BlankSlate) do
159
+ reveal :to_s
160
+ end
161
+ assert_match(/^#<.*>$/, with_to_s.new.to_s)
162
+ end
163
+
164
+ def test_revealing_previously_hidden_methods_are_callable_with_block
165
+ Object.class_eval <<-EOS
166
+ def given_block(&block)
167
+ block
168
+ end
169
+ EOS
170
+
171
+ with_given_block = Class.new(BlankSlate) do
172
+ reveal :given_block
173
+ end
174
+ assert_not_nil with_given_block.new.given_block {}
175
+ end
176
+
177
+ def test_revealing_a_hidden_method_twice_is_ok
178
+ with_to_s = Class.new(BlankSlate) do
179
+ reveal :to_s
180
+ reveal :to_s
181
+ end
182
+ assert_match(/^#<.*>$/, with_to_s.new.to_s)
183
+ end
184
+
185
+ def test_revealing_unknown_hidden_method_is_an_error
186
+ assert_raises(RuntimeError) do
187
+ Class.new(BlankSlate) do
188
+ reveal :xyz
189
+ end
190
+ end
191
+ end
192
+
193
+ def test_global_includes_still_work
194
+ assert_nothing_raised do
195
+ assert_equal 42, global_inclusion
196
+ assert_equal 42, Object.new.global_inclusion
197
+ assert_equal 42, "magic number".global_inclusion
198
+ assert_equal 43, direct_global
199
+ end
200
+ end
201
+
202
+ def test_reveal_should_not_bind_to_an_instance
203
+ with_object_id = Class.new(BlankSlate) do
204
+ reveal(:object_id)
205
+ end
206
+
207
+ obj1 = with_object_id.new
208
+ obj2 = with_object_id.new
209
+
210
+ assert obj1.object_id != obj2.object_id,
211
+ "Revealed methods should not be bound to a particular instance"
212
+ end
213
+ end
@@ -0,0 +1,150 @@
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 'helper'
14
+ require 'preload'
15
+ require 'builder'
16
+ require 'builder/xmlevents'
17
+
18
+ class TestEvents < Builder::Test
19
+
20
+ class Target
21
+ attr_reader :events
22
+
23
+ def initialize
24
+ @events = []
25
+ end
26
+
27
+ def start_tag(tag, attrs)
28
+ @events << [:start_tag, tag, attrs]
29
+ end
30
+
31
+ def end_tag(tag)
32
+ @events << [:end_tag, tag]
33
+ end
34
+
35
+ def text(string)
36
+ @events << [:text, string]
37
+ end
38
+
39
+ end
40
+
41
+
42
+ def setup
43
+ @target = Target.new
44
+ @xml = Builder::XmlEvents.new(:target=>@target)
45
+ end
46
+
47
+ def test_simple
48
+ @xml.one
49
+ expect [:start_tag, :one, nil]
50
+ expect [:end_tag, :one]
51
+ expect_done
52
+ end
53
+
54
+ def test_nested
55
+ @xml.one { @xml.two }
56
+ expect [:start_tag, :one, nil]
57
+ expect [:start_tag, :two, nil]
58
+ expect [:end_tag, :two]
59
+ expect [:end_tag, :one]
60
+ expect_done
61
+ end
62
+
63
+ def test_text
64
+ @xml.one("a")
65
+ expect [:start_tag, :one, nil]
66
+ expect [:text, "a"]
67
+ expect [:end_tag, :one]
68
+ expect_done
69
+ end
70
+
71
+ def test_special_text
72
+ @xml.one("H&R")
73
+ expect [:start_tag, :one, nil]
74
+ expect [:text, "H&R"]
75
+ expect [:end_tag, :one]
76
+ expect_done
77
+ end
78
+
79
+ def test_text_with_entity
80
+ @xml.one("H&amp;R")
81
+ expect [:start_tag, :one, nil]
82
+ expect [:text, "H&amp;R"]
83
+ expect [:end_tag, :one]
84
+ expect_done
85
+ end
86
+
87
+ def test_attributes
88
+ @xml.a(:b=>"c", :x=>"y")
89
+ expect [:start_tag, :a, {:x => "y", :b => "c"}]
90
+ expect [:end_tag, :a]
91
+ expect_done
92
+ end
93
+
94
+ def test_moderately_complex
95
+ @xml.tag! "address-book" do |x|
96
+ x.entry :id=>"1" do
97
+ x.name {
98
+ x.first "Bill"
99
+ x.last "Smith"
100
+ }
101
+ x.address "Cincinnati"
102
+ end
103
+ x.entry :id=>"2" do
104
+ x.name {
105
+ x.first "John"
106
+ x.last "Doe"
107
+ }
108
+ x.address "Columbus"
109
+ end
110
+ end
111
+ expect [:start_tag, "address-book".intern, nil]
112
+ expect [:start_tag, :entry, {:id => "1"}]
113
+ expect [:start_tag, :name, nil]
114
+ expect [:start_tag, :first, nil]
115
+ expect [:text, "Bill"]
116
+ expect [:end_tag, :first]
117
+ expect [:start_tag, :last, nil]
118
+ expect [:text, "Smith"]
119
+ expect [:end_tag, :last]
120
+ expect [:end_tag, :name]
121
+ expect [:start_tag, :address, nil]
122
+ expect [:text, "Cincinnati"]
123
+ expect [:end_tag, :address]
124
+ expect [:end_tag, :entry]
125
+ expect [:start_tag, :entry, {:id => "2"}]
126
+ expect [:start_tag, :name, nil]
127
+ expect [:start_tag, :first, nil]
128
+ expect [:text, "John"]
129
+ expect [:end_tag, :first]
130
+ expect [:start_tag, :last, nil]
131
+ expect [:text, "Doe"]
132
+ expect [:end_tag, :last]
133
+ expect [:end_tag, :name]
134
+ expect [:start_tag, :address, nil]
135
+ expect [:text, "Columbus"]
136
+ expect [:end_tag, :address]
137
+ expect [:end_tag, :entry]
138
+ expect [:end_tag, "address-book".intern]
139
+ expect_done
140
+ end
141
+
142
+ def expect(value)
143
+ assert_equal value, @target.events.shift
144
+ end
145
+
146
+ def expect_done
147
+ assert_nil @target.events.shift
148
+ end
149
+
150
+ end