block_helpers 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -166,11 +166,11 @@ Installation
166
166
 
167
167
  To use in Rails, add to your `environment.rb`:
168
168
 
169
- config.gem "markevans-block_helpers", :lib => "block_helpers", :source => "http://gems.github.com"
169
+ config.gem "block_helpers", :lib => "block_helpers", :source => "http://gemcutter.org"
170
170
 
171
171
  for Merb, in `init.rb`:
172
172
 
173
- dependency "markevans-block_helpers", :require_as => "block_helpers"
173
+ dependency "block_helpers"
174
174
 
175
175
  Compatibility
176
176
  =============
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.11
1
+ 0.3.0
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{block_helpers}
5
- s.version = "0.2.11"
8
+ s.version = "0.3.0"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Mark Evans"]
9
- s.date = %q{2009-08-28}
12
+ s.date = %q{2009-10-12}
10
13
  s.email = %q{mark@new-bamboo.co.uk}
11
14
  s.extra_rdoc_files = [
12
15
  "LICENSE",
@@ -25,11 +28,10 @@ Gem::Specification.new do |s|
25
28
  "spec/helpers/block_helpers_spec.rb",
26
29
  "spec/spec_helper.rb"
27
30
  ]
28
- s.has_rdoc = true
29
31
  s.homepage = %q{http://github.com/markevans/block_helpers}
30
32
  s.rdoc_options = ["--charset=UTF-8"]
31
33
  s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.3.1}
34
+ s.rubygems_version = %q{1.3.5}
33
35
  s.summary = %q{An extension to ActionView for adding block helpers to views}
34
36
  s.test_files = [
35
37
  "spec/for_spec_rails/application.rb",
@@ -39,7 +41,7 @@ Gem::Specification.new do |s|
39
41
 
40
42
  if s.respond_to? :specification_version then
41
43
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
- s.specification_version = 2
44
+ s.specification_version = 3
43
45
 
44
46
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
47
  s.add_runtime_dependency(%q<activesupport>, [">= 2.0"])
data/lib/block_helpers.rb CHANGED
@@ -17,22 +17,30 @@ module BlockHelpers
17
17
  klass.parent.class_eval %(
18
18
  def #{method_name}(*args, &block)
19
19
  renderer = #{klass.name}.new(*args)
20
- renderer.send(:helper=, self)
21
- if renderer.public_methods(false).include? 'display'
22
- body = block ? capture(renderer, &block) : nil
23
- if method(:concat).arity == 2
24
- concat renderer.display(body), binding
20
+ top_level_helper = if self.is_a?(BlockHelpers::Base)
21
+ self.helper
22
+ else
23
+ self
24
+ end
25
+ renderer.send(:helper=, top_level_helper)
26
+ body = block ? capture(renderer, &block) : nil
27
+ processed_body = renderer.display(body)
28
+ if processed_body
29
+ if top_level_helper.method(:concat).arity == 2
30
+ concat processed_body, binding
25
31
  else
26
- concat renderer.display(body)
32
+ concat processed_body
27
33
  end
28
- else
29
- block.call(renderer) if block
30
34
  end
31
35
  renderer
32
36
  end
33
37
  )
34
38
  end
35
39
 
40
+ def display(body)
41
+ body
42
+ end
43
+
36
44
  def respond_to?(method)
37
45
  super or helper.respond_to?(method)
38
46
  end
@@ -120,7 +120,7 @@ describe TestHelperModule do
120
120
  end
121
121
  end
122
122
 
123
- describe "accesibility" do
123
+ describe "accessibility" do
124
124
  def run_erb
125
125
  eval_erb(%(
126
126
  <% compat_helper do |r| %>
@@ -225,4 +225,93 @@ describe TestHelperModule do
225
225
  end
226
226
  end
227
227
 
228
+ describe "inheritance" do
229
+
230
+ before(:each) do
231
+ module TestHelperModule
232
+ remove_const(:ParentTestHelper) if defined?(ParentTestHelper)
233
+ remove_const(:ChildTestHelper) if defined?(ChildTestHelper)
234
+ class ParentTestHelper < BlockHelpers::Base
235
+ def hello
236
+ "hello"
237
+ end
238
+ end
239
+ class ChildTestHelper < ParentTestHelper
240
+ end
241
+ end
242
+ end
243
+
244
+ it "should inherit normal methods" do
245
+ eval_erb(%(
246
+ <% child_test_helper do |r| %>
247
+ <%= r.hello %>
248
+ <% end %>
249
+ )).should match_html("hello")
250
+ end
251
+
252
+ it "should inherit the 'display' method" do
253
+ TestHelperModule::ParentTestHelper.class_eval do
254
+ def display(body)
255
+ "before...#{body}...after"
256
+ end
257
+ end
258
+ eval_erb(%(
259
+ <% child_test_helper do %>
260
+ hello
261
+ <% end %>
262
+ )).should match_html("before... hello ...after")
263
+ end
264
+
265
+ end
266
+
267
+ describe "when display returns 'nil'" do
268
+ it "should output nothing" do
269
+ module TestHelperModule
270
+ remove_const(:NilHelper) if defined?(NilHelper)
271
+ class NilHelper < BlockHelpers::Base
272
+ def display(body)
273
+ end
274
+ end
275
+ end
276
+ eval_erb(%(
277
+ <% nil_helper do %>
278
+ hello
279
+ <% end %>
280
+ )).should match_html("")
281
+ end
282
+ end
283
+
284
+ describe "nested block helpers" do
285
+ it "should define a nested block helper method" do
286
+ module TestHelperModule
287
+ class OuterHelper < BlockHelpers::Base
288
+
289
+ def egg
290
+ 'bad egg'
291
+ end
292
+
293
+ def display(body)
294
+ "Outer #{body}"
295
+ end
296
+
297
+ class InnerHelper < BlockHelpers::Base
298
+ def egg
299
+ 'EGG'
300
+ end
301
+ def display(body)
302
+ "Inner #{body}"
303
+ end
304
+ end
305
+ end
306
+ end
307
+ eval_erb(%(
308
+ <% outer_helper do |o| %>
309
+ <% o.inner_helper do |i| %>
310
+ <%= i.egg %>
311
+ <% end %>
312
+ <% end %>
313
+ )).should match_html("Outer Inner EGG")
314
+ end
315
+ end
316
+
228
317
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: block_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.3.0
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-28 00:00:00 +01:00
12
+ date: 2009-10-12 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -69,7 +69,7 @@ requirements: []
69
69
  rubyforge_project:
70
70
  rubygems_version: 1.3.5
71
71
  signing_key:
72
- specification_version: 2
72
+ specification_version: 3
73
73
  summary: An extension to ActionView for adding block helpers to views
74
74
  test_files:
75
75
  - spec/for_spec_rails/application.rb