public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Move missing template logic to ActionView
lifo (author)
Sat Apr 19 10:52:14 -0700 2008
commit  ef4c65088fb907fc819e6b5d83d284c38cdaabfc
tree    e4e674e270a04a71deb0aa5741ae6c4f16b847db
parent  534c6b2444970d59aea654aa3c6aeb41c206d14d
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Move missing template logic to ActionView. [Pratik]
0
+
0
 * Introduce ActionView::InlineTemplate class. [Pratik]
0
 
0
 * Automatically parse posted JSON content for Mime::JSON requests. [rick]
...
16
17
18
19
20
21
22
23
24
...
1105
1106
1107
1108
1109
1110
1111
...
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
...
16
17
18
 
 
 
19
20
21
...
1102
1103
1104
 
1105
1106
1107
...
1261
1262
1263
 
 
 
 
 
 
 
 
 
1264
1265
1266
0
@@ -16,9 +16,6 @@
0
   class SessionRestoreError < ActionControllerError #:nodoc:
0
   end
0
 
0
- class MissingTemplate < ActionControllerError #:nodoc:
0
- end
0
-
0
   class RenderError < ActionControllerError #:nodoc:
0
   end
0
 
0
@@ -1105,7 +1102,6 @@
0
     private
0
       def render_for_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc:
0
         add_variables_to_assigns
0
- assert_existence_of_template_file(template_path) if use_full_path
0
         logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
0
         render_for_text(@template.render_file(template_path, use_full_path, locals), status)
0
       end
0
@@ -1265,15 +1261,6 @@
0
         extension = @template && @template.finder.pick_template_extension(template_name)
0
         name_with_extension = !template_name.include?('.') && extension ? "#{template_name}.#{extension}" : template_name
0
         @@exempt_from_layout.any? { |ext| name_with_extension =~ ext }
0
- end
0
-
0
- def assert_existence_of_template_file(template_name)
0
- unless template_exists?(template_name) || ignore_missing_templates
0
- full_template_path = template_name.include?('.') ? template_name : "#{template_name}.#{@template.template_format}.erb"
0
- display_paths = view_paths.join(':')
0
- template_type = (template_name =~ /layouts/i) ? 'layout' : 'template'
0
- raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}")
0
- end
0
       end
0
 
0
       def default_template_name(action_name = self.action_name)
...
244
245
246
247
248
249
 
250
251
252
...
244
245
246
 
 
 
247
248
249
250
0
@@ -244,9 +244,7 @@
0
       def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc:
0
         template_with_options = options.is_a?(Hash)
0
 
0
- if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options))
0
- assert_existence_of_template_file(layout)
0
-
0
+ if (layout = pick_layout(template_with_options, options)) && apply_layout?(template_with_options, options)
0
           options = options.merge :layout => false if template_with_options
0
           logger.info("Rendering template within #{layout}") if logger
0
 
...
26
27
28
29
 
30
31
32
...
26
27
28
 
29
30
31
32
0
@@ -26,7 +26,7 @@
0
 
0
     DEFAULT_RESCUE_TEMPLATE = 'diagnostics'
0
     DEFAULT_RESCUE_TEMPLATES = {
0
- 'ActionController::MissingTemplate' => 'missing_template',
0
+ 'ActionView::MissingTemplate' => 'missing_template',
0
       'ActionController::RoutingError' => 'routing_error',
0
       'ActionController::UnknownAction' => 'unknown_action',
0
       'ActionView::TemplateError' => 'template_error'
...
1
2
3
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
0
@@ -1,6 +1,9 @@
0
 module ActionView #:nodoc:
0
   class ActionViewError < StandardError #:nodoc:
0
   end
0
+
0
+ class MissingTemplate < ActionViewError #:nodoc:
0
+ end
0
 
0
   # Action View templates can be written in three ways. If the template file has a +.erb+ (or +.rhtml+) extension then it uses a mixture of ERb
0
   # (included in Ruby) and HTML. If the template file has a +.builder+ (or +.rxml+) extension then Jim Weirich's Builder::XmlMarkup library is used.
...
54
55
56
57
58
59
 
 
60
61
62
...
64
65
66
67
68
69
 
 
 
 
 
 
 
 
70
71
72
...
54
55
56
 
 
 
57
58
59
60
61
...
63
64
65
 
 
 
66
67
68
69
70
71
72
73
74
75
76
0
@@ -54,9 +54,8 @@
0
           @filename = @finder.pick_template(@path_without_extension, @extension)
0
         else
0
           @extension = @finder.pick_template_extension(@path).to_s
0
- unless @extension
0
- raise ActionViewError, "No template found for #{@path} in #{@finder.view_paths.inspect}"
0
- end
0
+ raise_missing_template_exception unless @extension
0
+
0
           @filename = @finder.pick_template(@path, @extension)
0
           @extension = @extension.gsub(/^.+\./, '') # strip off any formats
0
         end
0
@@ -64,9 +63,14 @@
0
         @filename = @path
0
       end
0
 
0
- if @filename.blank?
0
- raise ActionViewError, "Couldn't find template file for #{@path} in #{@finder.view_paths.inspect}"
0
- end
0
+ raise_missing_template_exception if @filename.blank?
0
+ end
0
+
0
+ def raise_missing_template_exception
0
+ full_template_path = @path.include?('.') ? @path : "#{@path}.#{@view.template_format}.erb"
0
+ display_paths = @finder.view_paths.join(':')
0
+ template_type = (@path =~ /layouts/i) ? 'layout' : 'template'
0
+ raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}")
0
     end
0
 
0
     # Template Handlers
...
37
38
39
40
 
41
42
43
...
37
38
39
 
40
41
42
43
0
@@ -37,7 +37,7 @@
0
     end
0
 
0
     def rescue_action(e)
0
- raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
0
+ raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output
0
     end
0
   end
0
 
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@
0
     end
0
 
0
     def rescue_action(e)
0
- raise unless ActionController::MissingTemplate === e
0
+ raise unless ActionView::MissingTemplate === e
0
     end
0
 
0
     # methods for test_sweep_after_halted_filter_chain
...
216
217
218
219
 
220
221
222
...
216
217
218
 
219
220
221
222
0
@@ -216,7 +216,7 @@
0
     @controller = SetsNonExistentLayoutFile.new
0
     get :hello
0
     @response.template.class.module_eval { attr_accessor :exception }
0
- assert_equal ActionController::MissingTemplate, @response.template.exception.class
0
+ assert_equal ActionView::MissingTemplate, @response.template.exception.class
0
   end
0
 end
0
 
...
468
469
470
471
 
472
473
474
...
468
469
470
 
471
472
473
474
0
@@ -468,7 +468,7 @@
0
     assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
0
 
0
     @request.env["HTTP_ACCEPT"] = "text/iphone"
0
- assert_raises(ActionController::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
0
+ assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
0
   end
0
 end
0
 
...
652
653
654
655
 
656
657
658
...
787
788
789
790
 
791
792
793
...
652
653
654
 
655
656
657
658
...
787
788
789
 
790
791
792
793
0
@@ -652,7 +652,7 @@
0
   end
0
 
0
   def test_bad_render_to_string_still_throws_exception
0
- assert_raises(ActionController::MissingTemplate) { get :render_to_string_with_exception }
0
+ assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
0
   end
0
   
0
   def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
0
@@ -787,7 +787,7 @@
0
   end
0
   
0
   def test_render_missing_partial_template
0
- assert_raises(ActionView::ActionViewError) do
0
+ assert_raises(ActionView::MissingTemplate) do
0
       get :missing_partial
0
     end
0
   end
...
279
280
281
282
 
283
284
285
...
279
280
281
 
282
283
284
285
0
@@ -279,7 +279,7 @@
0
     assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates.default
0
     assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates[Exception.new]
0
 
0
- assert_equal 'missing_template', templates[ActionController::MissingTemplate.name]
0
+ assert_equal 'missing_template', templates[ActionView::MissingTemplate.name]
0
     assert_equal 'routing_error', templates[ActionController::RoutingError.name]
0
     assert_equal 'unknown_action', templates[ActionController::UnknownAction.name]
0
     assert_equal 'template_error', templates[ActionView::TemplateError.name]
...
82
83
84
85
 
86
87
88
...
82
83
84
 
85
86
87
88
0
@@ -82,7 +82,7 @@
0
 
0
     def test_xml
0
       @view.template_format = :xml
0
- assert_raise ActionView::ActionViewError do
0
+ assert_raise ActionView::MissingTemplate do
0
         ActionView::PartialTemplate.new(@view, @path, nil)
0
       end
0
     end

Comments

    No one has commented yet.