mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
c1304098cc
* A new module (ActiveSupport::Autoload) is provide that extends autoloading with new behavior. * All autoloads in modules that have extended ActiveSupport::Autoload will be eagerly required in threadsafe environments * Autoloads can optionally leave off the path if the path is the same as full_constant_name.underscore * It is possible to specify that a group of autoloads live under an additional path. For instance, all of ActionDispatch's middlewares are ActionDispatch::MiddlewareName, but they live under "action_dispatch/middlewares/middleware_name" * It is possible to specify that a group of autoloads are all found at the same path. For instance, a number of exceptions might all be declared there. * One consequence of this is that testing-related constants are not autoloaded. To get the testing helpers for a given component, require "component_name/test_case". For instance, "action_controller/test_case". * test_help.rb, which is automatically required by a Rails application's test helper, requires the test_case.rb for all active components, so this change will not be disruptive in existing or new applications.
80 lines
2.4 KiB
Ruby
80 lines
2.4 KiB
Ruby
module ActionView #:nodoc:
|
|
class PathSet < Array #:nodoc:
|
|
def self.type_cast(obj, cache = nil)
|
|
# TODO: Clean this up
|
|
if obj.is_a?(String)
|
|
if cache.nil?
|
|
cache = !defined?(Rails.application) || Rails.application.config.cache_classes
|
|
end
|
|
FileSystemResolverWithFallback.new(obj, :cache => cache)
|
|
else
|
|
obj
|
|
end
|
|
end
|
|
|
|
def initialize(*args)
|
|
super(*args).map! { |obj| self.class.type_cast(obj) }
|
|
end
|
|
|
|
def <<(obj)
|
|
super(self.class.type_cast(obj))
|
|
end
|
|
|
|
def concat(array)
|
|
super(array.map! { |obj| self.class.type_cast(obj) })
|
|
end
|
|
|
|
def insert(index, obj)
|
|
super(index, self.class.type_cast(obj))
|
|
end
|
|
|
|
def push(*objs)
|
|
super(*objs.map { |obj| self.class.type_cast(obj) })
|
|
end
|
|
|
|
def unshift(*objs)
|
|
super(*objs.map { |obj| self.class.type_cast(obj) })
|
|
end
|
|
|
|
def find(path, details = {}, prefix = nil, partial = false)
|
|
template_path = path
|
|
|
|
each do |load_path|
|
|
if template = load_path.find(template_path, details, prefix, partial)
|
|
return template
|
|
end
|
|
end
|
|
|
|
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path} - #{details.inspect} - partial: #{!!partial}")
|
|
end
|
|
|
|
def exists?(path, extension = nil, prefix = nil, partial = false)
|
|
template_path = path.sub(/^\//, '')
|
|
|
|
each do |load_path|
|
|
return true if template = load_path.find(template_path, extension, prefix, partial)
|
|
end
|
|
false
|
|
end
|
|
|
|
def find_template(original_template_path, format = nil, html_fallback = true)
|
|
return original_template_path if original_template_path.respond_to?(:render)
|
|
template_path = original_template_path.sub(/^\//, '')
|
|
|
|
each do |load_path|
|
|
if template = load_path.find(template_path, format)
|
|
return template
|
|
# Try to find html version if the format is javascript
|
|
elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
|
|
return template
|
|
elsif format == :js && html_fallback && template = load_path["#{template_path}.html"]
|
|
return template
|
|
end
|
|
end
|
|
|
|
return Template.new(original_template_path, original_template_path.to_s =~ /\A\// ? "" : ".") if File.file?(original_template_path)
|
|
|
|
raise MissingTemplate.new(self, original_template_path, format)
|
|
end
|
|
end
|
|
end
|