markevans-block_helpers 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +10 -0
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/block_helpers.gemspec +2 -5
- data/lib/block_helpers.rb +5 -2
- data/spec/helpers/block_helpers_spec.rb +76 -19
- metadata +2 -12
data/README.markdown
CHANGED
@@ -168,6 +168,16 @@ To use in Rails, add to your `environment.rb`:
|
|
168
168
|
|
169
169
|
config.gem "markevans-block_helpers", :lib => "block_helpers", :source => "http://gems.github.com"
|
170
170
|
|
171
|
+
for Merb, in `init.rb`:
|
172
|
+
|
173
|
+
dependency "markevans-block_helpers", :require_as => "block_helpers"
|
174
|
+
|
175
|
+
Compatibility
|
176
|
+
=============
|
177
|
+
Currently it depends on activesupport, and requires that the helper already has the methods `concat` and `capture` available (which is the case in Rails and Merb).
|
178
|
+
|
179
|
+
It works with both the one and two argument versions of `concat`, so should work with all recent versions of Rails and Merb.
|
180
|
+
|
171
181
|
Credits
|
172
182
|
=======
|
173
183
|
- <a href="http://github.com/markevans">Mark Evans</a> (author)
|
data/Rakefile
CHANGED
@@ -10,7 +10,6 @@ begin
|
|
10
10
|
gem.homepage = "http://github.com/markevans/block_helpers"
|
11
11
|
gem.authors = ["Mark Evans"]
|
12
12
|
gem.add_dependency('activesupport', '>= 2.0')
|
13
|
-
gem.add_dependency('actionpack', '>= 2.0')
|
14
13
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
14
|
end
|
16
15
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.8
|
data/block_helpers.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{block_helpers}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.8"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Mark Evans"]
|
9
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-19}
|
10
10
|
s.email = %q{mark@new-bamboo.co.uk}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -43,13 +43,10 @@ Gem::Specification.new do |s|
|
|
43
43
|
|
44
44
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
45
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.0"])
|
46
|
-
s.add_runtime_dependency(%q<actionpack>, [">= 2.0"])
|
47
46
|
else
|
48
47
|
s.add_dependency(%q<activesupport>, [">= 2.0"])
|
49
|
-
s.add_dependency(%q<actionpack>, [">= 2.0"])
|
50
48
|
end
|
51
49
|
else
|
52
50
|
s.add_dependency(%q<activesupport>, [">= 2.0"])
|
53
|
-
s.add_dependency(%q<actionpack>, [">= 2.0"])
|
54
51
|
end
|
55
52
|
end
|
data/lib/block_helpers.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'activesupport'
|
2
|
-
require 'action_view'
|
3
2
|
|
4
3
|
module BlockHelpers
|
5
4
|
|
@@ -20,7 +19,11 @@ module BlockHelpers
|
|
20
19
|
renderer = #{klass.name}.new(*args)
|
21
20
|
renderer.send(:helper=, self)
|
22
21
|
if renderer.public_methods(false).include? 'display'
|
23
|
-
concat
|
22
|
+
if method(:concat).arity == 1
|
23
|
+
concat renderer.display(capture(renderer, &block))
|
24
|
+
else
|
25
|
+
concat renderer.display(capture(renderer, &block)), binding
|
26
|
+
end
|
24
27
|
else
|
25
28
|
block.call(renderer)
|
26
29
|
end
|
@@ -8,9 +8,12 @@ describe TestHelperModule do
|
|
8
8
|
describe "simple block_helper" do
|
9
9
|
|
10
10
|
before(:each) do
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
module TestHelperModule
|
12
|
+
remove_const(:TestHelper) if defined?(TestHelper)
|
13
|
+
class TestHelper < BlockHelpers::Base
|
14
|
+
def hello
|
15
|
+
'Hi there'
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
@@ -34,12 +37,13 @@ describe TestHelperModule do
|
|
34
37
|
describe "access to other methods" do
|
35
38
|
before(:each) do
|
36
39
|
module TestHelperModule
|
37
|
-
|
40
|
+
|
38
41
|
def yoghurt
|
39
42
|
'Yoghurt'
|
40
43
|
end
|
41
44
|
|
42
|
-
|
45
|
+
remove_const(:TestHelper) if defined?(TestHelper)
|
46
|
+
class TestHelper < BlockHelpers::Base
|
43
47
|
def yog
|
44
48
|
yoghurt[0..2]
|
45
49
|
end
|
@@ -92,7 +96,7 @@ describe TestHelperModule do
|
|
92
96
|
<% end %>
|
93
97
|
)).should match_html('<label for="hi">Hi</label>')
|
94
98
|
end
|
95
|
-
it "should work with methods like '
|
99
|
+
it "should work with methods like 'capture'" do
|
96
100
|
eval_erb(%(
|
97
101
|
<% test_helper do |r| %>
|
98
102
|
<% r.check_capture do %>
|
@@ -103,16 +107,66 @@ describe TestHelperModule do
|
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
110
|
+
describe "accesibility" do
|
111
|
+
def run_erb
|
112
|
+
eval_erb(%(
|
113
|
+
<% compat_helper do |r| %>
|
114
|
+
HELLO
|
115
|
+
<% end %>
|
116
|
+
))
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should work when concat has one arg" do
|
120
|
+
module TestHelperModule
|
121
|
+
def concat(html); super(html); end
|
122
|
+
remove_const(:CompatHelper) if defined?(CompatHelper)
|
123
|
+
class CompatHelper < BlockHelpers::Base
|
124
|
+
def display(body)
|
125
|
+
"Before...#{body}...after"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
run_erb.should match_html("Before... HELLO ...after")
|
130
|
+
end
|
131
|
+
it "should work when concat has two args" do
|
132
|
+
module TestHelperModule
|
133
|
+
def concat(html, binding); super(html); end
|
134
|
+
remove_const(:CompatHelper) if defined?(:CompatHelper)
|
135
|
+
class CompatHelper < BlockHelpers::Base
|
136
|
+
def display(body)
|
137
|
+
"Before...#{body}...after"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
run_erb.should match_html("Before... HELLO ...after")
|
142
|
+
end
|
143
|
+
it "should work when concat has one optional arg" do
|
144
|
+
module TestHelperModule
|
145
|
+
def concat(html, binding=nil); super(html); end
|
146
|
+
remove_const(:CompatHelper) if defined?(:CompatHelper)
|
147
|
+
class CompatHelper < BlockHelpers::Base
|
148
|
+
def display(body)
|
149
|
+
"Before...#{body}...after"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
run_erb.should match_html("Before... HELLO ...after")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
106
157
|
describe "surrounding the block" do
|
107
158
|
|
108
159
|
before(:each) do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
160
|
+
module TestHelperModule
|
161
|
+
remove_const(:TestHelperSurround) if defined?(TestHelperSurround)
|
162
|
+
class TestHelperSurround < BlockHelpers::Base
|
163
|
+
def display(body)
|
164
|
+
%(
|
165
|
+
<p>Before</p>
|
166
|
+
#{body}
|
167
|
+
<p>After</p>
|
168
|
+
)
|
169
|
+
end
|
116
170
|
end
|
117
171
|
end
|
118
172
|
end
|
@@ -128,12 +182,15 @@ describe TestHelperModule do
|
|
128
182
|
|
129
183
|
describe "block helpers with arguments" do
|
130
184
|
before(:each) do
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
185
|
+
module TestHelperModule
|
186
|
+
remove_const(:TestHelperWithArgs) if defined?(TestHelperWithArgs)
|
187
|
+
class TestHelperWithArgs < BlockHelpers::Base
|
188
|
+
def initialize(id, klass)
|
189
|
+
@id, @klass = id, klass
|
190
|
+
end
|
191
|
+
def hello
|
192
|
+
%(<p class="#{@klass}" id="#{@id}">Hello</p>)
|
193
|
+
end
|
137
194
|
end
|
138
195
|
end
|
139
196
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markevans-block_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Evans
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,16 +22,6 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "2.0"
|
24
24
|
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: actionpack
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "2.0"
|
34
|
-
version:
|
35
25
|
description:
|
36
26
|
email: mark@new-bamboo.co.uk
|
37
27
|
executables: []
|