Load view path cache after plugins and gems.

This commit is contained in:
Joshua Peek
2008-07-23 10:41:28 -05:00
parent db1bac796e
commit 97a954bf1d
2 changed files with 25 additions and 6 deletions

View File

@@ -27,11 +27,10 @@ module ActionView #:nodoc:
attr_reader :path, :paths
delegate :to_s, :to_str, :hash, :inspect, :to => :path
def initialize(path)
def initialize(path, load = true)
raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
@path = path.freeze
reload!
reload! if load
end
def ==(path)
@@ -46,6 +45,14 @@ module ActionView #:nodoc:
@paths[path]
end
def loaded?
@loaded ? true : false
end
def load
reload! unless loaded?
end
# Rebuild load path directory cache
def reload!
@paths = {}
@@ -59,6 +66,7 @@ module ActionView #:nodoc:
end
@paths.freeze
@loaded = true
end
private
@@ -71,6 +79,10 @@ module ActionView #:nodoc:
end
end
def load
each { |path| path.load }
end
def reload!
each { |path| path.reload! }
end

View File

@@ -168,6 +168,9 @@ module Rails
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
load_observers
# Load view path cache
load_view_paths
# load application classes
load_application_classes
@@ -333,6 +336,12 @@ Run `rake gems:install` to install the missing gems.
end
end
def load_view_paths
ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
ActionMailer::Base.template_root.load
ActionController::Base.view_paths.load
end
# Eager load application classes
def load_application_classes
if configuration.cache_classes
@@ -428,9 +437,7 @@ Run `rake gems:install` to install the missing gems.
# paths have already been set, it is not changed, otherwise it is
# set to use Configuration#view_path.
def initialize_framework_views
ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
view_path = ActionView::PathSet::Path.new(configuration.view_path)
view_path = ActionView::PathSet::Path.new(configuration.view_path, false)
ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer)
ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
end