building-blocks 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +103 -33
- data/VERSION +1 -1
- data/lib/building_blocks/base.rb +1 -1
- data/spec/building-blocks/base_spec.rb +33 -17
- metadata +18 -4
data/README.rdoc
CHANGED
@@ -21,8 +21,8 @@ The syntax for defining and using blocks is similar to how content_for and yield
|
|
21
21
|
My code to render
|
22
22
|
<% end %>
|
23
23
|
|
24
|
-
<!-- Elsewhere, you can
|
25
|
-
<%= blocks.
|
24
|
+
<!-- Elsewhere, you can render the block as follows -->
|
25
|
+
<%= blocks.render :my_block %>
|
26
26
|
|
27
27
|
<!-- Will render: My code to render -->
|
28
28
|
|
@@ -34,13 +34,13 @@ Parameters may also be passed into defined blocks:
|
|
34
34
|
The user of this block passed in "<%= options[:my_parameter] %>" as :my_parameter.
|
35
35
|
<% end %>
|
36
36
|
|
37
|
-
<!-- Elsewhere, you can
|
38
|
-
<%= blocks.
|
37
|
+
<!-- Elsewhere, you can render the block as follows -->
|
38
|
+
<%= blocks.render :my_block, :my_parameter => "The value I'm passing in" %>
|
39
39
|
|
40
40
|
<!-- Will render: The user of this block passed in "The value I'm passing in" as :my_parameter. -->
|
41
41
|
|
42
42
|
<!-- If the anticipated parameters are not passed: -->
|
43
|
-
<%= blocks.
|
43
|
+
<%= blocks.render :my_block %>
|
44
44
|
|
45
45
|
<!-- Will render: The user of this block passed in "" as :my_parameter. -->
|
46
46
|
|
@@ -52,24 +52,24 @@ The parameters are not required, but unexpected results might occur if the "nece
|
|
52
52
|
First parameter: <%= first_parameter %>, Second parameter: <%= second_parameter %>, Third parameter: <%= options[:third_parameter] %>
|
53
53
|
<% end %>
|
54
54
|
|
55
|
-
<!-- Elsewhere, you can
|
56
|
-
<%= blocks.
|
55
|
+
<!-- Elsewhere, you can render the block as follows -->
|
56
|
+
<%= blocks.render :my_block, "Value 1", 2, :third_parameter => "Value 3" %>
|
57
57
|
|
58
58
|
<!-- Will render: First parameter: Value 1, Second parameter: 2, Third parameter: Value 3 -->
|
59
59
|
|
60
60
|
== Providing default values for parameters to blocks
|
61
61
|
|
62
|
-
In the last example, the parameter the block was expecting was not passed in. For this reason, it is possible to specify default values for the parameters when you define a block. If parameters are passed in when the block is
|
62
|
+
In the last example, the parameter the block was expecting was not passed in. For this reason, it is possible to specify default values for the parameters when you define a block. If parameters are passed in when the block is rendered, the values passed in override the default values.
|
63
63
|
|
64
64
|
<% blocks.define :my_block, :parameter1 => "Parameter 1", :parameter2 => "Parameter 2" do |options| %>
|
65
65
|
The values specified are :parameter1 = "<%= options[:parameter1] %>", :parameter2 = "<%= options[:parameter2] %>"
|
66
66
|
<% end %>
|
67
67
|
|
68
|
-
<!-- Elsewhere, you can
|
69
|
-
<%= blocks.
|
70
|
-
<%= blocks.
|
71
|
-
<%= blocks.
|
72
|
-
<%= blocks.
|
68
|
+
<!-- Elsewhere, you can render the block as follows (specifying zero, one, or both of the parameters the block uses) -->
|
69
|
+
<%= blocks.render :my_block %><br />
|
70
|
+
<%= blocks.render :my_block, :parameter1 => "New Parameter 1" %><br />
|
71
|
+
<%= blocks.render :my_block, :parameter2 => "New Parameter 2" %><br />
|
72
|
+
<%= blocks.render :my_block, :parameter1 => "New Parameter 1", :parameter2 => "New Parameter 2" %>
|
73
73
|
|
74
74
|
<!--
|
75
75
|
Will render:
|
@@ -81,11 +81,11 @@ In the last example, the parameter the block was expecting was not passed in. Fo
|
|
81
81
|
|
82
82
|
== Providing a default definition for a block
|
83
83
|
|
84
|
-
What happens if you attempt to
|
84
|
+
What happens if you attempt to render a block that hasn't been "define"d? Nothing will get rendered.
|
85
85
|
|
86
|
-
However, you may want to provide a default definition for a block to
|
86
|
+
However, you may want to provide a default definition for a block to render if such a block was never "define"d. You can do this as follows:
|
87
87
|
|
88
|
-
<%= blocks.
|
88
|
+
<%= blocks.render :my_block, :my_parameter_1 => "Parameter 1" do %>
|
89
89
|
This is my default definition of :my_block.
|
90
90
|
<% end %>
|
91
91
|
|
@@ -98,8 +98,8 @@ If however, you have defined :my_block elsewhere, it would have used that defini
|
|
98
98
|
Some other definition of :my_block with :my_parameter_1 set to "<%= options[:my_parameter_1] %>"
|
99
99
|
<% end %>
|
100
100
|
|
101
|
-
<!-- Elsewhere, you can
|
102
|
-
<%= blocks.
|
101
|
+
<!-- Elsewhere, you can render the block as follows -->
|
102
|
+
<%= blocks.render :my_block, :my_parameter_1 => "Parameter 1" do %>
|
103
103
|
This is my default definition of :my_block.
|
104
104
|
<% end %>
|
105
105
|
|
@@ -108,17 +108,17 @@ If however, you have defined :my_block elsewhere, it would have used that defini
|
|
108
108
|
|
109
109
|
== Using "before" and "after filters"
|
110
110
|
|
111
|
-
"Before" and "After" hooks render code before and after the code produced by a "blocks.
|
111
|
+
"Before" and "After" hooks render code before and after the code produced by a "blocks.render" call. A practical example of this would be adding view-specific javascript and stylesheet includes to a global layout file.
|
112
112
|
|
113
113
|
In your application.html layout file, you might use this as follows:
|
114
114
|
|
115
115
|
<html>
|
116
116
|
<head>
|
117
|
-
<%= blocks.
|
118
|
-
<%= blocks.
|
117
|
+
<%= blocks.render :includes do %>
|
118
|
+
<%= blocks.render :stylesheets do %>
|
119
119
|
<%= stylesheet_link_tag "application", :media => "all" %>
|
120
120
|
<% end %>
|
121
|
-
<%= blocks.
|
121
|
+
<%= blocks.render :javscripts do %>
|
122
122
|
<%= javascript_include_tag "application" %>
|
123
123
|
<% end %>
|
124
124
|
<%= csrf_meta_tags %>
|
@@ -176,16 +176,16 @@ Then, in a specific view that is rendered using this layout, you can add stylesh
|
|
176
176
|
|
177
177
|
== Blocks as Partials
|
178
178
|
|
179
|
-
Using exactly the same syntax for "using" blocks, one can put the code to be rendered in it's own separate file (in a partial). When "blocks.
|
179
|
+
Using exactly the same syntax for "using" blocks, one can put the code to be rendered in it's own separate file (in a partial). When "blocks.render :some_block" is called, the system will first look for a block defined inline (i.e. one that has been defined using "blocks.define :some_block"). Failing to find that, it will look for a partial by the same name in your current controller's view directory. Failing to find that partial, it will look for a partial in the global blocks' directory (by default, /app/views/blocks). Any parameters passed in as a hash will be initialized in the partial as local variables. And failing to find that, it will see if a default implementation has been provided for the block and render it if one has been specified.
|
180
180
|
|
181
181
|
As an example, consider the following code, running in a view for PagesController:
|
182
182
|
|
183
|
-
<%= blocks.
|
183
|
+
<%= blocks.render :wizard, :step => @step %>
|
184
184
|
|
185
|
-
<!-- 1) Check and see if there was a block defined called "wizard" somewhere prior to its
|
185
|
+
<!-- 1) Check and see if there was a block defined called "wizard" somewhere prior to its render... No? then... -->
|
186
186
|
<!-- 2) Check and see if there is a controller-specific partial /app/views/pages/wizard.html.erb. No? Then... -->
|
187
187
|
<!-- 3) Check and see if there is a global partial /app/views/blocks/wizard.html.erb. No? Then... -->
|
188
|
-
<!-- 4) Check and see if there is a default definition provided for "wizard", i.e. specified in the "blocks.
|
188
|
+
<!-- 4) Check and see if there is a default definition provided for "wizard", i.e. specified in the "blocks.render" call... No? Then render nothing -->
|
189
189
|
|
190
190
|
Let's look at each example individually, written in the order that BuildingBlocks attempts to render them:
|
191
191
|
|
@@ -194,20 +194,20 @@ Let's look at each example individually, written in the order that BuildingBlock
|
|
194
194
|
Inline Block Step#<%= options[:step] %>.
|
195
195
|
<% end %>
|
196
196
|
|
197
|
-
<!-- Elsewhere, you can
|
198
|
-
<%= blocks.
|
197
|
+
<!-- Elsewhere, you can render the block as follows -->
|
198
|
+
<%= blocks.render :wizard, :step => @step %>
|
199
199
|
2) Controller-specific partial:
|
200
|
-
<%= blocks.
|
200
|
+
<%= blocks.render :wizard, :step => @step %>
|
201
201
|
|
202
202
|
<!-- In /app/views/pages/_wizard.html.erb: -->
|
203
203
|
Controller-specific Block Step# <%= step %>.
|
204
204
|
3) Global partial:
|
205
|
-
<%= blocks.
|
205
|
+
<%= blocks.render :wizard, :step => @step %>
|
206
206
|
|
207
207
|
<!-- In /app/views/blocks/_wizard.html.erb: -->
|
208
208
|
Global Block Step#<%= step %>.
|
209
209
|
4) Default implementation of a block:
|
210
|
-
<%= blocks.
|
210
|
+
<%= blocks.render :wizard, :step => @step do |options| do %>
|
211
211
|
Default Implementation Block Step#<%= options %>.
|
212
212
|
<% end %>
|
213
213
|
|
@@ -235,9 +235,79 @@ As an example, consider {table-for}[https://github.com/hunterae/table-for], a ge
|
|
235
235
|
<%= table.column :delete %>
|
236
236
|
<% end %>
|
237
237
|
|
238
|
-
|
238
|
+
Templating allows the code to render a partial, but dynamically change how that partial is rendered from outside its rendering. So in the above example,
|
239
|
+
there is a table_for partial that gets rendered, but before it is rendered, the block provided to the table_for call will be parsed so that the table_for
|
240
|
+
template (partial) knows what to render, and occasionally, how to render to render it.
|
239
241
|
|
240
|
-
|
242
|
+
As an easier example, consider the following call in a view file:
|
243
|
+
<%= BuildingBlocks::Base.new(self).render_template("blocks/wizard") do |blocks| %>
|
244
|
+
<% blocks.queue :step1 %>
|
245
|
+
<% blocks.queue :step2 do %>
|
246
|
+
My Overridden Step 2 |
|
247
|
+
<% end %>
|
248
|
+
<% blocks.queue :step3 %>
|
249
|
+
<% blocks.queue do %>
|
250
|
+
| Anonymous Step 4
|
251
|
+
<% end %>
|
252
|
+
<% end %>
|
253
|
+
|
254
|
+
Here, a template is provided ("/app/views/blocks/_wizard.html.erb") and four blocks are queued (step1, step2, step3, and an anonymous step). Now, let's look at
|
255
|
+
the template:
|
256
|
+
<!-- /app/views/blocks/_wizard.html.erb -->
|
257
|
+
<% blocks.define :step1 do %>
|
258
|
+
Step 1 |
|
259
|
+
<% end %>
|
260
|
+
|
261
|
+
<% blocks.define :step2 do %>
|
262
|
+
Step 2 |
|
263
|
+
<% end %>
|
264
|
+
|
265
|
+
<% blocks.define :step3 do %>
|
266
|
+
Step 3
|
267
|
+
<% end %>
|
268
|
+
|
269
|
+
<% blocks.queued_blocks.each do |block| %>
|
270
|
+
<%= blocks.render block %>
|
271
|
+
<% end %>
|
272
|
+
|
273
|
+
Step1, Step2, and Step3 are all provided default definitions. Step2's definition is overridden from the outside (i.e. from the view that renders the template).
|
274
|
+
Since all of the queued blocks are rendered, the anonymous block (Step4) will also get rendered. The resulting output will be:
|
275
|
+
|
276
|
+
Step 1 | My Overridden Step 2 | Step 3 | Anonymous Step4
|
277
|
+
|
278
|
+
Notice the order of the queued blocks was preserved, Step2's definition was successfully overridden, and the anonymous definition for Step4 was also rendered.
|
279
|
+
|
280
|
+
This technique could also very easily be used to do something like wrapping content in some complicated markup, such is wrapping code in html tags to display as
|
281
|
+
a header container:
|
282
|
+
<%= BuildingBlocks::Base.new(self).render_template("blocks/header_container") do |blocks| %>
|
283
|
+
My code to wrap
|
284
|
+
<% end %>
|
285
|
+
|
286
|
+
<!-- In /app/views/blocks/_header_container.html.erb -->
|
287
|
+
<div class="header">
|
288
|
+
<div class="wrapper">
|
289
|
+
<%= captured_block %>
|
290
|
+
</div>
|
291
|
+
</div>
|
292
|
+
|
293
|
+
What will get rendered will be the following:
|
294
|
+
<div class="header">
|
295
|
+
<div class="wrapper">
|
296
|
+
My code to wrap
|
297
|
+
</div>
|
298
|
+
</div>
|
299
|
+
|
300
|
+
The code called from the view could easily be extracted in a helper method as follows:
|
301
|
+
def header_container(options={}, &block)
|
302
|
+
BuildingBlocks::Base.new(self, options).render_template("blocks/header_container", &block)
|
303
|
+
end
|
304
|
+
|
305
|
+
Then it could be called from the view as follows:
|
306
|
+
<%= header_container do %>
|
307
|
+
My code to wrap
|
308
|
+
<% end %>
|
309
|
+
|
310
|
+
VIDEO TUTORIAL TO COME SHOWING HOW TABLE_FOR CAN BE BUILT FROM SCRATCH
|
241
311
|
|
242
312
|
== Questions or Problems?
|
243
313
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.1
|
data/lib/building_blocks/base.rb
CHANGED
@@ -278,7 +278,7 @@ describe BuildingBlocks::Base do
|
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
-
describe "
|
281
|
+
describe "render method" do
|
282
282
|
before :each do
|
283
283
|
@builder.expects(:render_before_blocks).at_least_once
|
284
284
|
@builder.expects(:render_after_blocks).at_least_once
|
@@ -397,7 +397,7 @@ describe BuildingBlocks::Base do
|
|
397
397
|
end
|
398
398
|
end
|
399
399
|
|
400
|
-
describe "
|
400
|
+
describe "render method - before blocks" do
|
401
401
|
before :each do
|
402
402
|
@builder.expects(:render_block).at_least_once
|
403
403
|
@builder.expects(:render_after_blocks).at_least_once
|
@@ -410,25 +410,35 @@ describe BuildingBlocks::Base do
|
|
410
410
|
@builder.render :my_before_block, 1, 2, :value3 => 3, :value4 => 4
|
411
411
|
end
|
412
412
|
|
413
|
-
it "should try and render a before block as a local partial if no before blocks are specified" do
|
413
|
+
it "should try and render a before block as a local partial if no before blocks are specified and BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to true" do
|
414
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
415
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
414
416
|
block = Proc.new {}
|
415
417
|
@view.expects(:capture).never
|
416
418
|
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).once
|
417
419
|
@view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
|
418
420
|
@builder.render :my_before_block, :value1 => 1, :value2 => 2
|
421
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
422
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
419
423
|
end
|
420
424
|
|
421
|
-
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
|
425
|
+
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 and BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to true" do
|
426
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
427
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
422
428
|
block = Proc.new {}
|
423
429
|
@view.expects(:capture).never
|
424
430
|
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
425
431
|
@view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).once
|
426
432
|
@builder.render :my_before_block, :value1 => 1, :value2 => 2
|
433
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
434
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
427
435
|
end
|
428
436
|
|
429
|
-
it "should not attempt to render a before block as a partial if BuildingBlocks::USE_PARTIALS is set to false" do
|
437
|
+
it "should not attempt to render a before block as a partial if BuildingBlocks::USE_PARTIALS is set to false even if BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to true" do
|
430
438
|
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
431
439
|
BuildingBlocks.const_set("USE_PARTIALS", false)
|
440
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
441
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
432
442
|
block = Proc.new {}
|
433
443
|
@view.expects(:capture).never
|
434
444
|
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).never
|
@@ -436,18 +446,16 @@ describe BuildingBlocks::Base do
|
|
436
446
|
@builder.render :my_before_block, :value1 => 1, :value2 => 2
|
437
447
|
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
438
448
|
BuildingBlocks.const_set("USE_PARTIALS", true)
|
449
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
450
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
439
451
|
end
|
440
452
|
|
441
453
|
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
|
442
|
-
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
443
|
-
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
444
454
|
block = Proc.new {}
|
445
455
|
@view.expects(:capture).never
|
446
456
|
@view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).never
|
447
457
|
@view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
|
448
458
|
@builder.render :my_before_block, :value1 => 1, :value2 => 2
|
449
|
-
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
450
|
-
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
451
459
|
end
|
452
460
|
|
453
461
|
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
|
@@ -460,7 +468,7 @@ describe BuildingBlocks::Base do
|
|
460
468
|
end
|
461
469
|
end
|
462
470
|
|
463
|
-
describe "
|
471
|
+
describe "render method - after blocks" do
|
464
472
|
before :each do
|
465
473
|
@builder.expects(:render_block).at_least_once
|
466
474
|
@builder.expects(:render_before_blocks).at_least_once
|
@@ -473,25 +481,35 @@ describe BuildingBlocks::Base do
|
|
473
481
|
@builder.render :my_after_block, 1, 2, :value3 => 3, :value4 => 4
|
474
482
|
end
|
475
483
|
|
476
|
-
it "should try and render a after block as a local partial if no after blocks are specified" do
|
484
|
+
it "should try and render a after block as a local partial if no after blocks are specified and BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to true" do
|
485
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
486
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
477
487
|
block = Proc.new {}
|
478
488
|
@view.expects(:capture).never
|
479
489
|
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).once
|
480
490
|
@view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
|
481
491
|
@builder.render :my_after_block, :value1 => 1, :value2 => 2
|
492
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
493
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
482
494
|
end
|
483
495
|
|
484
|
-
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
|
496
|
+
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 and BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to true" do
|
497
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
498
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
485
499
|
block = Proc.new {}
|
486
500
|
@view.expects(:capture).never
|
487
501
|
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
488
502
|
@view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).once
|
489
503
|
@builder.render :my_after_block, :value1 => 1, :value2 => 2
|
504
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
505
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
490
506
|
end
|
491
507
|
|
492
|
-
it "should not attempt to render a after block as a partial if BuildingBlocks::USE_PARTIALS is set to false" do
|
508
|
+
it "should not attempt to render a after block as a partial if BuildingBlocks::USE_PARTIALS is set to false even if BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS is set to false" do
|
493
509
|
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
494
510
|
BuildingBlocks.const_set("USE_PARTIALS", false)
|
511
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
512
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
495
513
|
block = Proc.new {}
|
496
514
|
@view.expects(:capture).never
|
497
515
|
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).never
|
@@ -499,18 +517,16 @@ describe BuildingBlocks::Base do
|
|
499
517
|
@builder.render :my_after_block, :value1 => 1, :value2 => 2
|
500
518
|
BuildingBlocks.send(:remove_const, "USE_PARTIALS")
|
501
519
|
BuildingBlocks.const_set("USE_PARTIALS", true)
|
520
|
+
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
521
|
+
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
502
522
|
end
|
503
523
|
|
504
524
|
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
|
505
|
-
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
506
|
-
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", false)
|
507
525
|
block = Proc.new {}
|
508
526
|
@view.expects(:capture).never
|
509
527
|
@view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).never
|
510
528
|
@view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
|
511
529
|
@builder.render :my_after_block, :value1 => 1, :value2 => 2
|
512
|
-
BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
|
513
|
-
BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
|
514
530
|
end
|
515
531
|
|
516
532
|
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
|
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: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Hunter
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-07 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -202,6 +202,20 @@ dependencies:
|
|
202
202
|
prerelease: false
|
203
203
|
type: :development
|
204
204
|
requirement: *id013
|
205
|
+
- !ruby/object:Gem::Dependency
|
206
|
+
name: jeweler
|
207
|
+
version_requirements: &id014 !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
hash: 3
|
213
|
+
segments:
|
214
|
+
- 0
|
215
|
+
version: "0"
|
216
|
+
prerelease: false
|
217
|
+
type: :development
|
218
|
+
requirement: *id014
|
205
219
|
description: ""
|
206
220
|
email: hunterae@gmail.com
|
207
221
|
executables: []
|