aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/capture_helper.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-06-19 22:03:27 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-06-19 22:21:56 -0700
commit72f93b581f1d1a7496ccebbd90578714c171c5a5 (patch)
tree0e89550d0297bba6a87c8eae507c7388d62c92e8 /actionpack/lib/action_view/helpers/capture_helper.rb
parentc440c9b199d7474e356472616ef03f9c7e17c405 (diff)
downloadrails-72f93b581f1d1a7496ccebbd90578714c171c5a5.tar.gz
rails-72f93b581f1d1a7496ccebbd90578714c171c5a5.tar.bz2
rails-72f93b581f1d1a7496ccebbd90578714c171c5a5.zip
Check whether blocks are called from erb using a special __in_erb_template variable visible in block binding.
Diffstat (limited to 'actionpack/lib/action_view/helpers/capture_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb8
1 files changed, 6 insertions, 2 deletions
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
# </body></html>
#
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