diff options
author | José Valim <jose.valim@gmail.com> | 2010-03-08 16:32:40 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-08 16:32:40 +0100 |
commit | 68cda695da27f57cae682d160a13dab4dacb1ef8 (patch) | |
tree | 3a3aedb66bc64e4e70220b3f051cd71356373226 /actionpack/lib/action_view/lookup_context.rb | |
parent | 44ebab96da0ab47cc45c64a6efdd2cbb80f9d042 (diff) | |
download | rails-68cda695da27f57cae682d160a13dab4dacb1ef8.tar.gz rails-68cda695da27f57cae682d160a13dab4dacb1ef8.tar.bz2 rails-68cda695da27f57cae682d160a13dab4dacb1ef8.zip |
Speed up performance in resolvers by adding fallbacks just when required.
Diffstat (limited to 'actionpack/lib/action_view/lookup_context.rb')
-rw-r--r-- | actionpack/lib/action_view/lookup_context.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 82aebe1678..e259a78c5c 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -6,6 +6,9 @@ module ActionView class LookupContext #:nodoc: attr_reader :details, :view_paths + mattr_accessor :fallbacks + @@fallbacks = [FileSystemResolver.new(""), FileSystemResolver.new("/")] + class DetailsKey #:nodoc: attr_reader :details alias :eql? :equal? @@ -69,6 +72,19 @@ module ActionView end end + # Added fallbacks to the view paths. Useful in cases you are rendering a file. + def with_fallbacks + added_resolvers = 0 + self.class.fallbacks.each do |resolver| + next if view_paths.include?(resolver) + view_paths.push(resolver) + added_resolvers += 1 + end + yield + ensure + added_resolvers.times { view_paths.pop } + end + def find_template(name, prefix = nil, partial = false) @view_paths.find(name, details, prefix, partial || false, details_key) end |