blocks 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.rdoc +8 -0
- data/lib/blocks/base.rb +2 -1
- data/lib/blocks/version.rb +1 -1
- data/spec/blocks/base_spec.rb +24 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzIxNTRkM2MxYWIwMjZmYWNiZmU5MWFmMGNkODU4ZDIyM2RmNmE2Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmRhYjAwZmFlNGE3YTQ2MGYxNWNmMzEwOGU3NDFkNWJhNGFlNDNiZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDc0ODgzNDM4Njg0YTY3NDM0NWQ1YmQyMGQwNGM1ZGVhZTM0YjFlNmUyZmE4
|
10
|
+
ZDQwMjg0NzE4NzljMmVjZDE0MTc3YTkyODk3Nzk1NjkxOGNjNmZhNGRhMjI2
|
11
|
+
MjI4NGUwNmU2MjQ1MDE3MjFmMGI2MDZjMTI4MzE4NTliNjhmNjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTdlYmUwMjRhMTcwMzdmZGY5NDkyMjE4YjY5MTlhNWYxZDg0NDUxMjJiMjky
|
14
|
+
NWFiOTNlMDA0OGIwZDZiNDMxMmNiNjc2MDgwMDdjMGIyNDg3ZTZkMDI4OTJi
|
15
|
+
Yjg3YTc4ODA5ODI3MTFiMDA0MWJhMzRlMDBmNDRjZGVlZDdlNjA=
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
2.8.0 (January 21, 2016)
|
2
|
+
* When rendering a collection of blocks through blocks.render BLOCK_NAME, collection: COLLECTION,
|
3
|
+
current_index will now be passed as a param for the options hash passed to the block. Example:
|
4
|
+
<% blocks.define :my_block do |object, options| %>
|
5
|
+
Item <%= options[:current_index] + 1 %>: <%= object %>
|
6
|
+
<% end %>
|
7
|
+
<%= blocks.render :my_block, collection: ["a", "b", "c"] %>
|
8
|
+
|
1
9
|
2.7.0 (December 9, 2015)
|
2
10
|
* Added configuration option skip_applies_to_surrounding_blocks. When set to true, if blocks.skip :SOME_BLOCK is called,
|
3
11
|
any before, after, and around hooks applied to that block will also be skipped when the block attempts to render.
|
data/lib/blocks/base.rb
CHANGED
@@ -165,10 +165,11 @@ module Blocks
|
|
165
165
|
wrap_each = options.delete(:wrap_each) || {}
|
166
166
|
|
167
167
|
buffer = content_tag_with_block(wrap_with[:tag], wrap_with.except(:tag), *args) do
|
168
|
-
collection.
|
168
|
+
collection.each_with_index do |object, index|
|
169
169
|
cloned_args = args.clone
|
170
170
|
cloned_args.unshift(object)
|
171
171
|
cloned_options = options.clone
|
172
|
+
cloned_options[:current_index] = index
|
172
173
|
cloned_options = cloned_options.merge(object.options) if object.is_a?(Blocks::Container)
|
173
174
|
cloned_args.push(cloned_options)
|
174
175
|
|
data/lib/blocks/version.rb
CHANGED
data/spec/blocks/base_spec.rb
CHANGED
@@ -15,8 +15,8 @@ describe Blocks::Base do
|
|
15
15
|
@builder.expects(:render_before_blocks).at_least_once
|
16
16
|
@builder.expects(:render_after_blocks).at_least_once
|
17
17
|
# @view.expects(:capture).with(:value1 => 1, :value2 => 2).never
|
18
|
-
@view.expects(:render).with("some_block", 'partials_folder' => 'shared', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
19
|
-
@view.expects(:render).with("shared/some_block", 'partials_folder' => 'shared', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
18
|
+
@view.expects(:render).with("some_block", 'partials_folder' => 'shared', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
19
|
+
@view.expects(:render).with("shared/some_block", 'partials_folder' => 'shared', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).once
|
20
20
|
@builder.render :some_block, :value1 => 1, :value2 => 2
|
21
21
|
end
|
22
22
|
|
@@ -299,7 +299,7 @@ describe Blocks::Base do
|
|
299
299
|
it "should automatically pass in an options hash to a defined block that takes one paramter when that block is rendered" do
|
300
300
|
block = Proc.new {|options| print_hash(options) }
|
301
301
|
@builder.define :some_block, &block
|
302
|
-
@builder.render(:some_block).should eql print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks =>
|
302
|
+
@builder.render(:some_block).should eql print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks => false)
|
303
303
|
end
|
304
304
|
|
305
305
|
it "should be able to render a defined block by its name and pass in runtime arguments as a hash" do
|
@@ -307,7 +307,7 @@ describe Blocks::Base do
|
|
307
307
|
print_hash(options)
|
308
308
|
end
|
309
309
|
@builder.define :some_block, &block
|
310
|
-
@builder.render(:some_block, :param1 => 1, :param2 => "value2").should eql print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks =>
|
310
|
+
@builder.render(:some_block, :param1 => 1, :param2 => "value2").should eql print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks => false, :param1 => 1, :param2 => "value2")
|
311
311
|
end
|
312
312
|
|
313
313
|
it "should be able to render a defined block by its name and pass in runtime arguments one by one" do
|
@@ -315,7 +315,7 @@ describe Blocks::Base do
|
|
315
315
|
"first_param: #{first_param}, second_param: #{second_param}, #{print_hash options}"
|
316
316
|
end
|
317
317
|
@builder.define :some_block, &block
|
318
|
-
@builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks =>
|
318
|
+
@builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks => false, :param1 => 1, :param2 => "value2")}")
|
319
319
|
end
|
320
320
|
|
321
321
|
it "should match up the number of arguments to a defined block with the parameters passed when a block is rendered" do
|
@@ -331,7 +331,7 @@ describe Blocks::Base do
|
|
331
331
|
"first_param: #{first_param}, second_param: #{second_param}, #{print_hash options}"
|
332
332
|
end
|
333
333
|
@builder.replace :some_block, &block
|
334
|
-
@builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks =>
|
334
|
+
@builder.render(:some_block, 3, 4, :param1 => 1, :param2 => "value2").should eql("first_param: 3, second_param: 4, #{print_hash(:wrap_before_and_after_blocks => false, :use_partials => false, :partials_folder => "blocks", :skip_applies_to_surrounding_blocks => false, :param1 => 1, :param2 => "value2")}")
|
335
335
|
end
|
336
336
|
|
337
337
|
it "should not render anything if using a block that has been defined" do
|
@@ -339,8 +339,8 @@ describe Blocks::Base do
|
|
339
339
|
config.use_partials = true
|
340
340
|
end
|
341
341
|
@builder = Blocks::Base.new(@view)
|
342
|
-
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
343
|
-
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
342
|
+
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
343
|
+
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
344
344
|
@builder.render :some_block
|
345
345
|
end
|
346
346
|
|
@@ -357,8 +357,8 @@ describe Blocks::Base do
|
|
357
357
|
config.use_partials = true
|
358
358
|
end
|
359
359
|
@builder = Blocks::Base.new(@view)
|
360
|
-
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
361
|
-
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
360
|
+
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).once
|
361
|
+
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).never
|
362
362
|
@builder.render :some_block, :value1 => 1, :value2 => 2
|
363
363
|
end
|
364
364
|
|
@@ -367,8 +367,8 @@ describe Blocks::Base do
|
|
367
367
|
config.use_partials = true
|
368
368
|
end
|
369
369
|
@builder = Blocks::Base.new(@view)
|
370
|
-
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
371
|
-
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
370
|
+
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
371
|
+
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).once
|
372
372
|
@builder.render :some_block, :value1 => 1, :value2 => 2
|
373
373
|
end
|
374
374
|
|
@@ -381,8 +381,8 @@ describe Blocks::Base do
|
|
381
381
|
config.use_partials = true
|
382
382
|
end
|
383
383
|
@builder = Blocks::Base.new(@view)
|
384
|
-
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
385
|
-
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' =>
|
384
|
+
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
385
|
+
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => true, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).raises(ActionView::MissingTemplate.new([],[],[],[],[]))
|
386
386
|
@builder.render :some_block, :value1 => 1, :value2 => 2, &block
|
387
387
|
end
|
388
388
|
|
@@ -391,8 +391,8 @@ describe Blocks::Base do
|
|
391
391
|
options[:value1].should eql 1
|
392
392
|
options[:value2].should eql 2
|
393
393
|
end
|
394
|
-
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' =>
|
395
|
-
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' =>
|
394
|
+
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).never
|
395
|
+
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).never
|
396
396
|
@builder.render :some_block, :value1 => 1, :value2 => 2, &block
|
397
397
|
end
|
398
398
|
|
@@ -405,8 +405,8 @@ describe Blocks::Base do
|
|
405
405
|
options[:value1].should eql 1
|
406
406
|
options[:value2].should eql 2
|
407
407
|
end
|
408
|
-
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' =>
|
409
|
-
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' =>
|
408
|
+
@view.expects(:render).with("some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).never
|
409
|
+
@view.expects(:render).with("blocks/some_block", 'partials_folder' => 'blocks', 'wrap_before_and_after_blocks' => false, 'use_partials' => false, 'skip_applies_to_surrounding_blocks' => false, 'value1' => 1, 'value2' => 2).never
|
410
410
|
@builder.render :some_block, :value1 => 1, :value2 => 2, &block
|
411
411
|
end
|
412
412
|
|
@@ -446,6 +446,12 @@ describe Blocks::Base do
|
|
446
446
|
@builder.render(:some_block, :collection => [1,2,3]).should eql "output1 output2 output3 "
|
447
447
|
end
|
448
448
|
|
449
|
+
it "should track the current index and pass as an option to the block" do
|
450
|
+
block = Proc.new {|item, options| "Item #{options[:current_index] + 1}: #{item} "}
|
451
|
+
@builder.define :some_block, &block
|
452
|
+
@builder.render(:some_block, :collection => ["a", "b", "c"]).should eql "Item 1: a Item 2: b Item 3: c "
|
453
|
+
end
|
454
|
+
|
449
455
|
it "should render a block for each element of the collection with the 'as' option specifying the name of the element passed into the block" do
|
450
456
|
block = Proc.new {|item, options| "output#{options[:my_block_name]} "}
|
451
457
|
@builder.define :some_block, &block
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Hunter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|