diff options
author | José Valim <jose.valim@gmail.com> | 2010-03-19 17:20:15 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-19 17:20:20 +0100 |
commit | f28d856cece877d1b2f306f54aeb12cce1db1023 (patch) | |
tree | f2ca547068d20558acc80433ef5f667f61f78737 /actionpack/lib/action_view/template/resolver.rb | |
parent | fbe35656a95228f760a2cd09676423ba41fe70ab (diff) | |
download | rails-f28d856cece877d1b2f306f54aeb12cce1db1023.tar.gz rails-f28d856cece877d1b2f306f54aeb12cce1db1023.tar.bz2 rails-f28d856cece877d1b2f306f54aeb12cce1db1023.zip |
Improve performance of the rendering stack by freezing formats as a sign that they shouldn't be further modified.
Diffstat (limited to 'actionpack/lib/action_view/template/resolver.rb')
-rw-r--r-- | actionpack/lib/action_view/template/resolver.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index 28cd30a959..8e8afaa43f 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -1,6 +1,5 @@ require "pathname" require "active_support/core_ext/class" -require "active_support/core_ext/array/wrap" require "action_view/template" module ActionView @@ -57,7 +56,7 @@ module ActionView def find_templates(name, prefix, partial, details) path = build_path(name, prefix, partial, details) - query(path, EXTENSION_ORDER.map { |ext| details[ext] }) + query(path, EXTENSION_ORDER.map { |ext| details[ext] }, details[:formats]) end def build_path(name, prefix, partial, details) @@ -67,7 +66,7 @@ module ActionView path end - def query(path, exts) + def query(path, exts, formats) query = File.join(@path, path) exts.each do |ext| @@ -75,18 +74,24 @@ module ActionView end Dir[query].reject { |p| File.directory?(p) }.map do |p| - handler, format = extract_handler_and_format(p) + handler, format = extract_handler_and_format(p, formats) Template.new(File.read(p), File.expand_path(p), handler, :virtual_path => path, :format => format) end end - def extract_handler_and_format(path) + # Extract handler and formats from path. If a format cannot be a found neither + # from the path, or the handler, we should return the array of formats given + # to the resolver. + def extract_handler_and_format(path, default_formats) pieces = File.basename(path).split(".") pieces.shift - handler = Template.handler_class_for_extension(pieces.pop) - format = pieces.last && Mime[pieces.last] && pieces.pop.to_sym + handler = Template.handler_class_for_extension(pieces.pop) + format = pieces.last && Mime[pieces.last] && pieces.pop.to_sym + format ||= handler.default_format if handler.respond_to?(:default_format) + format ||= default_formats + [handler, format] end end |