Changeset 9119
- Timestamp:
- 03/28/08 20:21:52 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_view/template_finder.rb
r9089 r9119 132 132 # 133 133 def pick_template_extension(template_path) 134 find_template_extension_from_handler(template_path) || find_template_extension_from_first_render 134 if extension = find_template_extension_from_handler(template_path, @template.template_format) || find_template_extension_from_first_render 135 extension 136 elsif @template.template_format == :js && extension = find_template_extension_from_handler(template_path, :html) 137 @template.template_format = :html 138 extension 139 end 135 140 end 136 141 137 def find_template_extension_from_handler(template_path )138 formatted_template_path = "#{template_path}.#{ @template.template_format}"142 def find_template_extension_from_handler(template_path, template_format = @template.template_format) 143 formatted_template_path = "#{template_path}.#{template_format}" 139 144 140 145 view_paths.each do |path| 141 146 if (extensions = @@file_extension_cache[path][formatted_template_path]).any? 142 return "#{ @template.template_format}.#{extensions.first}"147 return "#{template_format}.#{extensions.first}" 143 148 elsif (extensions = @@file_extension_cache[path][template_path]).any? 144 149 return extensions.first.to_s trunk/actionpack/test/template/template_object_test.rb
r8976 r9119 60 60 end 61 61 62 class PartialTemplateFallbackTest < Test::Unit::TestCase 63 def setup 64 @view = ActionView::Base.new(LOAD_PATH_ROOT) 65 @path = 'test/layout_for_partial' 66 end 67 68 def test_default 69 template = ActionView::PartialTemplate.new(@view, @path, nil) 70 assert_equal 'test/_layout_for_partial', template.path 71 assert_equal 'erb', template.extension 72 assert_equal :html, @view.template_format 73 end 74 75 def test_js 76 @view.template_format = :js 77 template = ActionView::PartialTemplate.new(@view, @path, nil) 78 assert_equal 'test/_layout_for_partial', template.path 79 assert_equal 'erb', template.extension 80 assert_equal :html, @view.template_format 81 end 82 83 def test_xml 84 @view.template_format = :xml 85 assert_raise ActionView::ActionViewError do 86 ActionView::PartialTemplate.new(@view, @path, nil) 87 end 88 end 89 end 62 90 end