aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template/handlers
diff options
context:
space:
mode:
authorDov Murik <dov.murik@gmail.com>2015-07-04 22:34:00 -0400
committerDov Murik <dov.murik@gmail.com>2015-07-07 16:57:09 -0400
commit5a41d00455f67a03e3cb77cd89c3b710a7c389d0 (patch)
tree04581f1a19441de919eacfd5ce3a4b0481c03658 /actionview/lib/action_view/template/handlers
parent062cbd18ddbf6ef48c9a9a2a69081737aebbee89 (diff)
downloadrails-5a41d00455f67a03e3cb77cd89c3b710a7c389d0.tar.gz
rails-5a41d00455f67a03e3cb77cd89c3b710a7c389d0.tar.bz2
rails-5a41d00455f67a03e3cb77cd89c3b710a7c389d0.zip
Support explicit defintion of resouce name for collection caching.
If a template includes `# Template Collection: ...` anywhere in its source, that name will be used as the cache name for the partial that is rendered for the collection. This allows users to enable collection caching even if the template doesn't start with `<% cache ... do %>`. Moreover, the `# Template Collection: ...` notation is recognized in all template types (and template types other than ERB can define a resource_cache_call_pattern method to allow the `cache ... do` pattern to be recognized too).
Diffstat (limited to 'actionview/lib/action_view/template/handlers')
-rw-r--r--actionview/lib/action_view/template/handlers/erb.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb
index da96347e4d..1f8459c24b 100644
--- a/actionview/lib/action_view/template/handlers/erb.rb
+++ b/actionview/lib/action_view/template/handlers/erb.rb
@@ -125,7 +125,7 @@ module ActionView
# Returns Regexp to extract a cached resource's name from a cache call at the
# first line of a template.
- # The extracted cache name is expected in $1.
+ # The extracted cache name is captured as :resource_name.
#
# <% cache notification do %> # => notification
#
@@ -138,7 +138,14 @@ module ActionView
#
# <% cache notification.event do %> # => nil
def resource_cache_call_pattern
- /\A(?:<%#.*%>)*\s*<%\s*cache\(?\s*(\w+)[\s\)]/m
+ /\A
+ (?:<%\#.*%>)* # optional initial comment
+ \s* # followed by optional spaces or newlines
+ <%\s*cache[\(\s] # followed by an ERB call to cache
+ \s* # followed by optional spaces or newlines
+ (?<resource_name>\w+) # capture the cache call argument as :resource_name
+ [\s\)] # followed by a space or close paren
+ /xm
end
private