building-blocks 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -3,4 +3,11 @@
3
3
  * Ability to disable use of partials when rendering a block
4
4
  * Ability to disable use of partials for before and after hooks
5
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
6
+ * :template_folder and :variable options are no longer being passed in as part of the options hash to defined blocks and partials
7
+
8
+ 1.2.0 (February 5, 2012)
9
+
10
+ * Changed prototype for "use" method, such that the name of the block being rendered is now a required parameter.
11
+ * Documented BuildingBlocks::Base more thoroughly
12
+ * Changed the blocks.use method to blocks.render (blocks.use is still available for legacy purposes)
13
+ * Removed the original render method and replaced with render_template that takes the partial and block to render as arguments.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -10,9 +10,6 @@ module BuildingBlocks
10
10
  # Hash of block names to BuildingBlocks::Container objects
11
11
  attr_accessor :blocks
12
12
 
13
- # the block that is passed in for the templating feature
14
- attr_accessor :block
15
-
16
13
  # Array of BuildingBlocks::Container objects, storing the order of blocks as they were queued
17
14
  attr_accessor :queued_blocks
18
15
 
@@ -50,9 +47,9 @@ module BuildingBlocks
50
47
  # The name of the block being defined (either a string or a symbol)
51
48
  # [+options+]
52
49
  # The default options for the block definition. Any or all of these options may be overrideen by
53
- # whomever calls "blocks.use" on this block.
50
+ # whomever calls "blocks.render" on this block.
54
51
  # [+block+]
55
- # The block that is to be rendered when "blocks.use" is called for this block.
52
+ # The block that is to be rendered when "blocks.render" is called for this block.
56
53
  def define(name, options={}, &block)
57
54
  self.define_block_container(name, options, &block)
58
55
  nil
@@ -71,37 +68,101 @@ module BuildingBlocks
71
68
  # The name of the block being defined (either a string or a symbol)
72
69
  # [+options+]
73
70
  # The default options for the block definition. Any or all of these options may be overrideen by
74
- # whomever calls "blocks.use" on this block.
71
+ # whomever calls "blocks.render" on this block.
75
72
  # [+block+]
76
- # The block that is to be rendered when "blocks.use" is called for this block.
73
+ # The block that is to be rendered when "blocks.render" is called for this block.
77
74
  def replace(name, options={}, &block)
78
75
  blocks[name.to_sym] = nil
79
76
  self.define_block_container(name, options, &block)
80
77
  nil
81
78
  end
82
79
 
83
- def use(*args, &block)
84
- name_or_container = args.first ? args.shift : self.anonymous_block_name
80
+ # Render a block, first rendering any "before" blocks, then rendering the block itself, then rendering
81
+ # any "after" blocks. BuildingBlocks will make four different attempts to render block:
82
+ # 1) Look for a block that has been defined inline elsewhere, using the blocks.define method:
83
+ # <% blocks.define :wizard do |options| %>
84
+ # Inline Block Step#<%= options[:step] %>.
85
+ # <% end %>
86
+ #
87
+ # <%= blocks.render :wizard, :step => @step %>
88
+ # 2) Look for a partial within the current controller's view directory:
89
+ # <%= blocks.render :wizard, :step => @step %>
90
+ #
91
+ # <!-- In /app/views/pages/_wizard.html.erb (assuming it is the pages controller running): -->
92
+ # Controller-specific Block Step# <%= step %>.
93
+ # 3) Look for a partial with the global blocks view directory (by default /app/views/blocks/):
94
+ # <%= blocks.render :wizard, :step => @step %>
95
+ #
96
+ # <!-- In /app/views/blocks/_wizard.html.erb: -->
97
+ # Global Block Step#<%= step %>.
98
+ # 4) Render the default implementation for the block if provided to the blocks.render call:
99
+ # <%= blocks.render :wizard, :step => @step do |options| do %>
100
+ # Default Implementation Block Step#<%= options %>.
101
+ # <% end %>
102
+ # Options:
103
+ # [+name+]
104
+ # The name of the block to render (either a string or a symbol)
105
+ # [+*args+]
106
+ # Any arguments to pass to the block to be rendered (and also to be passed to any "before" and "after" blocks).
107
+ # [+block+]
108
+ # The default block to render if no such block block that is to be rendered when "blocks.render" is called for this block.
109
+ def render(name_or_container, *args, &block)
85
110
  buffer = ActiveSupport::SafeBuffer.new
86
111
  buffer << render_before_blocks(name_or_container, *args)
87
112
  buffer << render_block(name_or_container, *args, &block)
88
113
  buffer << render_after_blocks(name_or_container, *args)
89
114
  buffer
90
115
  end
91
-
116
+ alias use render
117
+
118
+ # Queue a block for later rendering, such as within a template.
119
+ # <%= BuildingBlocks::Base.new(self).render_template("shared/wizard") do |blocks| %>
120
+ # <% blocks.queue :step1 %>
121
+ # <% blocks.queue :step2 do %>
122
+ # My overridden Step 2 |
123
+ # <% end %>
124
+ # <% blocks.queue :step3 %>
125
+ # <% blocks.queue do %>
126
+ # | Anonymous Step 4
127
+ # <% end %>
128
+ # <% end %>
129
+ #
130
+ # <!-- In /app/views/shared/wizard -->
131
+ # <% blocks.define :step1 do %>
132
+ # Step 1 |
133
+ # <% end %>
134
+ #
135
+ # <% blocks.define :step2 do %>
136
+ # Step 2 |
137
+ # <% end %>
138
+ #
139
+ # <% blocks.define :step3 do %>
140
+ # Step 3
141
+ # <% end %>
142
+ #
143
+ # <% blocks.queued_blocks.each do |block| %>
144
+ # <%= blocks.render block %>
145
+ # <% end %>
146
+ #
147
+ # <!-- Will render: Step 1 | My overridden Step 2 | Step 3 | Anonymous Step 4-->
148
+ # Options:
149
+ # [+*args+]
150
+ # The options to pass in when this block is rendered. These will override any options provided to the actual block
151
+ # definition. Any or all of these options may be overriden by whoever calls "blocks.render" on this block.
152
+ # Usually the first of these args will be the name of the block being queued (either a string or a symbol)
153
+ # [+block+]
154
+ # The optional block definition to render when the queued block is rendered
92
155
  def queue(*args, &block)
93
156
  self.queued_blocks << self.define_block_container(*args, &block)
94
157
  nil
95
158
  end
96
159
 
97
- def render
98
- raise "Must specify :template parameter in order to render" unless global_options[:template]
99
-
160
+ def render_template(partial, &block)
100
161
  render_options = global_options.clone
101
162
  render_options[self.variable] = self
102
- render_options[:captured_block] = view.capture(self, &self.block) if self.block
163
+ render_options[:captured_block] = view.capture(self, &block) if block_given?
103
164
 
104
- view.render global_options[:template], render_options
165
+ view.render partial, render_options
105
166
  end
106
167
 
107
168
  def before(name, options={}, &block)
@@ -116,6 +177,8 @@ module BuildingBlocks
116
177
  end
117
178
  alias append after
118
179
 
180
+ protected
181
+
119
182
  # If a method is missing, we'll assume the user is starting a new block group by that missing method name
120
183
  def method_missing(m, *args, &block)
121
184
  options = args.extract_options!
@@ -130,7 +193,7 @@ module BuildingBlocks
130
193
  self.queued_blocks = []
131
194
  self.block_groups[m] = self.queued_blocks
132
195
 
133
- # Capture the contents of the block group (this will only capture block definitions and block uses)
196
+ # Capture the contents of the block group (this will only capture block definitions and block renders; it will ignore anything else)
134
197
  view.capture(global_options.merge(options), &block) if block_given?
135
198
 
136
199
  # restore the original block positions array
@@ -138,14 +201,11 @@ module BuildingBlocks
138
201
  nil
139
202
  end
140
203
 
141
- protected
142
-
143
- def initialize(view, options={}, &block)
204
+ def initialize(view, options={})
144
205
  self.templates_folder = options[:templates_folder] ? options.delete(:templates_folder) : BuildingBlocks::TEMPLATE_FOLDER
145
206
  self.variable = (options[:variable] ? options.delete(:variable) : :blocks).to_sym
146
207
  self.view = view
147
208
  self.global_options = options
148
- self.block = block
149
209
  self.queued_blocks = []
150
210
  self.blocks = {}
151
211
  self.anonymous_block_number = 0
@@ -194,41 +254,14 @@ module BuildingBlocks
194
254
  end
195
255
 
196
256
  def render_before_blocks(name_or_container, *args)
197
- options = args.extract_options!
198
-
199
- block_options = {}
200
- if (name_or_container.is_a?(BuildingBlocks::Container))
201
- name = name_or_container.name.to_sym
202
- block_options = name_or_container.options
203
- else
204
- name = name_or_container.to_sym
205
- block_options = blocks[name].options if blocks[name]
206
- end
207
-
208
- before_name = "before_#{name.to_s}".to_sym
209
- buffer = ActiveSupport::SafeBuffer.new
210
-
211
- if blocks[before_name].present?
212
- blocks[before_name].each do |block_container|
213
- args_clone = args.clone
214
- args_clone.push(global_options.merge(block_options).merge(block_container.options).merge(options))
215
- buffer << view.capture(*(args_clone[0, block_container.block.arity]), &block_container.block)
216
- end
217
- elsif BuildingBlocks::USE_PARTIALS && BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS
218
- begin
219
- begin
220
- buffer << view.render("before_#{name.to_s}", global_options.merge(block_options).merge(options))
221
- rescue ActionView::MissingTemplate
222
- buffer << view.render("#{self.templates_folder}/before_#{name.to_s}", global_options.merge(block_options).merge(options))
223
- end
224
- rescue ActionView::MissingTemplate
225
- end
226
- end
227
-
228
- buffer
257
+ render_before_or_after_blocks(name_or_container, "before", *args)
229
258
  end
230
259
 
231
260
  def render_after_blocks(name_or_container, *args)
261
+ render_before_or_after_blocks(name_or_container, "after", *args)
262
+ end
263
+
264
+ def render_before_or_after_blocks(name_or_container, before_or_after, *args)
232
265
  options = args.extract_options!
233
266
 
234
267
  block_options = {}
@@ -240,11 +273,11 @@ module BuildingBlocks
240
273
  block_options = blocks[name].options if blocks[name]
241
274
  end
242
275
 
243
- after_name = "after_#{name.to_s}".to_sym
276
+ before_name = "#{before_or_after}_#{name.to_s}".to_sym
244
277
  buffer = ActiveSupport::SafeBuffer.new
245
278
 
246
- if blocks[after_name].present?
247
- blocks[after_name].each do |block_container|
279
+ if blocks[before_name].present?
280
+ blocks[before_name].each do |block_container|
248
281
  args_clone = args.clone
249
282
  args_clone.push(global_options.merge(block_options).merge(block_container.options).merge(options))
250
283
  buffer << view.capture(*(args_clone[0, block_container.block.arity]), &block_container.block)
@@ -252,9 +285,9 @@ module BuildingBlocks
252
285
  elsif BuildingBlocks::USE_PARTIALS && BuildingBlocks::USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS
253
286
  begin
254
287
  begin
255
- buffer << view.render("after_#{name.to_s}", global_options.merge(block_options).merge(options))
288
+ buffer << view.render("#{before_or_after}_#{name.to_s}", global_options.merge(block_options).merge(options))
256
289
  rescue ActionView::MissingTemplate
257
- buffer << view.render("#{self.templates_folder}/after_#{name.to_s}", global_options.merge(block_options).merge(options))
290
+ buffer << view.render("#{self.templates_folder}/#{before_or_after}_#{name.to_s}", global_options.merge(block_options).merge(options))
258
291
  end
259
292
  rescue ActionView::MissingTemplate
260
293
  end
@@ -15,7 +15,7 @@ describe BuildingBlocks::Base do
15
15
  @view.expects(:capture).with(:value1 => 1, :value2 => 2).never
16
16
  @view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
17
17
  @view.expects(:render).with("shared/some_block", :value1 => 1, :value2 => 2).once
18
- @builder.use :some_block, :value1 => 1, :value2 => 2
18
+ @builder.render :some_block, :value1 => 1, :value2 => 2
19
19
  BuildingBlocks.send(:remove_const, "TEMPLATE_FOLDER")
20
20
  BuildingBlocks.const_set("TEMPLATE_FOLDER", "blocks")
21
21
  end
@@ -147,46 +147,40 @@ describe BuildingBlocks::Base do
147
147
  end
148
148
  end
149
149
 
150
- describe "render method" do
151
- it "should raise an exception if no :template parameter is specified in the options hash" do
152
- view = mock()
153
- builder = BuildingBlocks::Base.new(view)
154
- lambda { builder.render }.should raise_error("Must specify :template parameter in order to render")
155
- end
156
-
150
+ describe "render_template method" do
157
151
  it "should attempt to render a partial specified as the :template parameter" do
158
152
  view = mock()
159
- builder = BuildingBlocks::Base.new(view, :template => "my_template")
160
- view.expects(:render).with{ |template, options| template.should eql "my_template"}
161
- builder.render
153
+ builder = BuildingBlocks::Base.new(view)
154
+ view.expects(:render).with{ |template, options| template == "my_template"}
155
+ builder.render_template("my_template")
162
156
  end
163
157
 
164
158
  it "should set all of the global options as local variables to the partial it renders" do
165
159
  view = mock()
166
- builder = BuildingBlocks::Base.new(view, :template => "some_template")
167
- view.expects(:render).with { |template, options| options.should eql :template => 'some_template', :blocks => builder }
168
- builder.render
160
+ builder = BuildingBlocks::Base.new(view)
161
+ view.expects(:render).with { |template, options| template == 'some_template' && options[:blocks] == builder }
162
+ builder.render_template("some_template")
169
163
  end
170
164
 
171
165
  it "should capture the data of a block if a block has been specified" do
172
166
  block = Proc.new { |options| "my captured block" }
173
- builder = BuildingBlocks::Base.new(@view, :template => "template", &block)
174
- @view.expects(:render).with { |tempate, options| options[:captured_block].should eql("my captured block") }
175
- builder.render
167
+ builder = BuildingBlocks::Base.new(@view)
168
+ @view.expects(:render).with { |tempate, options| options[:captured_block] == "my captured block" }
169
+ builder.render_template("template", &block)
176
170
  end
177
171
 
178
172
  it "should by default add a variable to the partial called 'blocks' as a pointer to the BuildingBlocks::Base instance" do
179
173
  view = mock()
180
- builder = BuildingBlocks::Base.new(view, :template => "some_template")
181
- view.expects(:render).with { |template, options| options[:blocks].should eql(builder) }
182
- builder.render
174
+ builder = BuildingBlocks::Base.new(view)
175
+ view.expects(:render).with { |template, options| options[:blocks] == builder }
176
+ builder.render_template("some_template")
183
177
  end
184
178
 
185
179
  it "should allow the user to override the local variable passed to the partial as a pointer to the BuildingBlocks::Base instance" do
186
180
  view = mock()
187
- builder = BuildingBlocks::Base.new(view, :variable => "my_variable", :template => "some_template")
181
+ builder = BuildingBlocks::Base.new(view, :variable => "my_variable")
188
182
  view.expects(:render).with { |template, options| options[:blocks].should be_nil }
189
- builder.render
183
+ builder.render_template("some_template")
190
184
  end
191
185
  end
192
186
 
@@ -293,13 +287,13 @@ describe BuildingBlocks::Base do
293
287
  it "should be able to use a defined block by its name" do
294
288
  block = Proc.new {"output"}
295
289
  @builder.define :some_block, &block
296
- @builder.use(:some_block).should eql "output"
290
+ @builder.render(:some_block).should eql "output"
297
291
  end
298
292
 
299
293
  it "should automatically pass in an options hash to a defined block that takes one paramter when that block is used" do
300
294
  block = Proc.new {|options| "Options are #{options.inspect}"}
301
295
  @builder.define :some_block, &block
302
- @builder.use(:some_block).should eql "Options are {}"
296
+ @builder.render(:some_block).should eql "Options are {}"
303
297
  end
304
298
 
305
299
  it "should be able to use a defined block by its name and pass in runtime arguments as a hash" do
@@ -307,7 +301,7 @@ describe BuildingBlocks::Base do
307
301
  print_hash(options)
308
302
  end
309
303
  @builder.define :some_block, &block
310
- @builder.use(:some_block, :param1 => 1, :param2 => "value2").should eql print_hash(:param1 => 1, :param2 => "value2")
304
+ @builder.render(:some_block, :param1 => 1, :param2 => "value2").should eql print_hash(:param1 => 1, :param2 => "value2")
311
305
  end
312
306
 
313
307
  it "should be able to use a defined block by its name and pass in runtime arguments one by one" do
@@ -315,61 +309,61 @@ describe BuildingBlocks::Base do
315
309
  "first_param: #{first_param}, second_param: #{second_param}, #{print_hash options}"
316
310
  end
317
311
  @builder.define :some_block, &block
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")}")
312
+ @builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:param1 => 1, :param2 => "value2")}")
319
313
  end
320
314
 
321
315
  it "should match up the number of arguments to a defined block with the parameters passed when a block is used" do
322
316
  block = Proc.new {|first_param| "first_param = #{first_param}"}
323
317
  @builder.define :some_block, &block
324
- @builder.use(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql "first_param = 3"
318
+ @builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql "first_param = 3"
325
319
 
326
320
  block = Proc.new {|first_param, second_param| "first_param = #{first_param}, second_param = #{second_param}"}
327
321
  @builder.replace :some_block, &block
328
- @builder.use(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql "first_param = 3, second_param = 4"
322
+ @builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql "first_param = 3, second_param = 4"
329
323
 
330
324
  block = Proc.new do |first_param, second_param, options|
331
325
  "first_param: #{first_param}, second_param: #{second_param}, #{print_hash options}"
332
326
  end
333
327
  @builder.replace :some_block, &block
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")}")
328
+ @builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:param1 => 1, :param2 => "value2")}")
335
329
  end
336
330
 
337
331
  it "should not render anything if using a block that has been defined" do
338
332
  @view.expects(:capture).never
339
333
  @view.expects(:render).with("some_block", {}).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
340
334
  @view.expects(:render).with("blocks/some_block", {}).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
341
- @builder.use :some_block
335
+ @builder.render :some_block
342
336
  end
343
337
 
344
- it "should first attempt to capture a block's contents when blocks.use is called" do
338
+ it "should first attempt to capture a block's contents when blocks.render is called" do
345
339
  block = Proc.new {|options|}
346
340
  @view.expects(:capture).with(:value1 => 1, :value2 => 2)
347
341
  @view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).never
348
342
  @view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).never
349
343
  @builder.define :some_block, &block
350
- @builder.use :some_block, :value1 => 1, :value2 => 2
344
+ @builder.render :some_block, :value1 => 1, :value2 => 2
351
345
  end
352
346
 
353
- it "should second attempt to render a local partial by the block's name when blocks.use is called" do
347
+ it "should second attempt to render a local partial by the block's name when blocks.render is called" do
354
348
  @view.expects(:capture).with(:value1 => 1, :value2 => 2).never
355
349
  @view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).once
356
350
  @view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).never
357
- @builder.use :some_block, :value1 => 1, :value2 => 2
351
+ @builder.render :some_block, :value1 => 1, :value2 => 2
358
352
  end
359
353
 
360
- it "should third attempt to render a global partial by the block's name when blocks.use is called" do
354
+ it "should third attempt to render a global partial by the block's name when blocks.render is called" do
361
355
  @view.expects(:capture).with(:value1 => 1, :value2 => 2).never
362
356
  @view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
363
357
  @view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).once
364
- @builder.use :some_block, :value1 => 1, :value2 => 2
358
+ @builder.render :some_block, :value1 => 1, :value2 => 2
365
359
  end
366
360
 
367
- it "should fourth attempt to render a default block when blocks.use is called" do
361
+ it "should fourth attempt to render a default block when blocks.render is called" do
368
362
  block = Proc.new {|options|}
369
363
  @view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
370
364
  @view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
371
365
  @view.expects(:capture).with(:value1 => 1, :value2 => 2)
372
- @builder.use :some_block, :value1 => 1, :value2 => 2, &block
366
+ @builder.render :some_block, :value1 => 1, :value2 => 2, &block
373
367
  end
374
368
 
375
369
  it "should not attempt to render a partial if BuildingBlocks::USE_PARTIALS is set to false" do
@@ -379,7 +373,7 @@ describe BuildingBlocks::Base do
379
373
  @view.expects(:render).with("some_block", :value1 => 1, :value2 => 2).never
380
374
  @view.expects(:render).with("blocks/some_block", :value1 => 1, :value2 => 2).never
381
375
  @view.expects(:capture).with(:value1 => 1, :value2 => 2)
382
- @builder.use :some_block, :value1 => 1, :value2 => 2, &block
376
+ @builder.render :some_block, :value1 => 1, :value2 => 2, &block
383
377
  BuildingBlocks.send(:remove_const, "USE_PARTIALS")
384
378
  BuildingBlocks.const_set("USE_PARTIALS", true)
385
379
  end
@@ -391,14 +385,14 @@ describe BuildingBlocks::Base do
391
385
  @builder.define(:my_before_block, :param1 => "define level", :param2 => "define level", :param3 => "define level", &block)
392
386
  block_container = @builder.queued_blocks.first
393
387
  @view.expects(:capture).with(:param4 => 'global level', :param1 => 'use level', :param2 => 'queue level', :param3 => 'define level')
394
- @builder.use block_container, :param1 => "use level"
388
+ @builder.render block_container, :param1 => "use level"
395
389
  end
396
390
 
397
391
  it "should render the contents of a defined block when that block is used" do
398
392
  block = Proc.new {}
399
393
  @view.expects(:capture).with(nil).returns("rendered content")
400
394
  @builder.define :some_block, &block
401
- buffer = @builder.use :some_block
395
+ buffer = @builder.render :some_block
402
396
  buffer.should eql "rendered content"
403
397
  end
404
398
  end
@@ -413,7 +407,7 @@ describe BuildingBlocks::Base do
413
407
  block = Proc.new {|value1, value2, options|}
414
408
  @builder.before("my_before_block", &block)
415
409
  @view.expects(:capture).with(1, 2, :value3 => 3, :value4 => 4)
416
- @builder.use :my_before_block, 1, 2, :value3 => 3, :value4 => 4
410
+ @builder.render :my_before_block, 1, 2, :value3 => 3, :value4 => 4
417
411
  end
418
412
 
419
413
  it "should try and render a before block as a local partial if no before blocks are specified" do
@@ -421,7 +415,7 @@ describe BuildingBlocks::Base do
421
415
  @view.expects(:capture).never
422
416
  @view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).once
423
417
  @view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
424
- @builder.use :my_before_block, :value1 => 1, :value2 => 2
418
+ @builder.render :my_before_block, :value1 => 1, :value2 => 2
425
419
  end
426
420
 
427
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
@@ -429,7 +423,7 @@ describe BuildingBlocks::Base do
429
423
  @view.expects(:capture).never
430
424
  @view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
431
425
  @view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).once
432
- @builder.use :my_before_block, :value1 => 1, :value2 => 2
426
+ @builder.render :my_before_block, :value1 => 1, :value2 => 2
433
427
  end
434
428
 
435
429
  it "should not attempt to render a before block as a partial if BuildingBlocks::USE_PARTIALS is set to false" do
@@ -439,7 +433,7 @@ describe BuildingBlocks::Base do
439
433
  @view.expects(:capture).never
440
434
  @view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).never
441
435
  @view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
442
- @builder.use :my_before_block, :value1 => 1, :value2 => 2
436
+ @builder.render :my_before_block, :value1 => 1, :value2 => 2
443
437
  BuildingBlocks.send(:remove_const, "USE_PARTIALS")
444
438
  BuildingBlocks.const_set("USE_PARTIALS", true)
445
439
  end
@@ -451,7 +445,7 @@ describe BuildingBlocks::Base do
451
445
  @view.expects(:capture).never
452
446
  @view.expects(:render).with("before_my_before_block", :value1 => 1, :value2 => 2).never
453
447
  @view.expects(:render).with("blocks/before_my_before_block", :value1 => 1, :value2 => 2).never
454
- @builder.use :my_before_block, :value1 => 1, :value2 => 2
448
+ @builder.render :my_before_block, :value1 => 1, :value2 => 2
455
449
  BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
456
450
  BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
457
451
  end
@@ -462,7 +456,7 @@ describe BuildingBlocks::Base do
462
456
  @builder.define(:my_before_block, :param1 => "block level", :param2 => "block level", :param3 => "block level", &block)
463
457
  @builder.before(:my_before_block, :param1 => "before block level", :param2 => "before block level", &block)
464
458
  @view.expects(:capture).with(:param4 => 'global level', :param1 => 'top level', :param2 => 'before block level', :param3 => 'block level')
465
- @builder.use :my_before_block, :param1 => "top level"
459
+ @builder.render :my_before_block, :param1 => "top level"
466
460
  end
467
461
  end
468
462
 
@@ -476,7 +470,7 @@ describe BuildingBlocks::Base do
476
470
  block = Proc.new {|value1, value2, options|}
477
471
  @builder.after("my_after_block", &block)
478
472
  @view.expects(:capture).with(1, 2, :value3 => 3, :value4 => 4)
479
- @builder.use :my_after_block, 1, 2, :value3 => 3, :value4 => 4
473
+ @builder.render :my_after_block, 1, 2, :value3 => 3, :value4 => 4
480
474
  end
481
475
 
482
476
  it "should try and render a after block as a local partial if no after blocks are specified" do
@@ -484,7 +478,7 @@ describe BuildingBlocks::Base do
484
478
  @view.expects(:capture).never
485
479
  @view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).once
486
480
  @view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
487
- @builder.use :my_after_block, :value1 => 1, :value2 => 2
481
+ @builder.render :my_after_block, :value1 => 1, :value2 => 2
488
482
  end
489
483
 
490
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
@@ -492,7 +486,7 @@ describe BuildingBlocks::Base do
492
486
  @view.expects(:capture).never
493
487
  @view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
494
488
  @view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).once
495
- @builder.use :my_after_block, :value1 => 1, :value2 => 2
489
+ @builder.render :my_after_block, :value1 => 1, :value2 => 2
496
490
  end
497
491
 
498
492
  it "should not attempt to render a after block as a partial if BuildingBlocks::USE_PARTIALS is set to false" do
@@ -502,7 +496,7 @@ describe BuildingBlocks::Base do
502
496
  @view.expects(:capture).never
503
497
  @view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).never
504
498
  @view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
505
- @builder.use :my_after_block, :value1 => 1, :value2 => 2
499
+ @builder.render :my_after_block, :value1 => 1, :value2 => 2
506
500
  BuildingBlocks.send(:remove_const, "USE_PARTIALS")
507
501
  BuildingBlocks.const_set("USE_PARTIALS", true)
508
502
  end
@@ -514,7 +508,7 @@ describe BuildingBlocks::Base do
514
508
  @view.expects(:capture).never
515
509
  @view.expects(:render).with("after_my_after_block", :value1 => 1, :value2 => 2).never
516
510
  @view.expects(:render).with("blocks/after_my_after_block", :value1 => 1, :value2 => 2).never
517
- @builder.use :my_after_block, :value1 => 1, :value2 => 2
511
+ @builder.render :my_after_block, :value1 => 1, :value2 => 2
518
512
  BuildingBlocks.send(:remove_const, "USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS")
519
513
  BuildingBlocks.const_set("USE_PARTIALS_FOR_BEFORE_AND_AFTER_HOOKS", true)
520
514
  end
@@ -525,7 +519,7 @@ describe BuildingBlocks::Base do
525
519
  @builder.define(:my_after_block, :param1 => "block level", :param2 => "block level", :param3 => "block level", &block)
526
520
  @builder.after(:my_after_block, :param1 => "after block level", :param2 => "after block level", &block)
527
521
  @view.expects(:capture).with(:param4 => 'global level', :param1 => 'top level', :param2 => 'after block level', :param3 => 'block level')
528
- @builder.use :my_after_block, :param1 => "top level"
522
+ @builder.render :my_after_block, :param1 => "top level"
529
523
  end
530
524
  end
531
525
 
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: 19
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
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-04 00:00:00 -05:00
18
+ date: 2012-02-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -160,6 +160,48 @@ dependencies:
160
160
  prerelease: false
161
161
  type: :development
162
162
  requirement: *id010
163
+ - !ruby/object:Gem::Dependency
164
+ name: jeweler
165
+ version_requirements: &id011 !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ prerelease: false
175
+ type: :development
176
+ requirement: *id011
177
+ - !ruby/object:Gem::Dependency
178
+ name: jeweler
179
+ version_requirements: &id012 !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ hash: 3
185
+ segments:
186
+ - 0
187
+ version: "0"
188
+ prerelease: false
189
+ type: :development
190
+ requirement: *id012
191
+ - !ruby/object:Gem::Dependency
192
+ name: jeweler
193
+ version_requirements: &id013 !ruby/object:Gem::Requirement
194
+ none: false
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ hash: 3
199
+ segments:
200
+ - 0
201
+ version: "0"
202
+ prerelease: false
203
+ type: :development
204
+ requirement: *id013
163
205
  description: ""
164
206
  email: hunterae@gmail.com
165
207
  executables: []