aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/renderer/partial_renderer
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-02-13 17:59:21 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2019-02-19 13:46:09 -0800
commit1bc0a59d6ee198fa535c04f32527a1d6228b647d (patch)
treebbdbd9cdef5aebd1878df4ee54b1f6e2cd534ebd /actionview/lib/action_view/renderer/partial_renderer
parentd0733ba8c0528aa4bc6e890e189afaac62ebe58f (diff)
downloadrails-1bc0a59d6ee198fa535c04f32527a1d6228b647d.tar.gz
rails-1bc0a59d6ee198fa535c04f32527a1d6228b647d.tar.bz2
rails-1bc0a59d6ee198fa535c04f32527a1d6228b647d.zip
Return rendered template information instead of just strings
This commit introduces "rendered template" and "rendered collection" objects. The template renderers can now return a more complex object than just strings. This allows the framework to get more information about the templates that were rendered. In this commit we use the rendered template object to set the "rendered_format" on the lookup context in the controller rather than all the way in the template renderer. That means we don't need to check the "rendered_format" every time we render a template, we just do it once after all templates have been rendered.
Diffstat (limited to 'actionview/lib/action_view/renderer/partial_renderer')
-rw-r--r--actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
index 9f1de5a397..401391290f 100644
--- a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
+++ b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
@@ -40,7 +40,7 @@ module ActionView
rendered_partials = @collection.empty? ? [] : yield
index = 0
- fetch_or_cache_partial(cached_partials, order_by: keyed_collection.each_key) do
+ fetch_or_cache_partial(cached_partials, template, order_by: keyed_collection.each_key) do
# This block is called once
# for every cache miss while preserving order.
rendered_partials[index].tap { index += 1 }
@@ -81,11 +81,13 @@ module ActionView
#
# If the partial is not already cached it will also be
# written back to the underlying cache store.
- def fetch_or_cache_partial(cached_partials, order_by:)
+ def fetch_or_cache_partial(cached_partials, template, order_by:)
order_by.map do |cache_key|
- cached_partials.fetch(cache_key) do
+ if content = cached_partials[cache_key]
+ build_rendered_template(content, nil, template)
+ else
yield.tap do |rendered_partial|
- collection_cache.write(cache_key, rendered_partial)
+ collection_cache.write(cache_key, rendered_partial.body)
end
end
end