2008-07-12 19:33:46 +00:00
|
|
|
module ActionView #:nodoc:
|
2008-08-21 05:28:25 +00:00
|
|
|
class PathSet < Array #:nodoc:
|
2008-07-12 19:33:46 +00:00
|
|
|
def self.type_cast(obj)
|
2008-07-12 20:31:50 +00:00
|
|
|
if obj.is_a?(String)
|
2009-02-12 18:35:14 +00:00
|
|
|
if Base.cache_template_loading?
|
|
|
|
Template::EagerPath.new(obj.to_s)
|
|
|
|
else
|
|
|
|
ReloadableTemplate::ReloadablePath.new(obj.to_s)
|
|
|
|
end
|
2008-07-12 20:31:50 +00:00
|
|
|
else
|
|
|
|
obj
|
|
|
|
end
|
2008-07-12 19:33:46 +00:00
|
|
|
end
|
2009-02-12 18:35:14 +00:00
|
|
|
|
2008-08-21 05:28:25 +00:00
|
|
|
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
|
2009-02-12 18:35:14 +00:00
|
|
|
|
|
|
|
def load!
|
|
|
|
each(&:load!)
|
|
|
|
end
|
2008-08-21 05:28:25 +00:00
|
|
|
|
2009-02-12 18:35:14 +00:00
|
|
|
def find_template(original_template_path, format = nil)
|
|
|
|
return original_template_path if original_template_path.respond_to?(:render)
|
|
|
|
template_path = original_template_path.sub(/^\//, '')
|
2008-11-28 17:18:28 +00:00
|
|
|
|
2008-12-21 23:23:53 +00:00
|
|
|
each do |load_path|
|
2009-01-26 04:50:02 +00:00
|
|
|
if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"])
|
|
|
|
return template
|
|
|
|
elsif format && (template = load_path["#{template_path}.#{format}"])
|
|
|
|
return template
|
|
|
|
elsif template = load_path["#{template_path}.#{I18n.locale}"]
|
2008-12-21 23:23:53 +00:00
|
|
|
return template
|
|
|
|
elsif template = load_path[template_path]
|
2008-11-28 17:18:28 +00:00
|
|
|
return template
|
2009-01-27 20:09:11 +00:00
|
|
|
# Try to find html version if the format is javascript
|
2009-02-07 17:37:02 +00:00
|
|
|
elsif format == :js && template = load_path["#{template_path}.#{I18n.locale}.html"]
|
|
|
|
return template
|
2009-01-27 20:09:11 +00:00
|
|
|
elsif format == :js && template = load_path["#{template_path}.html"]
|
|
|
|
return template
|
2008-11-28 17:18:28 +00:00
|
|
|
end
|
|
|
|
end
|
2008-12-21 23:23:53 +00:00
|
|
|
|
2009-02-12 18:35:14 +00:00
|
|
|
return Template.new(original_template_path, original_template_path =~ /\A\// ? "" : ".") if File.file?(original_template_path)
|
2009-02-09 20:20:30 +00:00
|
|
|
|
2009-02-12 18:35:14 +00:00
|
|
|
raise MissingTemplate.new(self, original_template_path, format)
|
2008-11-28 17:18:28 +00:00
|
|
|
end
|
2008-07-12 19:33:46 +00:00
|
|
|
end
|
|
|
|
end
|