Skip to content

Commit e3b166a

Browse files
thedarkonejosh
authored andcommitted
Simplify handling of absolute path templates. [rails#2276 state:resolved]
Signed-off-by: Joshua Peek <[email protected]>
1 parent 4c2f09f commit e3b166a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

actionpack/lib/action_view/paths.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def find_template(original_template_path, format = nil, html_fallback = true)
6161
end
6262
end
6363

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

6666
raise MissingTemplate.new(self, original_template_path, format)
6767
end

actionpack/lib/action_view/template.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ def self.exempt_from_layout(*extensions)
107107
attr_accessor :locale, :name, :format, :extension
108108
delegate :to_s, :to => :path
109109

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

@@ -180,6 +179,12 @@ def exempt_from_layout?
180179
@@exempt_from_layout.any? { |exempted| path =~ exempted }
181180
end
182181

182+
def filename
183+
# no load_path means this is an "absolute pathed" template
184+
load_path ? File.join(load_path, template_path) : template_path
185+
end
186+
memoize :filename
187+
183188
def source
184189
File.read(filename)
185190
end

0 commit comments

Comments
 (0)