8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/block_helpers.rb', line 8
def self.inherited(klass)
method_name = klass.name.split('::').last.underscore
klass.parent.class_eval %(
def #{method_name}(*args, &block)
renderer = #{klass.name}.new(*args)
if renderer.public_methods(false).include? 'display'
concat renderer.display(capture(renderer, &block))
else
block.call(renderer)
end
end
)
klass.class_eval do
include klass.parent
include ActionView::Helpers
protected
define_method :helper do
if @helper.nil?
@helper = Object.new
class << @helper; self; end.class_eval do
include klass.parent
include ActionView::Helpers
end
end
@helper
end
end
end
|