Skip to content

Commit

Permalink
Simplify handling of absolute path templates. [#2276 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
thedarkone authored and josh committed Mar 24, 2009
1 parent 4c2f09f commit e3b166a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/paths.rb
Expand Up @@ -61,7 +61,7 @@ def find_template(original_template_path, format = nil, html_fallback = true)
end
end

return Template.new(original_template_path, original_template_path.to_s =~ /\A\// ? "" : ".") if File.file?(original_template_path)
return Template.new(original_template_path) if File.file?(original_template_path)

raise MissingTemplate.new(self, original_template_path, format)
end
Expand Down
11 changes: 8 additions & 3 deletions actionpack/lib/action_view/template.rb
Expand Up @@ -107,9 +107,8 @@ def self.exempt_from_layout(*extensions)
attr_accessor :locale, :name, :format, :extension
delegate :to_s, :to => :path

def initialize(template_path, load_path)
@template_path = template_path.dup
@load_path, @filename = load_path, File.join(load_path, template_path)
def initialize(template_path, load_path = nil)
@template_path, @load_path = template_path.dup, load_path
@base_path, @name, @locale, @format, @extension = split(template_path)
@base_path.to_s.gsub!(/\/$/, '') # Push to split method

Expand Down Expand Up @@ -180,6 +179,12 @@ def exempt_from_layout?
@@exempt_from_layout.any? { |exempted| path =~ exempted }
end

def filename
# no load_path means this is an "absolute pathed" template
load_path ? File.join(load_path, template_path) : template_path
end
memoize :filename

def source
File.read(filename)
end
Expand Down

0 comments on commit e3b166a

Please sign in to comment.