markevans-block_helpers 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -84,14 +84,14 @@ This generates:
84
84
  Using arguments
85
85
  ---------------
86
86
 
87
- You can pass in arguments to the helper, and these will be passed through to the class's `initialize` method.
87
+ You can pass in arguments to the helper, and these will be passed through to the class's `options` method.
88
88
  In the helper:
89
89
 
90
90
  module MyHelper
91
91
 
92
92
  class MyBlockHelper < ActionView::BlockHelper
93
93
 
94
- def initialize(tag_type)
94
+ def options(tag_type)
95
95
  @tag_type = tag_type
96
96
  end
97
97
 
@@ -168,6 +168,12 @@ 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
+ Credits
172
+ =======
173
+ - <a href="http://github.com/markevans">Mark Evans</a> (author)
174
+ - <a href="http://github.com/nesquena">Nathan Esquenazi</a> and <a href="http://github.com/2collegebums">2collegebums</a> (contributor)
175
+
176
+
171
177
  Copyright
172
178
  ========
173
179
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -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.4"
5
+ s.version = "0.2.5"
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-13}
9
+ s.date = %q{2009-08-14}
10
10
  s.email = %q{mark@new-bamboo.co.uk}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
data/lib/block_helpers.rb CHANGED
@@ -2,9 +2,9 @@ require 'activesupport'
2
2
  require 'action_view'
3
3
 
4
4
  module ActionView
5
-
5
+
6
6
  class BlockHelper
7
-
7
+
8
8
  def self.inherited(klass)
9
9
  # Define the helper method
10
10
  # e.g. for a class:
@@ -15,9 +15,10 @@ module ActionView
15
15
  # then we define a helper method 'hello_helper'
16
16
  #
17
17
  method_name = klass.name.split('::').last.underscore
18
- klass.parent.class_eval %(
18
+ klass.parent.class_eval %(
19
19
  def #{method_name}(*args, &block)
20
20
  renderer = #{klass.name}.new(*args)
21
+ renderer.send(:helper=, self)
21
22
  if renderer.public_methods(false).include? 'display'
22
23
  concat renderer.display(capture(renderer, &block))
23
24
  else
@@ -25,32 +26,25 @@ module ActionView
25
26
  end
26
27
  end
27
28
  )
28
-
29
- # Make a 'helper' object available, for calling
30
- # other helper methods / action view helpers,
31
- # in case of name clashes
32
- klass.class_eval do
33
-
34
- include klass.parent
35
- include ActionView::Helpers
36
-
37
- protected
38
- define_method :helper do
39
- if @helper.nil?
40
- @helper = Object.new
41
- # Open the singleton class of @helper, while
42
- # keeping 'klass' visible
43
- class << @helper; self; end.class_eval do
44
- include klass.parent
45
- include ActionView::Helpers
46
- end
47
- end
48
- @helper
49
- end
29
+ end
50
30
 
31
+ def respond_to?(method)
32
+ super or helper.respond_to?(method)
33
+ end
34
+
35
+ protected
36
+
37
+ attr_accessor :helper
38
+
39
+ def method_missing(method, *args, &block)
40
+ if helper.respond_to?(method)
41
+ self.class_eval "def #{method}(*args, &block); helper.send('#{method}', *args, &block); end"
42
+ self.send(method, *args, &block)
43
+ else
44
+ super
51
45
  end
52
46
  end
53
47
 
54
48
  end
55
-
56
- end
49
+
50
+ end
@@ -52,6 +52,10 @@ describe TestHelperModule do
52
52
  def label_tag(text)
53
53
  helper.label_tag(text[0..1])
54
54
  end
55
+ def check_capture(&block)
56
+ string = capture(&block)
57
+ 2.times{ concat(string) }
58
+ end
55
59
  end
56
60
 
57
61
  def cheese
@@ -88,6 +92,15 @@ describe TestHelperModule do
88
92
  <% end %>
89
93
  )).should match_html('<label for="hi">Hi</label>')
90
94
  end
95
+ it "should work with methods like 'concat'" do
96
+ eval_erb(%(
97
+ <% test_helper do |r| %>
98
+ <% r.check_capture do %>
99
+ HELLO
100
+ <% end %>
101
+ <% end %>
102
+ )).should match_html('HELLO HELLO')
103
+ end
91
104
  end
92
105
 
93
106
  describe "surrounding the block" do
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
4
+ version: 0.2.5
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-13 00:00:00 -07:00
12
+ date: 2009-08-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency