aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/caching
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-03-15 11:58:05 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-03-15 14:50:43 -0700
commit9de83050d3a4b260d4aeb5d09ec4eb64f913ba64 (patch)
tree1688303e527eec441a5ec79011f06907dfe5a264 /actionpack/lib/action_controller/caching
parent1f2738261f3c3c061540bb20e3a1edec96b76034 (diff)
downloadrails-9de83050d3a4b260d4aeb5d09ec4eb64f913ba64.tar.gz
rails-9de83050d3a4b260d4aeb5d09ec4eb64f913ba64.tar.bz2
rails-9de83050d3a4b260d4aeb5d09ec4eb64f913ba64.zip
Add deprecation notices for <% %>.
* The approach is to compile <% %> into a method call that checks whether the value returned from a block is a String. If it is, it concats to the buffer and prints a deprecation warning. * <%= %> uses exactly the same logic to compile the template, which first checks to see whether it's compiling a block. * This should have no impact on other uses of block in templates. For instance, in <% [1,2,3].each do |i| %><%= i %><% end %>, the call to each returns an Array, not a String, so the result is not concatenated * In two cases (#capture and #cache), a String can be returned that should *never* be concatenated. We have temporarily created a String subclass called NonConcattingString which behaves (and is serialized) identically to String, but is not concatenated by the code that handles deprecated <% %> block helpers. Once we remove support for <% %> block helpers, we can remove NonConcattingString.
Diffstat (limited to 'actionpack/lib/action_controller/caching')
-rw-r--r--actionpack/lib/action_controller/caching/fragments.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb
index 89787727bd..a07fe2b255 100644
--- a/actionpack/lib/action_controller/caching/fragments.rb
+++ b/actionpack/lib/action_controller/caching/fragments.rb
@@ -34,17 +34,23 @@ module ActionController #:nodoc:
ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
end
- def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
+ def fragment_for(name = {}, options = nil, &block) #:nodoc:
if perform_caching
if fragment_exist?(name, options)
- buffer.safe_concat(read_fragment(name, options))
+ read_fragment(name, options)
else
+ # VIEW TODO: Make #capture usable outside of ERB
+ # This dance is needed because Builder can't use capture
+ buffer = view_context.output_buffer
pos = buffer.length
- block.call
- write_fragment(name, buffer[pos..-1], options)
+ yield
+ fragment = buffer[pos..-1]
+ write_fragment(name, fragment, options)
+ ActionView::NonConcattingString.new(fragment)
end
else
- block.call
+ ret = yield
+ ActiveSupport::SafeBuffer.new(ret) if ret.is_a?(String)
end
end