Skip to content

Commit

Permalink
Some more tweaks on <% %>.
Browse files Browse the repository at this point in the history
  * The cache helper is now semantically "mark this region for caching"
  * As a result, <% x = cache do %> no longer works
  • Loading branch information
Carlhuda committed Mar 16, 2010
1 parent 67d8b97 commit c61ed70
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions actionpack/lib/action_controller/caching/fragments.rb
Expand Up @@ -44,9 +44,8 @@ def fragment_for(name = {}, options = nil, &block) #:nodoc:
buffer = view_context.output_buffer
pos = buffer.length
yield
fragment = buffer[pos..-1]
fragment = buffer.slice!(pos..-1)
write_fragment(name, fragment, options)
fragment.is_a?(String) ? ActionView::NonConcattingString.new(fragment) : fragment
end
else
ret = yield
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_view/helpers/cache_helper.rb
Expand Up @@ -32,7 +32,8 @@ module CacheHelper
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
controller.fragment_for(name, options, &block)
safe_concat controller.fragment_for(name, options, &block)
nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -29,7 +29,7 @@ def concat(string)
end

def safe_concat(string)
output_buffer.safe_concat(string)
output_buffer.respond_to?(:safe_concat) ? output_buffer.safe_concat(string) : concat(string)
end

# Truncates a given +text+ after a given <tt>:length</tt> if +text+ is longer than <tt>:length</tt>
Expand Down
8 changes: 4 additions & 4 deletions actionpack/test/controller/caching_test.rb
Expand Up @@ -704,8 +704,8 @@ def test_fragment_caching
def test_fragment_caching_in_partials
get :html_fragment_cached_with_partial
assert_response :success
assert_match /Fragment caching in a partial/, @response.body
assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
assert_match /Old fragment caching in a partial/, @response.body
assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
end

def test_render_inline_before_fragment_caching
Expand All @@ -719,8 +719,8 @@ def test_render_inline_before_fragment_caching
def test_fragment_caching_in_rjs_partials
xhr :get, :js_fragment_cached_with_partial
assert_response :success
assert_match /Fragment caching in a partial/, @response.body
assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
assert_match /Old fragment caching in a partial/, @response.body
assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
end

def test_html_formatted_fragment_caching
Expand Down

0 comments on commit c61ed70

Please sign in to comment.