aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/paths.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-07 12:49:27 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-07 12:49:27 +0100
commit6e0443fd433393dc1967fab4f4fa06dc2b3c02fd (patch)
tree32feba93812d013957c5ba7b2d2a283162238e0d /actionpack/lib/action_view/paths.rb
parenta424f199a9143e7ea451ba6f5e7dc54eb6103988 (diff)
downloadrails-6e0443fd433393dc1967fab4f4fa06dc2b3c02fd.tar.gz
rails-6e0443fd433393dc1967fab4f4fa06dc2b3c02fd.tar.bz2
rails-6e0443fd433393dc1967fab4f4fa06dc2b3c02fd.zip
First take on ViewPaths clean up.
Diffstat (limited to 'actionpack/lib/action_view/paths.rb')
-rw-r--r--actionpack/lib/action_view/paths.rb78
1 files changed, 19 insertions, 59 deletions
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb
index 6e55d69d00..459b6bba54 100644
--- a/actionpack/lib/action_view/paths.rb
+++ b/actionpack/lib/action_view/paths.rb
@@ -1,46 +1,17 @@
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
+ %w(initialize << concat insert push unshift).each do |method|
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
+ def #{method}(*args)
+ super
+ typecast!
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) })
+ METHOD
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)
+ each do |resolver|
+ if template = resolver.find(path, details, prefix, partial)
return template
end
end
@@ -48,33 +19,22 @@ module ActionView #:nodoc:
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path}", details, 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
+ def exists?(path, details = {}, prefix = nil, partial = false)
+ each do |resolver|
+ if resolver.find(path, details, prefix, partial)
+ return true
+ end
+ 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(/^\//, '')
+ protected
- 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
+ def typecast!
+ each_with_index do |path, i|
+ next unless path.is_a?(String)
+ self[i] = FileSystemResolverWithFallback.new(path)
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