0
@@ -3,6 +3,12 @@ module ActionView #:nodoc:
0
class MissingTemplate < ActionViewError #:nodoc:
0
+ def initialize(paths, path, template_format = nil)
0
+ full_template_path = path.include?('.') ? path : "#{path}.erb"
0
+ display_paths = paths.join(':')
0
+ template_type = (path =~ /layouts/i) ? 'layout' : 'template'
0
+ super("Missing #{template_type} #{full_template_path} in view path #{display_paths}")
0
# Action View templates can be written in three ways. If the template file has a <tt>.erb</tt> (or <tt>.rhtml</tt>) extension then it uses a mixture of ERb
0
@@ -216,12 +222,14 @@ module ActionView #:nodoc:
0
attr_reader :view_paths
0
- @view_paths =
ViewLoadPaths.new(Array(paths))
0
+ @view_paths =
PathSet.new(Array(paths))
0
# Renders the template present at <tt>template_path</tt> (relative to the view_paths array).
0
# The hash in <tt>local_assigns</tt> is made available as local variables.
0
def render(options = {}, local_assigns = {}, &block) #:nodoc:
0
if options.is_a?(String)
0
render_file(options, nil, local_assigns)
0
elsif options == :update
0
@@ -270,21 +278,40 @@ module ActionView #:nodoc:
0
def file_exists?(template_path)
0
- view_paths.template_exists?(template_file_from_name(template_path))
0
+ pick_template(template_path) ? true : false
0
+ rescue MissingTemplate
0
# Gets the extension for an existing template with the given template_path.
0
# Returns the format with the extension if that template exists.
0
- # pick_template_extension('users/show')
0
+ # pick_template('users/show')
0
+ # # => 'users/show.html.erb'
0
- # pick_template_extension('users/legacy')
0
+ # pick_template('users/legacy')
0
+ # # => 'users/legacy.rhtml'
0
- def pick_template_extension(template_path)
0
- if template = template_file_from_name(template_path)
0
+ def pick_template(template_path)
0
+ path = template_path.sub(/^\//, '')
0
+ if m = path.match(/(.*)\.(\w+)$/)
0
+ template_file_name, template_file_extension = m[1], m[2]
0
+ template_file_name = path
0
+ # OPTIMIZE: Checks to lookup template in view path
0
+ if template = self.view_paths["#{template_file_name}.#{template_format}"]
0
+ elsif template = self.view_paths[template_file_name]
0
+ elsif first_render && template = self.view_paths["#{template_file_name}.#{first_render.extension}"]
0
+ elsif template_format == :js && template = self.view_paths["#{template_file_name}.html"]
0
+ @template_format = :html
0
+ Template.new(template_path, view_paths)
0
@@ -292,6 +319,10 @@ module ActionView #:nodoc:
0
# Renders the template present at <tt>template_path</tt>. The hash in <tt>local_assigns</tt>
0
# is made available as local variables.
0
def render_file(template_path, use_full_path = nil, local_assigns = {}) #:nodoc:
0
+ unless use_full_path == nil
0
+ ActiveSupport::Deprecation.warn("use_full_path option has been deprecated and has no affect.", caller)
0
if defined?(ActionMailer) && defined?(ActionMailer::Base) && controller.is_a?(ActionMailer::Base) && !template_path.include?("/")
0
raise ActionViewError, <<-END_ERROR
0
Due to changes in ActionMailer, you need to provide the mailer_name along with the template name.
0
@@ -305,11 +336,12 @@ module ActionView #:nodoc:
0
- Template.new(self, template_path, use_full_path, local_assigns).render_template
0
+ template = pick_template(template_path)
0
+ template.render_template(self, local_assigns)
0
def render_inline(text, local_assigns = {}, type = nil)
0
- InlineTemplate.new(
self, text, local_assigns, type).render0
+ InlineTemplate.new(
text, type).render(self, local_assigns)0
def wrap_content_for_layout(content)
0
@@ -333,32 +365,9 @@ module ActionView #:nodoc:
0
def execute(template, local_assigns = {})
0
- send(template.method
, local_assigns) do |*names|
0
+ send(template.method
(local_assigns), local_assigns) do |*names|
0
instance_variable_get "@content_for_#{names.first || 'layout'}"
0
- def template_file_from_name(template_name)
0
- template_name = TemplateFile.from_path(template_name)
0
- pick_template(template_name) unless template_name.extension
0
- def pick_template(file)
0
- if f = self.view_paths.find_template_file_for_path(file.dup_with_extension(template_format)) || file_from_first_render(file)
0
- elsif template_format == :js && f = self.view_paths.find_template_file_for_path(file.dup_with_extension(:html))
0
- @template_format = :html
0
- # Determine the template extension from the <tt>@first_render</tt> filename
0
- def file_from_first_render(file)
0
- if extension = File.basename(@first_render.to_s)[/^[^.]+\.(.+)$/, 1]
0
- file.dup_with_extension(extension)