diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-27 21:04:24 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-29 10:45:06 +0100 |
commit | 34905673a3018edeff71aafeceb64e487304d31d (patch) | |
tree | 02264b718d54ffb2a513ad9a05bf2c7a6f572589 /actionpack/lib/action_view | |
parent | 6fa9957e0e83f327aaffe34679a5752fc2343fae (diff) | |
download | rails-34905673a3018edeff71aafeceb64e487304d31d.tar.gz rails-34905673a3018edeff71aafeceb64e487304d31d.tar.bz2 rails-34905673a3018edeff71aafeceb64e487304d31d.zip |
Revert "Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache." as it killed dev mode reloading.
This reverts commit 4d910b033379727e5e7355590c50c72fc75e56db.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/paths.rb | 67 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderable.rb | 2 |
3 files changed, 21 insertions, 52 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index da1f283deb..7697848713 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -322,7 +322,9 @@ module ActionView #:nodoc: end # OPTIMIZE: Checks to lookup template in view path - if template = self.view_paths.find_template(template_file_name, template_format) + if template = self.view_paths["#{template_file_name}.#{template_format}"] + template + elsif template = self.view_paths[template_file_name] template elsif (first_render = @_render_stack.first) && first_render.respond_to?(:format_and_extension) && (template = self.view_paths["#{template_file_name}.#{first_render.format_and_extension}"]) diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index f01ed9e6e0..d6bf2137af 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -40,10 +40,18 @@ module ActionView #:nodoc: end class Path #:nodoc: + def self.eager_load_templates! + @eager_load_templates = true + end + + def self.eager_load_templates? + @eager_load_templates || false + end + attr_reader :path, :paths delegate :to_s, :to_str, :hash, :inspect, :to => :path - def initialize(path, load = false) + def initialize(path, load = true) raise ArgumentError, "path already is a Path class" if path.is_a?(Path) @path = path.freeze reload! if load @@ -57,35 +65,9 @@ module ActionView #:nodoc: to_str == path.to_str end - # Returns a ActionView::Template object for the given path string. The - # input path should be relative to the view path directory, - # +hello/index.html.erb+. This method also has a special exception to - # match partial file names without a handler extension. So - # +hello/index.html+ will match the first template it finds with a - # known template extension, +hello/index.html.erb+. Template extensions - # should not be confused with format extensions +html+, +js+, +xml+, - # etc. A format must be supplied to match a formated file. +hello/index+ - # will never match +hello/index.html.erb+. - # - # This method also has two different implementations, one that is "lazy" - # and makes file system calls every time and the other is cached, - # "eager" which looks up the template in an in memory index. The "lazy" - # version is designed for development where you want to automatically - # find new templates between requests. The "eager" version is designed - # for production mode and it is much faster but requires more time - # upfront to build the file index. def [](path) - if loaded? - @paths[path] - else - Dir.glob("#{@path}/#{path}*").each do |file| - template = create_template(file) - if path == template.path_without_extension || path == template.path - return template - end - end - nil - end + raise "Unloaded view path! #{@path}" unless @loaded + @paths[path] end def loaded? @@ -102,7 +84,9 @@ module ActionView #:nodoc: @paths = {} templates_in_path do |template| - template.freeze + # Eager load memoized methods and freeze cached template + template.freeze if self.class.eager_load_templates? + @paths[template.path] = template @paths[template.path_without_extension] ||= template end @@ -114,13 +98,11 @@ module ActionView #:nodoc: private def templates_in_path (Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |file| - yield create_template(file) unless File.directory?(file) + unless File.directory?(file) + yield Template.new(file.split("#{self}/").last, self) + end end end - - def create_template(file) - Template.new(file.split("#{self}/").last, self) - end end def load @@ -139,20 +121,5 @@ module ActionView #:nodoc: end nil end - - def find_template(path, *formats) - if formats && formats.first == :all - formats = Mime::EXTENSION_LOOKUP.values.map(&:to_sym) - end - formats.each do |format| - if template = self["#{path}.#{format}"] - return template - end - end - if template = self[path] - return template - end - nil - end end end diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index c04399f2c9..5ff5569db6 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -96,7 +96,7 @@ module ActionView # The template will be compiled if the file has not been compiled yet, or # if local_assigns has a new key, which isn't supported by the compiled code yet. def recompile?(symbol) - !(frozen? && Base::CompiledTemplates.method_defined?(symbol)) + !(ActionView::PathSet::Path.eager_load_templates? && Base::CompiledTemplates.method_defined?(symbol)) end end end |