tadpole 0.1.4 → 0.1.5
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/lib/tadpole/filters.rb +12 -5
- data/lib/tadpole.rb +1 -1
- data/spec/filters_spec.rb +40 -0
- metadata +2 -2
data/lib/tadpole/filters.rb
CHANGED
@@ -29,8 +29,7 @@ module Tadpole
|
|
29
29
|
module InstanceMethods
|
30
30
|
def run_before_run
|
31
31
|
self.class.before_run_filters.each do |meth|
|
32
|
-
|
33
|
-
result = meth.call
|
32
|
+
result = call_before_method(meth, false)
|
34
33
|
return result if result.is_a?(FalseClass)
|
35
34
|
end
|
36
35
|
end
|
@@ -39,14 +38,22 @@ module Tadpole
|
|
39
38
|
self.class.before_section_filters.each do |info|
|
40
39
|
result, sec, meth = nil, *info
|
41
40
|
if sec.nil? || sec.to_s == current_section.to_s
|
42
|
-
|
43
|
-
args = meth.arity == 0 ? [] : [current_section]
|
44
|
-
result = meth.call(*args)
|
41
|
+
result = call_before_method(meth)
|
45
42
|
end
|
46
43
|
|
47
44
|
return result if result.is_a?(FalseClass)
|
48
45
|
end
|
49
46
|
end
|
47
|
+
|
48
|
+
def call_before_method(meth, pass_args = true)
|
49
|
+
if meth.is_a?(Symbol)
|
50
|
+
meth = method(meth)
|
51
|
+
args = meth.arity == 0 ? [] : [current_section]
|
52
|
+
meth.call(*args)
|
53
|
+
else
|
54
|
+
instance_eval(&meth)
|
55
|
+
end
|
56
|
+
end
|
50
57
|
end
|
51
58
|
end
|
52
59
|
end
|
data/lib/tadpole.rb
CHANGED
data/spec/filters_spec.rb
CHANGED
@@ -28,6 +28,26 @@ describe Tadpole::Filters do
|
|
28
28
|
it "should take a block" do
|
29
29
|
Template(:filters).before_run_filters.last.should be_kind_of(Proc)
|
30
30
|
end
|
31
|
+
|
32
|
+
it "should execute block in instance context" do
|
33
|
+
module Tadpole::LocalTemplate
|
34
|
+
before_run do
|
35
|
+
@xyz = self
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
t = Tadpole.create_template('block_run')
|
40
|
+
module Tadpole::Template_block_run
|
41
|
+
def sections
|
42
|
+
['x']
|
43
|
+
end
|
44
|
+
def x; "x" end
|
45
|
+
end
|
46
|
+
obj = t.new
|
47
|
+
obj.run.should == ""
|
48
|
+
obj.instance_variable_get("@xyz").should == obj
|
49
|
+
Tadpole::LocalTemplate.before_run_filters.clear
|
50
|
+
end
|
31
51
|
end
|
32
52
|
|
33
53
|
describe '#before_section' do
|
@@ -54,6 +74,26 @@ describe Tadpole::Filters do
|
|
54
74
|
filter[0].should == nil
|
55
75
|
filter[1].should be_kind_of(Proc)
|
56
76
|
end
|
77
|
+
|
78
|
+
it "should execute block in instance context" do
|
79
|
+
module Tadpole::LocalTemplate
|
80
|
+
before_section(:x) do
|
81
|
+
@xyz = options
|
82
|
+
false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
t = Tadpole.create_template('block_sections')
|
86
|
+
module Tadpole::Template_block_sections
|
87
|
+
def init; sections :x end
|
88
|
+
def x; 'x' end
|
89
|
+
end
|
90
|
+
obj = t.new
|
91
|
+
obj.run(:foo => 1).should == ""
|
92
|
+
opts = obj.instance_variable_get("@xyz")
|
93
|
+
opts.should be_instance_of(OpenHashStruct)
|
94
|
+
opts.foo.should == 1
|
95
|
+
Tadpole::LocalTemplate.before_run_filters.clear
|
96
|
+
end
|
57
97
|
end
|
58
98
|
|
59
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tadpole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loren Segal
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-15 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|