lib/block_helpers.rb in block_helpers-0.2.11 vs lib/block_helpers.rb in block_helpers-0.3.0
- old
+ new
@@ -15,25 +15,33 @@
#
method_name = klass.name.split('::').last.underscore
klass.parent.class_eval %(
def #{method_name}(*args, &block)
renderer = #{klass.name}.new(*args)
- renderer.send(:helper=, self)
- if renderer.public_methods(false).include? 'display'
- body = block ? capture(renderer, &block) : nil
- if method(:concat).arity == 2
- concat renderer.display(body), binding
+ top_level_helper = if self.is_a?(BlockHelpers::Base)
+ self.helper
+ else
+ self
+ end
+ renderer.send(:helper=, top_level_helper)
+ body = block ? capture(renderer, &block) : nil
+ processed_body = renderer.display(body)
+ if processed_body
+ if top_level_helper.method(:concat).arity == 2
+ concat processed_body, binding
else
- concat renderer.display(body)
+ concat processed_body
end
- else
- block.call(renderer) if block
end
renderer
end
)
end
+ def display(body)
+ body
+ end
+
def respond_to?(method)
super or helper.respond_to?(method)
end
protected