From 72f93b581f1d1a7496ccebbd90578714c171c5a5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 19 Jun 2008 22:03:27 -0700 Subject: Check whether blocks are called from erb using a special __in_erb_template variable visible in block binding. --- actionpack/lib/action_view/helpers/capture_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view/helpers/capture_helper.rb') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 9cd9d3d06a..990c30b90d 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -31,10 +31,13 @@ module ActionView # # def capture(*args, &block) - if output_buffer + # Return captured buffer in erb. + if block_called_from_erb?(block) with_output_buffer { block.call(*args) } + + # Return block result otherwise, but protect buffer also. else - block.call(*args) + with_output_buffer { return block.call(*args) } end end @@ -117,6 +120,7 @@ module ActionView ivar = "@content_for_#{name}" content = capture(&block) if block_given? instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{content}") + nil end private -- cgit v1.2.3