aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template/resolver.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-08 20:39:15 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-08 20:39:15 +0100
commitbdf5096816d03f2bdaefd20a07a0fa562543549c (patch)
tree3e656b06836772e74f8c44492d61caddb6bfb893 /actionpack/lib/action_view/template/resolver.rb
parent67a6725bf934452219cc054c8cd0535148d4fcd4 (diff)
downloadrails-bdf5096816d03f2bdaefd20a07a0fa562543549c.tar.gz
rails-bdf5096816d03f2bdaefd20a07a0fa562543549c.tar.bz2
rails-bdf5096816d03f2bdaefd20a07a0fa562543549c.zip
Move details to lookup_context and make resolvers use the cache key.
Diffstat (limited to 'actionpack/lib/action_view/template/resolver.rb')
-rw-r--r--actionpack/lib/action_view/template/resolver.rb46
1 files changed, 12 insertions, 34 deletions
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index fde13a4bdf..9a011f7638 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -5,24 +5,9 @@ require "action_view/template"
module ActionView
class Resolver
-
- class_inheritable_accessor(:registered_details)
- self.registered_details = {}
-
- def self.register_detail(name, options = {})
- registered_details[name] = lambda do |val|
- val = Array.wrap(val || yield)
- val |= [nil] unless options[:allow_nil] == false
- val
- end
- end
-
- register_detail(:locale) { [I18n.locale] }
- register_detail(:formats) { Mime::SET.symbols }
- register_detail(:handlers) { Template::Handlers.extensions }
-
def initialize
- @cached = {}
+ @cached = Hash.new { |h1,k1| h1[k1] =
+ Hash.new { |h2,k2| h2[k2] = Hash.new { |h3, k3| h3[k3] = {} } } }
end
def find(*args)
@@ -30,11 +15,10 @@ module ActionView
end
# Normalizes the arguments and passes it on to find_template.
- def find_all(name, details = {}, prefix = nil, partial = nil)
- details = normalize_details(details)
+ def find_all(name, details = {}, prefix = nil, partial = nil, key=nil)
name, prefix = normalize_name(name, prefix)
- cached([name, details, prefix, partial]) do
+ cached(key, prefix, name, partial) do
find_templates(name, details, prefix, partial)
end
end
@@ -52,16 +36,6 @@ module ActionView
raise NotImplementedError
end
- def normalize_details(details)
- details = details.dup
- # TODO: Refactor this concern out of the resolver
- details.delete(:formats) if details[:formats] == [:"*/*"]
- registered_details.each do |k, v|
- details[k] = v.call(details[k])
- end
- details
- end
-
# Support legacy foo.erb names even though we now ignore .erb
# as well as incorrectly putting part of the path in the template
# name instead of the prefix.
@@ -73,10 +47,14 @@ module ActionView
return parts.pop, [prefix, *parts].compact.join("/")
end
- def cached(key)
- return yield unless caching?
- return @cached[key] if @cached.key?(key)
- @cached[key] = yield
+ def cached(key, prefix, name, partial)
+ return yield unless key && caching?
+ scope = @cached[key][prefix][name]
+ if scope.key?(partial)
+ scope[partial]
+ else
+ scope[partial] = yield
+ end
end
end