Ticket #2754: alternate_base_paths2.diff
| File alternate_base_paths2.diff, 4.2 kB (added by duane.johnson@gmail.com, 4 years ago) |
|---|
-
test/controller/render_test.rb
old new 92 92 def render_to_string_test 93 93 @foo = render_to_string :inline => "this is a test" 94 94 end 95 96 def alternate_only 97 # See if the alternate_base_path_* options works 98 end 95 99 96 100 def rescue_action(e) raise end 97 101 … … 240 244 @request.query_parameters[:local_name] = "Local David" 241 245 assert_equal "Goodbye, Local David", process_request.body 242 246 end 247 248 def test_alternate_base_paths_before 249 ActionView::Base.alternate_base_paths_before = 250 [File.dirname(__FILE__) + "/../fixtures/alternate_base_path/"] 251 252 @request.action = "hello_world" 253 assert_equal "Bonjour monde!", process_request.body 243 254 255 @request.action = "greeting" 256 assert_equal "<p>This is grand!</p>\n", process_request.body 257 258 ActionView::Base.alternate_base_paths_before = [] 259 end 260 261 def test_alternate_base_paths_after 262 ActionView::Base.alternate_base_paths_after = 263 [File.dirname(__FILE__) + "/../fixtures/alternate_base_path/"] 264 265 @request.action = "hello_world" 266 assert_equal "Hello world!", process_request.body 267 268 @request.action = "alternate_only" 269 assert_equal "Only the alternate base path has this file.", process_request.body 270 271 ActionView::Base.alternate_base_paths_after = [] 272 end 273 244 274 private 245 275 def process_request 246 276 TestController.process(@request, @response) -
test/fixtures/alternate_base_path/test/hello_world.rhtml
old new -
test/fixtures/alternate_base_path/test/alternate_only.rhtml
old new -
lib/action_view/base.rb
old new 138 138 # shortly. 139 139 @@local_assigns_support_string_keys = true 140 140 cattr_accessor :local_assigns_support_string_keys 141 142 # Specify alternate paths for view files, if any. The _before_ list will 143 # be checked before the primary @base_path while the _after_ list will be 144 # checked after. 145 @@alternate_base_paths_before = [] 146 @@alternate_base_paths_after = [] 147 cattr_accessor :alternate_base_paths_before, :alternate_base_paths_after 141 148 142 149 @@template_handlers = {} 143 150 … … 306 313 307 314 private 308 315 def full_template_path(template_path, extension) 309 "#{@base_path}/#{template_path}.#{extension}" 316 primary_location = "#{@base_path}/#{template_path}.#{extension}" 317 return primary_location if only_one_base_path? 318 319 # If there are alternate base paths to try, check them each one by one 320 all_base_paths.each do |try_path| 321 try_location = "#{try_path}/#{template_path}.#{extension}" 322 return try_location if template_is_cached_or_exists_on_disk?(try_location) 323 end 324 325 # If it cannot be found anywhere, return the default path, where the 326 # user *should* have put it. 327 return primary_location 310 328 end 329 330 def all_base_paths 331 @@alternate_base_paths_before + [ @base_path ] + @@alternate_base_paths_after 332 end 333 334 def only_one_base_path? 335 alternate_base_paths_before.empty? and alternate_base_paths_after.empty? 336 end 311 337 312 338 def template_exists?(template_path, extension) 313 339 file_path = full_template_path(template_path, extension) 340 template_is_cached_or_exists_on_disk?(file_path) 341 end 342 343 def template_is_cached_or_exists_on_disk?(file_path) 314 344 @@method_names.has_key?(file_path) || FileTest.exists?(file_path) 315 345 end 316 346