blocks 2.1.0 → 2.2.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/.rspec +2 -0
- data/CHANGELOG.rdoc +4 -0
- data/Gemfile +16 -0
- data/Rakefile +37 -14
- data/VERSION +1 -1
- data/blocks.gemspec +89 -0
- data/blocks_render_order.graffle +1397 -0
- data/blocks_render_order.png +0 -0
- data/lib/blocks.rb +1 -0
- data/lib/blocks/base.rb +3 -18
- data/lib/blocks/proc_with_args.rb +18 -0
- data/lib/blocks/view_additions.rb +8 -0
- data/spec/blocks/base_spec.rb +0 -43
- data/spec/blocks/proc_with_args_spec.rb +50 -0
- metadata +56 -135
Binary file
|
data/lib/blocks.rb
CHANGED
@@ -4,6 +4,7 @@ require "action_controller"
|
|
4
4
|
module Blocks
|
5
5
|
autoload :Base, "blocks/base"
|
6
6
|
autoload :Container, "blocks/container"
|
7
|
+
autoload :ProcWithArgs, "blocks/proc_with_args"
|
7
8
|
autoload :ViewAdditions, "blocks/view_additions"
|
8
9
|
autoload :ControllerAdditions, "blocks/controller_additions"
|
9
10
|
|
data/lib/blocks/base.rb
CHANGED
@@ -57,7 +57,7 @@ module Blocks
|
|
57
57
|
|
58
58
|
if collection
|
59
59
|
collection.each do |object|
|
60
|
-
define(
|
60
|
+
define(view.call_if_proc(name, object, options), options, &block)
|
61
61
|
end
|
62
62
|
else
|
63
63
|
self.define_block_container(name, options, &block)
|
@@ -155,7 +155,7 @@ module Blocks
|
|
155
155
|
cloned_options = cloned_options.merge(object.options) if object.is_a?(Blocks::Container)
|
156
156
|
cloned_args.push(cloned_options)
|
157
157
|
|
158
|
-
block_name =
|
158
|
+
block_name = view.call_if_proc(name_or_container, *cloned_args)
|
159
159
|
as_name = (as.presence || block_name).to_sym
|
160
160
|
cloned_options[as_name] = object
|
161
161
|
|
@@ -484,21 +484,6 @@ module Blocks
|
|
484
484
|
nil
|
485
485
|
end
|
486
486
|
|
487
|
-
def evaluated_procs(*args)
|
488
|
-
options = args.shift.presence || {}
|
489
|
-
if options.is_a?(Proc)
|
490
|
-
evaluated_proc(options, *args)
|
491
|
-
else
|
492
|
-
options.inject({}) { |hash, (k, v)| hash[k] = evaluated_proc(v, *args); hash}
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
def evaluated_proc(*args)
|
497
|
-
return nil unless args.present?
|
498
|
-
v = args.shift
|
499
|
-
v.is_a?(Proc) ? v.call(*(args[0, v.arity])) : v
|
500
|
-
end
|
501
|
-
|
502
487
|
protected
|
503
488
|
|
504
489
|
# If a method is missing, we'll assume the user is starting a new block group by that missing method name
|
@@ -663,7 +648,7 @@ module Blocks
|
|
663
648
|
|
664
649
|
def content_tag(tag, tag_html, *args, &block)
|
665
650
|
if tag
|
666
|
-
view.content_tag(tag, block.call,
|
651
|
+
view.content_tag(tag, block.call, view.call_each_hash_value_if_proc(tag_html, *args))
|
667
652
|
else
|
668
653
|
block.call
|
669
654
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Blocks
|
2
|
+
class ProcWithArgs
|
3
|
+
def self.call(*args)
|
4
|
+
return nil unless args.present?
|
5
|
+
v = args.shift
|
6
|
+
v.is_a?(Proc) ? v.call(*(args[0, v.arity])) : v
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.call_each_hash_value(*args)
|
10
|
+
options = args.shift.presence || {}
|
11
|
+
if options.is_a?(Proc)
|
12
|
+
call(options, *args)
|
13
|
+
else
|
14
|
+
options.inject({}) { |hash, (k, v)| hash[k] = call(v, *args); hash}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -7,6 +7,14 @@ module Blocks
|
|
7
7
|
@blocks.blocks.merge! @controller_blocks.blocks if @controller_blocks
|
8
8
|
@blocks
|
9
9
|
end
|
10
|
+
|
11
|
+
def call_if_proc(*args)
|
12
|
+
Blocks::ProcWithArgs.call(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def call_each_hash_value_if_proc(*args)
|
16
|
+
Blocks::ProcWithArgs.call_each_hash_value(*args)
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
data/spec/blocks/base_spec.rb
CHANGED
@@ -613,47 +613,4 @@ describe Blocks::Base do
|
|
613
613
|
@builder.queued_blocks.should eql []
|
614
614
|
end
|
615
615
|
end
|
616
|
-
|
617
|
-
describe "evaluated_procs method" do
|
618
|
-
it "should evaluate any proc options" do
|
619
|
-
proc1 = lambda {@view.cycle("even", "odd")}
|
620
|
-
proc2 = lambda {@view.cycle("one", "two")}
|
621
|
-
evaluated_procs = @builder.evaluated_procs(:class => proc1, :id => proc2, :style => "color:red")
|
622
|
-
evaluated_procs[:class].should eql "even"
|
623
|
-
evaluated_procs[:id].should eql "one"
|
624
|
-
evaluated_procs[:style].should eql "color:red"
|
625
|
-
end
|
626
|
-
|
627
|
-
it "should pass any additional arguments to evaluated procs" do
|
628
|
-
proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
|
629
|
-
evaluated_procs = @builder.evaluated_procs({:class => proc1}, 1, 2)
|
630
|
-
evaluated_procs[:class].should eql "user_1_2"
|
631
|
-
end
|
632
|
-
end
|
633
|
-
|
634
|
-
describe "evaluated_proc method" do
|
635
|
-
it "should evaluate a proc" do
|
636
|
-
proc = lambda {@view.cycle("even", "odd")}
|
637
|
-
@builder.evaluated_proc(proc).should eql "even"
|
638
|
-
@builder.evaluated_proc(proc).should eql "odd"
|
639
|
-
@builder.evaluated_proc(proc).should eql "even"
|
640
|
-
end
|
641
|
-
|
642
|
-
it "should just return the value if it is not a proc" do
|
643
|
-
@builder.evaluated_proc("1234").should eql "1234"
|
644
|
-
end
|
645
|
-
|
646
|
-
it "should return nil if no arguments are specified" do
|
647
|
-
@builder.evaluated_proc.should be_nil
|
648
|
-
end
|
649
|
-
|
650
|
-
it "should treat the first argument as the potential proc to evaluate" do
|
651
|
-
@builder.evaluated_proc(1, 2, 3).should eql 1
|
652
|
-
end
|
653
|
-
|
654
|
-
it "should pass any additional arguments to the evaluated proc" do
|
655
|
-
proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
|
656
|
-
@builder.evaluated_proc(proc1, 1, 2).should eql "user_1_2"
|
657
|
-
end
|
658
|
-
end
|
659
616
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Blocks::ProcWithArgs do
|
4
|
+
before :each do
|
5
|
+
@view = ActionView::Base.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "call_each_hash_value method" do
|
9
|
+
it "should evaluate any proc options" do
|
10
|
+
proc1 = lambda {@view.cycle("even", "odd")}
|
11
|
+
proc2 = lambda {@view.cycle("one", "two")}
|
12
|
+
evaluated_procs = Blocks::ProcWithArgs.call_each_hash_value(:class => proc1, :id => proc2, :style => "color:red")
|
13
|
+
evaluated_procs[:class].should eql "even"
|
14
|
+
evaluated_procs[:id].should eql "one"
|
15
|
+
evaluated_procs[:style].should eql "color:red"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should pass any additional arguments to evaluated procs" do
|
19
|
+
proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
|
20
|
+
evaluated_procs = Blocks::ProcWithArgs.call_each_hash_value({:class => proc1}, 1, 2)
|
21
|
+
evaluated_procs[:class].should eql "user_1_2"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "call method" do
|
26
|
+
it "should evaluate a proc" do
|
27
|
+
proc = lambda {@view.cycle("even", "odd")}
|
28
|
+
Blocks::ProcWithArgs.call(proc).should eql "even"
|
29
|
+
Blocks::ProcWithArgs.call(proc).should eql "odd"
|
30
|
+
Blocks::ProcWithArgs.call(proc).should eql "even"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should just return the value if it is not a proc" do
|
34
|
+
Blocks::ProcWithArgs.call("1234").should eql "1234"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return nil if no arguments are specified" do
|
38
|
+
Blocks::ProcWithArgs.call.should be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should treat the first argument as the potential proc to evaluate" do
|
42
|
+
Blocks::ProcWithArgs.call(1, 2, 3).should eql 1
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should pass any additional arguments to the evaluated proc" do
|
46
|
+
proc1 = lambda { |param1, param2| "user_#{param1}_#{param2}"}
|
47
|
+
Blocks::ProcWithArgs.call(proc1, 1, 2).should eql "user_1_2"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 2.
|
10
|
+
version: 2.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: 2013-08-
|
18
|
+
date: 2013-08-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -51,26 +51,30 @@ dependencies:
|
|
51
51
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ~>
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
hash:
|
56
|
+
hash: 25
|
57
57
|
segments:
|
58
|
-
-
|
59
|
-
|
58
|
+
- 1
|
59
|
+
- 1
|
60
|
+
- 5
|
61
|
+
version: 1.1.5
|
60
62
|
requirement: *id003
|
61
63
|
prerelease: false
|
62
|
-
name:
|
64
|
+
name: bundler
|
63
65
|
type: :development
|
64
66
|
- !ruby/object:Gem::Dependency
|
65
67
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
68
|
none: false
|
67
69
|
requirements:
|
68
|
-
- -
|
70
|
+
- - ~>
|
69
71
|
- !ruby/object:Gem::Version
|
70
|
-
hash:
|
72
|
+
hash: 7
|
71
73
|
segments:
|
72
|
-
-
|
73
|
-
|
74
|
+
- 1
|
75
|
+
- 6
|
76
|
+
- 4
|
77
|
+
version: 1.6.4
|
74
78
|
requirement: *id004
|
75
79
|
prerelease: false
|
76
80
|
name: jeweler
|
@@ -87,32 +91,36 @@ dependencies:
|
|
87
91
|
version: "0"
|
88
92
|
requirement: *id005
|
89
93
|
prerelease: false
|
90
|
-
name:
|
94
|
+
name: rcov
|
91
95
|
type: :development
|
92
96
|
- !ruby/object:Gem::Dependency
|
93
97
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
94
98
|
none: false
|
95
99
|
requirements:
|
96
|
-
- -
|
100
|
+
- - ~>
|
97
101
|
- !ruby/object:Gem::Version
|
98
|
-
hash:
|
102
|
+
hash: 25
|
99
103
|
segments:
|
100
|
-
-
|
101
|
-
|
104
|
+
- 1
|
105
|
+
- 1
|
106
|
+
- 5
|
107
|
+
version: 1.1.5
|
102
108
|
requirement: *id006
|
103
109
|
prerelease: false
|
104
|
-
name:
|
110
|
+
name: bundler
|
105
111
|
type: :development
|
106
112
|
- !ruby/object:Gem::Dependency
|
107
113
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
108
114
|
none: false
|
109
115
|
requirements:
|
110
|
-
- -
|
116
|
+
- - ~>
|
111
117
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
118
|
+
hash: 7
|
113
119
|
segments:
|
114
|
-
-
|
115
|
-
|
120
|
+
- 1
|
121
|
+
- 6
|
122
|
+
- 4
|
123
|
+
version: 1.6.4
|
116
124
|
requirement: *id007
|
117
125
|
prerelease: false
|
118
126
|
name: jeweler
|
@@ -129,32 +137,36 @@ dependencies:
|
|
129
137
|
version: "0"
|
130
138
|
requirement: *id008
|
131
139
|
prerelease: false
|
132
|
-
name:
|
140
|
+
name: rcov
|
133
141
|
type: :development
|
134
142
|
- !ruby/object:Gem::Dependency
|
135
143
|
version_requirements: &id009 !ruby/object:Gem::Requirement
|
136
144
|
none: false
|
137
145
|
requirements:
|
138
|
-
- -
|
146
|
+
- - ~>
|
139
147
|
- !ruby/object:Gem::Version
|
140
|
-
hash:
|
148
|
+
hash: 25
|
141
149
|
segments:
|
142
|
-
-
|
143
|
-
|
150
|
+
- 1
|
151
|
+
- 1
|
152
|
+
- 5
|
153
|
+
version: 1.1.5
|
144
154
|
requirement: *id009
|
145
155
|
prerelease: false
|
146
|
-
name:
|
156
|
+
name: bundler
|
147
157
|
type: :development
|
148
158
|
- !ruby/object:Gem::Dependency
|
149
159
|
version_requirements: &id010 !ruby/object:Gem::Requirement
|
150
160
|
none: false
|
151
161
|
requirements:
|
152
|
-
- -
|
162
|
+
- - ~>
|
153
163
|
- !ruby/object:Gem::Version
|
154
|
-
hash:
|
164
|
+
hash: 7
|
155
165
|
segments:
|
156
|
-
-
|
157
|
-
|
166
|
+
- 1
|
167
|
+
- 6
|
168
|
+
- 4
|
169
|
+
version: 1.6.4
|
158
170
|
requirement: *id010
|
159
171
|
prerelease: false
|
160
172
|
name: jeweler
|
@@ -171,105 +183,7 @@ dependencies:
|
|
171
183
|
version: "0"
|
172
184
|
requirement: *id011
|
173
185
|
prerelease: false
|
174
|
-
name:
|
175
|
-
type: :development
|
176
|
-
- !ruby/object:Gem::Dependency
|
177
|
-
version_requirements: &id012 !ruby/object:Gem::Requirement
|
178
|
-
none: false
|
179
|
-
requirements:
|
180
|
-
- - ">="
|
181
|
-
- !ruby/object:Gem::Version
|
182
|
-
hash: 3
|
183
|
-
segments:
|
184
|
-
- 0
|
185
|
-
version: "0"
|
186
|
-
requirement: *id012
|
187
|
-
prerelease: false
|
188
|
-
name: jeweler
|
189
|
-
type: :development
|
190
|
-
- !ruby/object:Gem::Dependency
|
191
|
-
version_requirements: &id013 !ruby/object:Gem::Requirement
|
192
|
-
none: false
|
193
|
-
requirements:
|
194
|
-
- - ">="
|
195
|
-
- !ruby/object:Gem::Version
|
196
|
-
hash: 3
|
197
|
-
segments:
|
198
|
-
- 0
|
199
|
-
version: "0"
|
200
|
-
requirement: *id013
|
201
|
-
prerelease: false
|
202
|
-
name: jeweler
|
203
|
-
type: :development
|
204
|
-
- !ruby/object:Gem::Dependency
|
205
|
-
version_requirements: &id014 !ruby/object:Gem::Requirement
|
206
|
-
none: false
|
207
|
-
requirements:
|
208
|
-
- - ">="
|
209
|
-
- !ruby/object:Gem::Version
|
210
|
-
hash: 3
|
211
|
-
segments:
|
212
|
-
- 0
|
213
|
-
version: "0"
|
214
|
-
requirement: *id014
|
215
|
-
prerelease: false
|
216
|
-
name: jeweler
|
217
|
-
type: :development
|
218
|
-
- !ruby/object:Gem::Dependency
|
219
|
-
version_requirements: &id015 !ruby/object:Gem::Requirement
|
220
|
-
none: false
|
221
|
-
requirements:
|
222
|
-
- - ">="
|
223
|
-
- !ruby/object:Gem::Version
|
224
|
-
hash: 3
|
225
|
-
segments:
|
226
|
-
- 0
|
227
|
-
version: "0"
|
228
|
-
requirement: *id015
|
229
|
-
prerelease: false
|
230
|
-
name: jeweler
|
231
|
-
type: :development
|
232
|
-
- !ruby/object:Gem::Dependency
|
233
|
-
version_requirements: &id016 !ruby/object:Gem::Requirement
|
234
|
-
none: false
|
235
|
-
requirements:
|
236
|
-
- - ">="
|
237
|
-
- !ruby/object:Gem::Version
|
238
|
-
hash: 3
|
239
|
-
segments:
|
240
|
-
- 0
|
241
|
-
version: "0"
|
242
|
-
requirement: *id016
|
243
|
-
prerelease: false
|
244
|
-
name: jeweler
|
245
|
-
type: :development
|
246
|
-
- !ruby/object:Gem::Dependency
|
247
|
-
version_requirements: &id017 !ruby/object:Gem::Requirement
|
248
|
-
none: false
|
249
|
-
requirements:
|
250
|
-
- - ">="
|
251
|
-
- !ruby/object:Gem::Version
|
252
|
-
hash: 3
|
253
|
-
segments:
|
254
|
-
- 0
|
255
|
-
version: "0"
|
256
|
-
requirement: *id017
|
257
|
-
prerelease: false
|
258
|
-
name: jeweler
|
259
|
-
type: :development
|
260
|
-
- !ruby/object:Gem::Dependency
|
261
|
-
version_requirements: &id018 !ruby/object:Gem::Requirement
|
262
|
-
none: false
|
263
|
-
requirements:
|
264
|
-
- - ">="
|
265
|
-
- !ruby/object:Gem::Version
|
266
|
-
hash: 3
|
267
|
-
segments:
|
268
|
-
- 0
|
269
|
-
version: "0"
|
270
|
-
requirement: *id018
|
271
|
-
prerelease: false
|
272
|
-
name: jeweler
|
186
|
+
name: rcov
|
273
187
|
type: :development
|
274
188
|
description: Blocks goes beyond blocks and partials
|
275
189
|
email: hunterae@gmail.com
|
@@ -280,23 +194,30 @@ extensions: []
|
|
280
194
|
extra_rdoc_files:
|
281
195
|
- README.rdoc
|
282
196
|
files:
|
197
|
+
- .rspec
|
283
198
|
- CHANGELOG.rdoc
|
199
|
+
- Gemfile
|
284
200
|
- README.rdoc
|
285
201
|
- Rakefile
|
286
202
|
- VERSION
|
203
|
+
- blocks.gemspec
|
204
|
+
- blocks_render_order.graffle
|
205
|
+
- blocks_render_order.png
|
287
206
|
- lib/blocks.rb
|
288
207
|
- lib/blocks/base.rb
|
289
208
|
- lib/blocks/container.rb
|
290
209
|
- lib/blocks/controller_additions.rb
|
210
|
+
- lib/blocks/proc_with_args.rb
|
291
211
|
- lib/blocks/view_additions.rb
|
292
212
|
- rails/init.rb
|
293
213
|
- spec/blocks/base_spec.rb
|
294
214
|
- spec/blocks/blocks_spec.rb
|
215
|
+
- spec/blocks/proc_with_args_spec.rb
|
295
216
|
- spec/blocks/view_additions_spec.rb
|
296
217
|
- spec/spec_helper.rb
|
297
218
|
homepage: http://github.com/hunterae/blocks
|
298
|
-
licenses:
|
299
|
-
|
219
|
+
licenses:
|
220
|
+
- MIT
|
300
221
|
post_install_message:
|
301
222
|
rdoc_options: []
|
302
223
|
|
@@ -326,6 +247,6 @@ rubyforge_project:
|
|
326
247
|
rubygems_version: 1.8.24
|
327
248
|
signing_key:
|
328
249
|
specification_version: 3
|
329
|
-
summary: Blocks is an intricate way of rendering blocks of code
|
250
|
+
summary: Blocks is an intricate way of rendering blocks of code and adding several new features that go above and beyond what a simple content_for with yield is capable of doing.
|
330
251
|
test_files: []
|
331
252
|
|