aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-04-19 18:52:14 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-04-19 18:59:13 +0100
commitef4c65088fb907fc819e6b5d83d284c38cdaabfc (patch)
treee4e674e270a04a71deb0aa5741ae6c4f16b847db
parent534c6b2444970d59aea654aa3c6aeb41c206d14d (diff)
downloadrails-ef4c65088fb907fc819e6b5d83d284c38cdaabfc.tar.gz
rails-ef4c65088fb907fc819e6b5d83d284c38cdaabfc.tar.bz2
rails-ef4c65088fb907fc819e6b5d83d284c38cdaabfc.zip
Move missing template logic to ActionView
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/base.rb13
-rw-r--r--actionpack/lib/action_controller/layout.rb4
-rw-r--r--actionpack/lib/action_controller/rescue.rb2
-rw-r--r--actionpack/lib/action_view/base.rb3
-rw-r--r--actionpack/lib/action_view/template.rb16
-rw-r--r--actionpack/test/controller/cookie_test.rb2
-rw-r--r--actionpack/test/controller/flash_test.rb2
-rw-r--r--actionpack/test/controller/layout_test.rb2
-rw-r--r--actionpack/test/controller/mime_responds_test.rb2
-rw-r--r--actionpack/test/controller/new_render_test.rb4
-rw-r--r--actionpack/test/controller/rescue_test.rb2
-rw-r--r--actionpack/test/template/template_object_test.rb2
13 files changed, 25 insertions, 31 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index e8cef9eb71..4694c0e996 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Move missing template logic to ActionView. [Pratik]
+
* Introduce ActionView::InlineTemplate class. [Pratik]
* Automatically parse posted JSON content for Mime::JSON requests. [rick]
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index f620c442fd..32df035871 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -16,9 +16,6 @@ module ActionController #:nodoc:
class SessionRestoreError < ActionControllerError #:nodoc:
end
- class MissingTemplate < ActionControllerError #:nodoc:
- end
-
class RenderError < ActionControllerError #:nodoc:
end
@@ -1105,7 +1102,6 @@ module ActionController #:nodoc:
private
def render_for_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc:
add_variables_to_assigns
- assert_existence_of_template_file(template_path) if use_full_path
logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
render_for_text(@template.render_file(template_path, use_full_path, locals), status)
end
@@ -1267,15 +1263,6 @@ module ActionController #:nodoc:
@@exempt_from_layout.any? { |ext| name_with_extension =~ ext }
end
- def assert_existence_of_template_file(template_name)
- unless template_exists?(template_name) || ignore_missing_templates
- full_template_path = template_name.include?('.') ? template_name : "#{template_name}.#{@template.template_format}.erb"
- display_paths = view_paths.join(':')
- template_type = (template_name =~ /layouts/i) ? 'layout' : 'template'
- raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}")
- end
- end
-
def default_template_name(action_name = self.action_name)
if action_name
action_name = action_name.to_s
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index 5484add3b5..b5b59f2d7c 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -244,9 +244,7 @@ module ActionController #:nodoc:
def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc:
template_with_options = options.is_a?(Hash)
- if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options))
- assert_existence_of_template_file(layout)
-
+ if (layout = pick_layout(template_with_options, options)) && apply_layout?(template_with_options, options)
options = options.merge :layout => false if template_with_options
logger.info("Rendering template within #{layout}") if logger
diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb
index f5ad04532b..d4d561bdb7 100644
--- a/actionpack/lib/action_controller/rescue.rb
+++ b/actionpack/lib/action_controller/rescue.rb
@@ -26,7 +26,7 @@ module ActionController #:nodoc:
DEFAULT_RESCUE_TEMPLATE = 'diagnostics'
DEFAULT_RESCUE_TEMPLATES = {
- 'ActionController::MissingTemplate' => 'missing_template',
+ 'ActionView::MissingTemplate' => 'missing_template',
'ActionController::RoutingError' => 'routing_error',
'ActionController::UnknownAction' => 'unknown_action',
'ActionView::TemplateError' => 'template_error'
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index f001b81eca..e57c447682 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -1,6 +1,9 @@
module ActionView #:nodoc:
class ActionViewError < StandardError #:nodoc:
end
+
+ class MissingTemplate < ActionViewError #:nodoc:
+ end
# 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
# (included in Ruby) and HTML. If the template file has a +.builder+ (or +.rxml+) extension then Jim Weirich's Builder::XmlMarkup library is used.
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 985aa090e5..bc3d8d5e52 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -54,9 +54,8 @@ module ActionView #:nodoc:
@filename = @finder.pick_template(@path_without_extension, @extension)
else
@extension = @finder.pick_template_extension(@path).to_s
- unless @extension
- raise ActionViewError, "No template found for #{@path} in #{@finder.view_paths.inspect}"
- end
+ raise_missing_template_exception unless @extension
+
@filename = @finder.pick_template(@path, @extension)
@extension = @extension.gsub(/^.+\./, '') # strip off any formats
end
@@ -64,9 +63,14 @@ module ActionView #:nodoc:
@filename = @path
end
- if @filename.blank?
- raise ActionViewError, "Couldn't find template file for #{@path} in #{@finder.view_paths.inspect}"
- end
+ raise_missing_template_exception if @filename.blank?
+ end
+
+ def raise_missing_template_exception
+ full_template_path = @path.include?('.') ? @path : "#{@path}.#{@view.template_format}.erb"
+ display_paths = @finder.view_paths.join(':')
+ template_type = (@path =~ /layouts/i) ? 'layout' : 'template'
+ raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}")
end
# Template Handlers
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
index 0483fe918a..42f3bd26a4 100644
--- a/actionpack/test/controller/cookie_test.rb
+++ b/actionpack/test/controller/cookie_test.rb
@@ -37,7 +37,7 @@ class CookieTest < Test::Unit::TestCase
end
def rescue_action(e)
- raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
+ raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output
end
end
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
index f672f2f427..e562531bf3 100644
--- a/actionpack/test/controller/flash_test.rb
+++ b/actionpack/test/controller/flash_test.rb
@@ -52,7 +52,7 @@ class FlashTest < Test::Unit::TestCase
end
def rescue_action(e)
- raise unless ActionController::MissingTemplate === e
+ raise unless ActionView::MissingTemplate === e
end
# methods for test_sweep_after_halted_filter_chain
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 145543a357..3dc311b78a 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -216,7 +216,7 @@ class LayoutExceptionRaised < Test::Unit::TestCase
@controller = SetsNonExistentLayoutFile.new
get :hello
@response.template.class.module_eval { attr_accessor :exception }
- assert_equal ActionController::MissingTemplate, @response.template.exception.class
+ assert_equal ActionView::MissingTemplate, @response.template.exception.class
end
end
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index c34643ddd5..c617cb2e84 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -468,7 +468,7 @@ class MimeControllerTest < Test::Unit::TestCase
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
@request.env["HTTP_ACCEPT"] = "text/iphone"
- assert_raises(ActionController::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
+ assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
end
end
diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index 342e2e7f87..80cf09e5f3 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -652,7 +652,7 @@ EOS
end
def test_bad_render_to_string_still_throws_exception
- assert_raises(ActionController::MissingTemplate) { get :render_to_string_with_exception }
+ assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
end
def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
@@ -787,7 +787,7 @@ EOS
end
def test_render_missing_partial_template
- assert_raises(ActionView::ActionViewError) do
+ assert_raises(ActionView::MissingTemplate) do
get :missing_partial
end
end
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 011992474f..27fcc5e04c 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -279,7 +279,7 @@ class RescueTest < Test::Unit::TestCase
assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates.default
assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates[Exception.new]
- assert_equal 'missing_template', templates[ActionController::MissingTemplate.name]
+ assert_equal 'missing_template', templates[ActionView::MissingTemplate.name]
assert_equal 'routing_error', templates[ActionController::RoutingError.name]
assert_equal 'unknown_action', templates[ActionController::UnknownAction.name]
assert_equal 'template_error', templates[ActionView::TemplateError.name]
diff --git a/actionpack/test/template/template_object_test.rb b/actionpack/test/template/template_object_test.rb
index b3a33938cf..7adcde421f 100644
--- a/actionpack/test/template/template_object_test.rb
+++ b/actionpack/test/template/template_object_test.rb
@@ -82,7 +82,7 @@ class TemplateObjectTest < Test::Unit::TestCase
def test_xml
@view.template_format = :xml
- assert_raise ActionView::ActionViewError do
+ assert_raise ActionView::MissingTemplate do
ActionView::PartialTemplate.new(@view, @path, nil)
end
end