Skip to content
This repository
Browse code

Simplify handling of absolute path templates. [#2276 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit d2e6a0fbc30d3fd03e7945306d18ed8ced8b20cf 1 parent dace54b
authored josh committed
2  actionpack/lib/action_view/paths.rb
@@ -61,7 +61,7 @@ def find_template(original_template_path, format = nil, html_fallback = true)
61 61
         end
62 62
       end
63 63
 
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)
65 65
 
66 66
       raise MissingTemplate.new(self, original_template_path, format)
67 67
     end
11  actionpack/lib/action_view/template.rb
@@ -107,9 +107,8 @@ def self.exempt_from_layout(*extensions)
107 107
     attr_accessor :locale, :name, :format, :extension
108 108
     delegate :to_s, :to => :path
109 109
 
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
113 112
       @base_path, @name, @locale, @format, @extension = split(template_path)
114 113
       @base_path.to_s.gsub!(/\/$/, '') # Push to split method
115 114
 
@@ -180,6 +179,12 @@ def exempt_from_layout?
180 179
       @@exempt_from_layout.any? { |exempted| path =~ exempted }
181 180
     end
182 181
 
  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
+
183 188
     def source
184 189
       File.read(filename)
185 190
     end

0 notes on commit d2e6a0f

Please sign in to comment.
Something went wrong with that request. Please try again.