Permalink
Browse files

fixed for Rails 3.1+ (ActiveSupport 3.1 breaks capture method)

  • Loading branch information...
1 parent 7b917a0 commit 64a28acf0de46cef44747573b18eec55b5c4ffa9 @fastcatch committed May 22, 2012
Showing with 16 additions and 2 deletions.
  1. +1 −1 README.markdown
  2. +15 −1 lib/block_helpers.rb
View
@@ -241,7 +241,7 @@ Block_helpers will work as per the new syntax if run on Rails 3. If you want it
Compatibility
=============
-Currently it depends on activesupport, and requires that the helper already has the methods `concat` and `capture` available (which is the case in Rails and Merb).
+Currently it depends on activesupport, and requires that the helper already has the methods `concat` and `capture` available (which is the case in Rails and Merb). Please, note, that ActiveSupport 3.1+ breaks the `capture` method (see <a href='https://github.com/capistrano/capistrano/issues/168#issuecomment-4162727'>this comment</a> and <a href='https://github.com/rails/rails/commit/d4fa120671e989eecb71c14647dd2051d28de4a5#activesupport/lib/active_support/core_ext/kernel/reporting.rb'>this commit</a>). Thus `capture` got replicated in the gem.
It works with both the one and two argument versions of `concat`, so should work with all recent versions of Rails and Merb.
View
@@ -71,7 +71,7 @@ def respond_to?(method)
# For nested block helpers
def parent
- @parent ||= self.class .current_parent_block_helper
+ @parent ||= self.class.current_parent_block_helper
end
def helper
@@ -87,6 +87,20 @@ def method_missing(method, *args, &block)
end
end
+ def capture(*args)
+ # ActiveSupport 3.1 breaks capture method (defines it on all objects)
+ # so we have to resort to rewrite it
+ if Rails.version < "3.1"
+ ActionView::Helpers::CaptureHelper.capture(renderer, &block)
+ else
+ value = nil
+ buffer = with_output_buffer { value = yield(*args) }
+ if string = buffer.presence || value and string.is_a?(String)
+ ERB::Util.html_escape string
+ end
+ end
+ end
+
end
end

0 comments on commit 64a28ac

Please sign in to comment.