building-blocks 1.0.0 → 1.1.0
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.
- data/CHANGELOG.rdoc +6 -0
- data/VERSION +1 -1
- data/lib/building_blocks/base.rb +25 -10
- data/spec/building-blocks/base_spec.rb +107 -33
- data/spec/building-blocks/view_additions_spec.rb +22 -0
- metadata +33 -3
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
1.1.0 (February 4, 2012)
|
2
|
+
|
3
|
+
* Ability to disable use of partials when rendering a block
|
4
|
+
* Ability to disable use of partials for before and after hooks
|
5
|
+
* Complete test coverage
|
6
|
+
* :template_folder and :variable options are no longer being passed in as part of the options hash to defined blocks and partials
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/building_blocks/base.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
module BuildingBlocks
|
2
|
-
|
2
|
+
TEMPLATE_FOLDER = "blocks"
|
3
|
+
USE_PARTIALS = true
|
4
|
+
USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS = true
|
3
5
|
|
4
6
|
class Base
|
7
|
+
# a pointer to the ActionView that called BuildingBlocks
|
5
8
|
attr_accessor :view
|
6
9
|
|
10
|
+
# Hash of block names to BuildingBlocks::Container objects
|
7
11
|
attr_accessor :blocks
|
8
12
|
|
13
|
+
# the block that is passed in for the templating feature
|
9
14
|
attr_accessor :block
|
10
15
|
|
11
16
|
# Array of BuildingBlocks::Container objects, storing the order of blocks as they were queued
|
@@ -14,11 +19,18 @@ module BuildingBlocks
|
|
14
19
|
# counter, used to give unnamed blocks a unique name
|
15
20
|
attr_accessor :anonymous_block_number
|
16
21
|
|
22
|
+
# A Hash of queued_blocks arrays; a new array is started when method_missing is invoked
|
17
23
|
attr_accessor :block_groups
|
18
24
|
|
19
25
|
# These are the options that are passed into the initalize method
|
20
26
|
attr_accessor :global_options
|
21
27
|
|
28
|
+
# The default folder to look in for global partials
|
29
|
+
attr_accessor :templates_folder
|
30
|
+
|
31
|
+
# The variable to use when rendering the partial for the templating feature (by default, "blocks")
|
32
|
+
attr_accessor :variable
|
33
|
+
|
22
34
|
# Checks if a particular block has been defined within the current block scope.
|
23
35
|
# <%= blocks.defined? :some_block_name %>
|
24
36
|
# Options:
|
@@ -86,7 +98,7 @@ module BuildingBlocks
|
|
86
98
|
raise "Must specify :template parameter in order to render" unless global_options[:template]
|
87
99
|
|
88
100
|
render_options = global_options.clone
|
89
|
-
render_options[
|
101
|
+
render_options[self.variable] = self
|
90
102
|
render_options[:captured_block] = view.capture(self, &self.block) if self.block
|
91
103
|
|
92
104
|
view.render global_options[:template], render_options
|
@@ -129,8 +141,8 @@ module BuildingBlocks
|
|
129
141
|
protected
|
130
142
|
|
131
143
|
def initialize(view, options={}, &block)
|
132
|
-
options[:templates_folder]
|
133
|
-
|
144
|
+
self.templates_folder = options[:templates_folder] ? options.delete(:templates_folder) : BuildingBlocks::TEMPLATE_FOLDER
|
145
|
+
self.variable = (options[:variable] ? options.delete(:variable) : :blocks).to_sym
|
134
146
|
self.view = view
|
135
147
|
self.global_options = options
|
136
148
|
self.block = block
|
@@ -162,17 +174,20 @@ module BuildingBlocks
|
|
162
174
|
block_container = blocks[name]
|
163
175
|
args.push(global_options.merge(block_container.options).merge(block_options).merge(options))
|
164
176
|
buffer << view.capture(*(args[0, block_container.block.arity]), &block_container.block)
|
165
|
-
|
177
|
+
elsif BuildingBlocks::USE_PARTIALS
|
166
178
|
begin
|
167
179
|
begin
|
168
180
|
buffer << view.render("#{name.to_s}", global_options.merge(block_options).merge(options))
|
169
181
|
rescue ActionView::MissingTemplate
|
170
|
-
buffer << view.render("#{self.
|
182
|
+
buffer << view.render("#{self.templates_folder}/#{name.to_s}", global_options.merge(block_options).merge(options))
|
171
183
|
end
|
172
184
|
rescue ActionView::MissingTemplate
|
173
185
|
args.push(global_options.merge(options))
|
174
186
|
buffer << view.capture(*(args[0, block.arity]), &block) if block_given?
|
175
187
|
end
|
188
|
+
else
|
189
|
+
args.push(global_options.merge(options))
|
190
|
+
buffer << view.capture(*(args[0, block.arity]), &block) if block_given?
|
176
191
|
end
|
177
192
|
|
178
193
|
buffer
|
@@ -199,12 +214,12 @@ module BuildingBlocks
|
|
199
214
|
args_clone.push(global_options.merge(block_options).merge(block_container.options).merge(options))
|
200
215
|
buffer << view.capture(*(args_clone[0, block_container.block.arity]), &block_container.block)
|
201
216
|
end
|
202
|
-
|
217
|
+
elsif BuildingBlocks::USE_PARTIALS && BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS
|
203
218
|
begin
|
204
219
|
begin
|
205
220
|
buffer << view.render("before_#{name.to_s}", global_options.merge(block_options).merge(options))
|
206
221
|
rescue ActionView::MissingTemplate
|
207
|
-
buffer << view.render("#{self.
|
222
|
+
buffer << view.render("#{self.templates_folder}/before_#{name.to_s}", global_options.merge(block_options).merge(options))
|
208
223
|
end
|
209
224
|
rescue ActionView::MissingTemplate
|
210
225
|
end
|
@@ -234,12 +249,12 @@ module BuildingBlocks
|
|
234
249
|
args_clone.push(global_options.merge(block_options).merge(block_container.options).merge(options))
|
235
250
|
buffer << view.capture(*(args_clone[0, block_container.block.arity]), &block_container.block)
|
236
251
|
end
|
237
|
-
|
252
|
+
elsif BuildingBlocks::USE_PARTIALS && BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS
|
238
253
|
begin
|
239
254
|
begin
|
240
255
|
buffer << view.render("after_#{name.to_s}", global_options.merge(block_options).merge(options))
|
241
256
|
rescue ActionView::MissingTemplate
|
242
|
-
buffer << view.render("#{self.
|
257
|
+
buffer << view.render("#{self.templates_folder}/after_#{name.to_s}", global_options.merge(block_options).merge(options))
|
243
258
|
end
|
244
259
|
rescue ActionView::MissingTemplate
|
245
260
|
end
|
@@ -6,6 +6,20 @@ describe BuildingBlocks::Base do
|
|
6
6
|
@builder = BuildingBlocks::Base.new(@view)
|
7
7
|
end
|
8
8
|
|
9
|
+
it "should be able change the default global partials directory" do
|
10
|
+
BuildingBlocks.send(:remove_const, "TEMPLATE_FOLDER")
|
11
|
+
BuildingBlocks.const_set("TEMPLATE_FOLDER", "shared")
|
12
|
+
@builder = BuildingBlocks::Base.new(@view)
|
13
|
+
@builder.expects(:render_before_blocks).at_least_once
|
14
|
+
@builder.expects(:render_after_blocks).at_least_once
|
15
|
+
@view.expects(:capture).with(:value1 => 1, :value2 => 2).never
|
16
|
+
@view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
17
|
+
@view.expects(:render).with("shared/some_block", :value1 => 1, :value2 => 2).once
|
18
|
+
@builder.use :some_block, :value1 => 1, :value2 => 2
|
19
|
+
BuildingBlocks.send(:remove_const, "TEMPLATE_FOLDER")
|
20
|
+
BuildingBlocks.const_set("TEMPLATE_FOLDER", "blocks")
|
21
|
+
end
|
22
|
+
|
9
23
|
describe "defined? method" do
|
10
24
|
it "should be able to determine if a block by a specific name is already defined" do
|
11
25
|
@builder.defined?(:test_block).should be_false
|
@@ -150,7 +164,7 @@ describe BuildingBlocks::Base do
|
|
150
164
|
it "should set all of the global options as local variables to the partial it renders" do
|
151
165
|
view = mock()
|
152
166
|
builder = BuildingBlocks::Base.new(view, :template => "some_template")
|
153
|
-
view.expects(:render).with { |template, options| options.should eql :
|
167
|
+
view.expects(:render).with { |template, options| options.should eql :template => 'some_template', :blocks => builder }
|
154
168
|
builder.render
|
155
169
|
end
|
156
170
|
|
@@ -283,9 +297,9 @@ describe BuildingBlocks::Base do
|
|
283
297
|
end
|
284
298
|
|
285
299
|
it "should automatically pass in an options hash to a defined block that takes one paramter when that block is used" do
|
286
|
-
block = Proc.new {|options| "
|
300
|
+
block = Proc.new {|options| "Options are #{options.inspect}"}
|
287
301
|
@builder.define :some_block, &block
|
288
|
-
@builder.use(:some_block).should eql "
|
302
|
+
@builder.use(:some_block).should eql "Options are {}"
|
289
303
|
end
|
290
304
|
|
291
305
|
it "should be able to use a defined block by its name and pass in runtime arguments as a hash" do
|
@@ -293,7 +307,7 @@ describe BuildingBlocks::Base do
|
|
293
307
|
print_hash(options)
|
294
308
|
end
|
295
309
|
@builder.define :some_block, &block
|
296
|
-
@builder.use(:some_block, :param1 => 1, :param2 => "value2").should eql print_hash(:
|
310
|
+
@builder.use(:some_block, :param1 => 1, :param2 => "value2").should eql print_hash(:param1 => 1, :param2 => "value2")
|
297
311
|
end
|
298
312
|
|
299
313
|
it "should be able to use a defined block by its name and pass in runtime arguments one by one" do
|
@@ -301,7 +315,7 @@ describe BuildingBlocks::Base do
|
|
301
315
|
"first_param: #{first_param}, second_param: #{second_param}, #{print_hash options}"
|
302
316
|
end
|
303
317
|
@builder.define :some_block, &block
|
304
|
-
@builder.use(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:
|
318
|
+
@builder.use(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:param1 => 1, :param2 => "value2")}")
|
305
319
|
end
|
306
320
|
|
307
321
|
it "should match up the number of arguments to a defined block with the parameters passed when a block is used" do
|
@@ -317,45 +331,57 @@ describe BuildingBlocks::Base do
|
|
317
331
|
"first_param: #{first_param}, second_param: #{second_param}, #{print_hash options}"
|
318
332
|
end
|
319
333
|
@builder.replace :some_block, &block
|
320
|
-
@builder.use(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:
|
334
|
+
@builder.use(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:param1 => 1, :param2 => "value2")}")
|
321
335
|
end
|
322
336
|
|
323
337
|
it "should not render anything if using a block that has been defined" do
|
324
338
|
@view.expects(:capture).never
|
325
|
-
@view.expects(:render).with("some_block",
|
326
|
-
@view.expects(:render).with("blocks/some_block",
|
339
|
+
@view.expects(:render).with("some_block", {}).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
340
|
+
@view.expects(:render).with("blocks/some_block", {}).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
327
341
|
@builder.use :some_block
|
328
342
|
end
|
329
343
|
|
330
344
|
it "should first attempt to capture a block's contents when blocks.use is called" do
|
331
345
|
block = Proc.new {|options|}
|
332
|
-
@view.expects(:capture).with(:
|
333
|
-
@view.expects(:render).with("some_block", :
|
334
|
-
@view.expects(:render).with("blocks/some_block", :
|
346
|
+
@view.expects(:capture).with(:value1 => 1, :value2 => 2)
|
347
|
+
@view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).never
|
348
|
+
@view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).never
|
335
349
|
@builder.define :some_block, &block
|
336
350
|
@builder.use :some_block, :value1 => 1, :value2 => 2
|
337
351
|
end
|
338
352
|
|
339
353
|
it "should second attempt to render a local partial by the block's name when blocks.use is called" do
|
340
|
-
@view.expects(:capture).with(:
|
341
|
-
@view.expects(:render).with("some_block", :
|
342
|
-
@view.expects(:render).with("blocks/some_block", :
|
354
|
+
@view.expects(:capture).with(:value1 => 1, :value2 => 2).never
|
355
|
+
@view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).once
|
356
|
+
@view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).never
|
343
357
|
@builder.use :some_block, :value1 => 1, :value2 => 2
|
344
358
|
end
|
345
359
|
|
346
360
|
it "should third attempt to render a global partial by the block's name when blocks.use is called" do
|
347
|
-
@view.expects(:capture).with(:
|
348
|
-
@view.expects(:render).with("some_block", :
|
349
|
-
@view.expects(:render).with("blocks/some_block", :
|
361
|
+
@view.expects(:capture).with(:value1 => 1, :value2 => 2).never
|
362
|
+
@view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
363
|
+
@view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).once
|
350
364
|
@builder.use :some_block, :value1 => 1, :value2 => 2
|
351
365
|
end
|
352
366
|
|
353
367
|
it "should fourth attempt to render a default block when blocks.use is called" do
|
354
368
|
block = Proc.new {|options|}
|
355
|
-
@view.expects(:render).with("some_block", :
|
356
|
-
@view.expects(:render).with("blocks/some_block", :
|
357
|
-
@view.expects(:capture).with(:
|
369
|
+
@view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
370
|
+
@view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
371
|
+
@view.expects(:capture).with(:value1 => 1, :value2 => 2)
|
372
|
+
@builder.use :some_block, :value1 => 1, :value2 => 2, &block
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should not attempt to render a partial if BuildingBlocks::USE_PARTIALS is set to false" do
|
376
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
377
|
+
BuildingBlocks.const_set("USE_PARTIALS", false)
|
378
|
+
block = Proc.new {|options|}
|
379
|
+
@view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).never
|
380
|
+
@view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).never
|
381
|
+
@view.expects(:capture).with(:value1 => 1, :value2 => 2)
|
358
382
|
@builder.use :some_block, :value1 => 1, :value2 => 2, &block
|
383
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
384
|
+
BuildingBlocks.const_set("USE_PARTIALS", true)
|
359
385
|
end
|
360
386
|
|
361
387
|
it "should override hash options for a block by merging the runtime options the define default options into the queue level options into the global options" do
|
@@ -364,7 +390,7 @@ describe BuildingBlocks::Base do
|
|
364
390
|
@builder.queue(:my_before_block, :param1 => "queue level", :param2 => "queue level")
|
365
391
|
@builder.define(:my_before_block, :param1 => "define level", :param2 => "define level", :param3 => "define level", &block)
|
366
392
|
block_container = @builder.queued_blocks.first
|
367
|
-
@view.expects(:capture).with(:param4 => 'global level', :param1 => 'use level', :
|
393
|
+
@view.expects(:capture).with(:param4 => 'global level', :param1 => 'use level', :param2 => 'queue level', :param3 => 'define level')
|
368
394
|
@builder.use block_container, :param1 => "use level"
|
369
395
|
end
|
370
396
|
|
@@ -386,32 +412,56 @@ describe BuildingBlocks::Base do
|
|
386
412
|
it "should render before blocks when using a block" do
|
387
413
|
block = Proc.new {|value1, value2, options|}
|
388
414
|
@builder.before("my_before_block", &block)
|
389
|
-
@view.expects(:capture).with(1, 2, :
|
415
|
+
@view.expects(:capture).with(1, 2, :value3 => 3, :value4 => 4)
|
390
416
|
@builder.use :my_before_block, 1, 2, :value3 => 3, :value4 => 4
|
391
417
|
end
|
392
418
|
|
393
419
|
it "should try and render a before block as a local partial if no before blocks are specified" do
|
394
420
|
block = Proc.new {}
|
395
421
|
@view.expects(:capture).never
|
396
|
-
@view.expects(:render).with("before_my_before_block", :
|
397
|
-
@view.expects(:render).with("blocks/before_my_before_block", :
|
422
|
+
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).once
|
423
|
+
@view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
|
398
424
|
@builder.use :my_before_block, :value1 => 1, :value2 => 2
|
399
425
|
end
|
400
426
|
|
401
427
|
it "should try and render a before block as a global partial if no after blocks are specified and the local partial does not exist" do
|
402
428
|
block = Proc.new {}
|
403
429
|
@view.expects(:capture).never
|
404
|
-
@view.expects(:render).with("before_my_before_block", :
|
405
|
-
@view.expects(:render).with("blocks/before_my_before_block", :
|
430
|
+
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
431
|
+
@view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).once
|
406
432
|
@builder.use :my_before_block, :value1 => 1, :value2 => 2
|
407
433
|
end
|
408
434
|
|
435
|
+
it "should not attempt to render a before block as a partial if BuildingBlocks::USE_PARTIALS is set to false" do
|
436
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
437
|
+
BuildingBlocks.const_set("USE_PARTIALS", false)
|
438
|
+
block = Proc.new {}
|
439
|
+
@view.expects(:capture).never
|
440
|
+
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).never
|
441
|
+
@view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
|
442
|
+
@builder.use :my_before_block, :value1 => 1, :value2 => 2
|
443
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
444
|
+
BuildingBlocks.const_set("USE_PARTIALS", true)
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should not attempt to render a before block as a partial if BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to false" do
|
448
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
449
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
450
|
+
block = Proc.new {}
|
451
|
+
@view.expects(:capture).never
|
452
|
+
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).never
|
453
|
+
@view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
|
454
|
+
@builder.use :my_before_block, :value1 => 1, :value2 => 2
|
455
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
456
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
457
|
+
end
|
458
|
+
|
409
459
|
it "should override hash options for before blocks by merging the runtime options into the before block options into the block options into the global options" do
|
410
460
|
block = Proc.new {|options|}
|
411
461
|
@builder.global_options.merge!(:param1 => "global level", :param2 => "global level", :param3 => "global level", :param4 => "global level")
|
412
462
|
@builder.define(:my_before_block, :param1 => "block level", :param2 => "block level", :param3 => "block level", &block)
|
413
463
|
@builder.before(:my_before_block, :param1 => "before block level", :param2 => "before block level", &block)
|
414
|
-
@view.expects(:capture).with(:param4 => 'global level', :param1 => 'top level', :
|
464
|
+
@view.expects(:capture).with(:param4 => 'global level', :param1 => 'top level', :param2 => 'before block level', :param3 => 'block level')
|
415
465
|
@builder.use :my_before_block, :param1 => "top level"
|
416
466
|
end
|
417
467
|
end
|
@@ -425,24 +475,48 @@ describe BuildingBlocks::Base do
|
|
425
475
|
it "should render after blocks when using a block" do
|
426
476
|
block = Proc.new {|value1, value2, options|}
|
427
477
|
@builder.after("my_after_block", &block)
|
428
|
-
@view.expects(:capture).with(1, 2, :
|
478
|
+
@view.expects(:capture).with(1, 2, :value3 => 3, :value4 => 4)
|
429
479
|
@builder.use :my_after_block, 1, 2, :value3 => 3, :value4 => 4
|
430
480
|
end
|
431
481
|
|
432
482
|
it "should try and render a after block as a local partial if no after blocks are specified" do
|
433
483
|
block = Proc.new {}
|
434
484
|
@view.expects(:capture).never
|
435
|
-
@view.expects(:render).with("after_my_after_block", :
|
436
|
-
@view.expects(:render).with("blocks/after_my_after_block", :
|
485
|
+
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).once
|
486
|
+
@view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
|
437
487
|
@builder.use :my_after_block, :value1 => 1, :value2 => 2
|
438
488
|
end
|
439
489
|
|
440
490
|
it "should try and render a after block as a global partial if no after blocks are specified and the local partial does not exist" do
|
441
491
|
block = Proc.new {}
|
442
492
|
@view.expects(:capture).never
|
443
|
-
@view.expects(:render).with("after_my_after_block", :
|
444
|
-
@view.expects(:render).with("blocks/after_my_after_block", :
|
493
|
+
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
494
|
+
@view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).once
|
495
|
+
@builder.use :my_after_block, :value1 => 1, :value2 => 2
|
496
|
+
end
|
497
|
+
|
498
|
+
it "should not attempt to render a after block as a partial if BuildingBlocks::USE_PARTIALS is set to false" do
|
499
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
500
|
+
BuildingBlocks.const_set("USE_PARTIALS", false)
|
501
|
+
block = Proc.new {}
|
502
|
+
@view.expects(:capture).never
|
503
|
+
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).never
|
504
|
+
@view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
|
505
|
+
@builder.use :my_after_block, :value1 => 1, :value2 => 2
|
506
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
507
|
+
BuildingBlocks.const_set("USE_PARTIALS", true)
|
508
|
+
end
|
509
|
+
|
510
|
+
it "should not attempt to render a after block as a partial if BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to false" do
|
511
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
512
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
513
|
+
block = Proc.new {}
|
514
|
+
@view.expects(:capture).never
|
515
|
+
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).never
|
516
|
+
@view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
|
445
517
|
@builder.use :my_after_block, :value1 => 1, :value2 => 2
|
518
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
519
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
446
520
|
end
|
447
521
|
|
448
522
|
it "should override hash options for after blocks by merging the runtime options into the after block options into the block options into the global options" do
|
@@ -450,7 +524,7 @@ describe BuildingBlocks::Base do
|
|
450
524
|
@builder.global_options.merge!(:param1 => "global level", :param2 => "global level", :param3 => "global level", :param4 => "global level")
|
451
525
|
@builder.define(:my_after_block, :param1 => "block level", :param2 => "block level", :param3 => "block level", &block)
|
452
526
|
@builder.after(:my_after_block, :param1 => "after block level", :param2 => "after block level", &block)
|
453
|
-
@view.expects(:capture).with(:param4 => 'global level', :param1 => 'top level', :
|
527
|
+
@view.expects(:capture).with(:param4 => 'global level', :param1 => 'top level', :param2 => 'after block level', :param3 => 'block level')
|
454
528
|
@builder.use :my_after_block, :param1 => "top level"
|
455
529
|
end
|
456
530
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BuildingBlocks::ViewAdditions do
|
4
|
+
before(:each) do
|
5
|
+
@view_class = Class.new
|
6
|
+
@view = @view_class.new
|
7
|
+
@view_class.send(:include, BuildingBlocks::ViewAdditions::ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "blocks method" do
|
11
|
+
it "should pass the view as the only parameter to BuildingBlocks::Base initialization" do
|
12
|
+
BuildingBlocks::Base.expects(:new).with {|view| view == @view}
|
13
|
+
@view.blocks
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should memoize the BuildingBlocks::Base instance for 'blocks' call" do
|
17
|
+
BuildingBlocks::Base.expects(:new).once.with {|view| view == @view}.returns "something"
|
18
|
+
@view.blocks.should eql "something"
|
19
|
+
@view.blocks.should eql "something"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: building-blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Hunter
|
@@ -132,6 +132,34 @@ dependencies:
|
|
132
132
|
prerelease: false
|
133
133
|
type: :development
|
134
134
|
requirement: *id008
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: jeweler
|
137
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
prerelease: false
|
147
|
+
type: :development
|
148
|
+
requirement: *id009
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: jeweler
|
151
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
hash: 3
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
version: "0"
|
160
|
+
prerelease: false
|
161
|
+
type: :development
|
162
|
+
requirement: *id010
|
135
163
|
description: ""
|
136
164
|
email: hunterae@gmail.com
|
137
165
|
executables: []
|
@@ -141,6 +169,7 @@ extensions: []
|
|
141
169
|
extra_rdoc_files:
|
142
170
|
- README.rdoc
|
143
171
|
files:
|
172
|
+
- CHANGELOG.rdoc
|
144
173
|
- README.rdoc
|
145
174
|
- Rakefile
|
146
175
|
- VERSION
|
@@ -150,6 +179,7 @@ files:
|
|
150
179
|
- lib/building_blocks/view_additions.rb
|
151
180
|
- rails/init.rb
|
152
181
|
- spec/building-blocks/base_spec.rb
|
182
|
+
- spec/building-blocks/view_additions_spec.rb
|
153
183
|
- spec/spec_helper.rb
|
154
184
|
has_rdoc: true
|
155
185
|
homepage: http://github.com/hunterae/building-blocks
|