aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/view_load_paths.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-07-03 14:01:45 -0500
committerJoshua Peek <josh@joshpeek.com>2008-07-03 14:01:45 -0500
commit1a478923dc909bf7b6aea4f2ad49cbeee6dea259 (patch)
tree44cf634937e470352b6eafde6d0169ab0b5fbf96 /actionpack/lib/action_view/view_load_paths.rb
parent8a442e0d57fabedcaf3ded836cfc12f7067ead68 (diff)
downloadrails-1a478923dc909bf7b6aea4f2ad49cbeee6dea259.tar.gz
rails-1a478923dc909bf7b6aea4f2ad49cbeee6dea259.tar.bz2
rails-1a478923dc909bf7b6aea4f2ad49cbeee6dea259.zip
Reduce the number of callsites for new TemplateFiles
Diffstat (limited to 'actionpack/lib/action_view/view_load_paths.rb')
-rw-r--r--actionpack/lib/action_view/view_load_paths.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/view_load_paths.rb b/actionpack/lib/action_view/view_load_paths.rb
index f23ac665f1..6e439a009c 100644
--- a/actionpack/lib/action_view/view_load_paths.rb
+++ b/actionpack/lib/action_view/view_load_paths.rb
@@ -29,12 +29,10 @@ module ActionView #:nodoc:
@paths.freeze
end
- # Tries to find the extension for the template name.
- # If it does not it exist, tries again without the format extension
- # find_template_file_for_partial_path('users/show') => 'html.erb'
- # find_template_file_for_partial_path('users/legacy') => 'rhtml'
- def find_template_file_for_partial_path(file)
- @paths[file.path] || @paths[file.path_without_extension] || @paths[file.path_without_format_and_extension]
+ def find_template_file_for_partial_path(template_path, template_format)
+ @paths["#{template_path}.#{template_format}"] ||
+ @paths[template_path] ||
+ @paths[template_path.gsub(/\..*$/, '')]
end
private
@@ -81,10 +79,10 @@ module ActionView #:nodoc:
find { |path| path.paths[file.to_s] }
end
- def find_template_file_for_path(file)
- file = TemplateFile.from_path(file)
+ def find_template_file_for_path(template_path)
+ template_path_without_extension, template_extension = path_and_extension(template_path.to_s)
each do |path|
- if f = path.find_template_file_for_partial_path(file)
+ if f = path.find_template_file_for_partial_path(template_path_without_extension, template_extension)
return f
end
end
@@ -95,5 +93,11 @@ module ActionView #:nodoc:
def delete_paths!(paths)
paths.each { |p1| delete_if { |p2| p1.to_s == p2.to_s } }
end
+
+ # Splits the path and extension from the given template_path and returns as an array.
+ def path_and_extension(template_path)
+ template_path_without_extension = template_path.sub(/\.(\w+)$/, '')
+ [template_path_without_extension, $1]
+ end
end
end