building-blocks 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -1
- data/VERSION +1 -1
- data/lib/building_blocks/base.rb +11 -0
- data/spec/building-blocks/base_spec.rb +41 -0
- metadata +17 -3
data/CHANGELOG.rdoc
CHANGED
@@ -18,4 +18,8 @@
|
|
18
18
|
|
19
19
|
1.2.2 (February 9, 2012)
|
20
20
|
|
21
|
-
* Allow :use_partials and :use_partials_for_before_and_after_hooks to be passed in as initialization options to BuildingBlocks::Base to control whether BuildingBlocks attempts to render partials when "blocks.render" is called.
|
21
|
+
* Allow :use_partials and :use_partials_for_before_and_after_hooks to be passed in as initialization options to BuildingBlocks::Base to control whether BuildingBlocks attempts to render partials when "blocks.render" is called.
|
22
|
+
|
23
|
+
1.2.3 (February 9, 2012)
|
24
|
+
|
25
|
+
* Created two new utility methods: evaluated_procs and evaluated_proc that allow parameters for blocks to be Proc objects so long as these methods are called to evaluate them. (These methods have been carried over and renamed from the table-for gem where they were used to be able to dynamically specify table css classes, styles, and ids at runtime).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
data/lib/building_blocks/base.rb
CHANGED
@@ -284,6 +284,17 @@ module BuildingBlocks
|
|
284
284
|
end
|
285
285
|
alias append after
|
286
286
|
|
287
|
+
def evaluated_procs(*args)
|
288
|
+
options = args.extract_options!
|
289
|
+
options.inject({}) { |hash, (k, v)| hash[k] = (v.is_a?(Proc) ? v.call(*args) : v); hash} unless options.nil?
|
290
|
+
end
|
291
|
+
|
292
|
+
def evaluated_proc(*args)
|
293
|
+
return nil unless args.present?
|
294
|
+
v = args.pop
|
295
|
+
v.is_a?(Proc) ? v.call(*args) : v
|
296
|
+
end
|
297
|
+
|
287
298
|
protected
|
288
299
|
|
289
300
|
# If a method is missing, we'll assume the user is starting a new block group by that missing method name
|
@@ -549,4 +549,45 @@ describe BuildingBlocks::Base do
|
|
549
549
|
@builder.queued_blocks.should eql []
|
550
550
|
end
|
551
551
|
end
|
552
|
+
|
553
|
+
describe "evaluated_procs method" do
|
554
|
+
it "should evaluate any proc options" do
|
555
|
+
proc1 = lambda {@view.cycle("even", "odd")}
|
556
|
+
proc2 = lambda {@view.cycle("one", "two")}
|
557
|
+
evaluated_procs = @builder.evaluated_procs(:class => proc1, :id => proc2, :style => "color:red")
|
558
|
+
evaluated_procs[:class].should eql "even"
|
559
|
+
evaluated_procs[:id].should eql "one"
|
560
|
+
evaluated_procs[:style].should eql "color:red"
|
561
|
+
end
|
562
|
+
|
563
|
+
it "should pass any additional arguments to evaluated procs" do
|
564
|
+
proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
|
565
|
+
evaluated_procs = @builder.evaluated_procs(1, 2, :class => proc1)
|
566
|
+
evaluated_procs[:class].should eql "user_1_2"
|
567
|
+
end
|
568
|
+
|
569
|
+
describe "evaluated_proc method" do
|
570
|
+
it "should evaluate a proc" do
|
571
|
+
proc = lambda {@view.cycle("even", "odd")}
|
572
|
+
@builder.evaluated_proc(proc).should eql "even"
|
573
|
+
end
|
574
|
+
|
575
|
+
it "should just return the value if it is not a proc" do
|
576
|
+
@builder.evaluated_proc("1234").should eql "1234"
|
577
|
+
end
|
578
|
+
|
579
|
+
it "should return nil if no arguments are specified" do
|
580
|
+
@builder.evaluated_proc.should be_nil
|
581
|
+
end
|
582
|
+
|
583
|
+
it "should treat the last argument as the potential proc to evaluate" do
|
584
|
+
@builder.evaluated_proc(1, 2, 3).should eql 3
|
585
|
+
end
|
586
|
+
|
587
|
+
it "should pass any additional arguments to the evaluated proc" do
|
588
|
+
proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
|
589
|
+
@builder.evaluated_proc(1, 2, proc1).should eql "user_1_2"
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
552
593
|
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: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 3
|
10
|
+
version: 1.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Hunter
|
@@ -230,6 +230,20 @@ dependencies:
|
|
230
230
|
prerelease: false
|
231
231
|
type: :development
|
232
232
|
requirement: *id015
|
233
|
+
- !ruby/object:Gem::Dependency
|
234
|
+
name: jeweler
|
235
|
+
version_requirements: &id016 !ruby/object:Gem::Requirement
|
236
|
+
none: false
|
237
|
+
requirements:
|
238
|
+
- - ">="
|
239
|
+
- !ruby/object:Gem::Version
|
240
|
+
hash: 3
|
241
|
+
segments:
|
242
|
+
- 0
|
243
|
+
version: "0"
|
244
|
+
prerelease: false
|
245
|
+
type: :development
|
246
|
+
requirement: *id016
|
233
247
|
description: ""
|
234
248
|
email: hunterae@gmail.com
|
235
249
|
executables: []
|