aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-29 17:21:31 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-29 17:51:06 +0100
commitcc2642b220958894c5a384530f32f622f76cd097 (patch)
treea696d3af738d16b7e693c4e3d6a1814ac89c4807 /actionpack
parent986a4e616be715e5c5a6ebbd25d339fa9bba4072 (diff)
downloadrails-cc2642b220958894c5a384530f32f622f76cd097.tar.gz
rails-cc2642b220958894c5a384530f32f622f76cd097.tar.bz2
rails-cc2642b220958894c5a384530f32f622f76cd097.zip
Added :format and :locale options to render.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb11
-rw-r--r--actionpack/test/abstract/render_test.rb41
2 files changed, 50 insertions, 2 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 40cac40ba7..ac407bda5e 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -160,11 +160,20 @@ module AbstractController
name = (options[:_template_name] || options[:action] || action_name).to_s
options[:_prefix] ||= _prefix if (options.keys & [:partial, :file, :template]).empty?
+ details = _normalize_details(options)
+
options[:_template] ||= with_template_cache(name) do
- find_template(name, { :formats => formats }, options)
+ find_template(name, details, options)
end
end
+ def _normalize_details(options)
+ details = { :formats => formats }
+ details[:formats] = Array(options[:format]) if options[:format]
+ details[:locale] = Array(options[:locale]) if options[:locale]
+ details
+ end
+
def find_template(name, details, options)
view_paths.find(name, details, options[:_prefix], options[:_partial])
end
diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb
index 9a0a140bee..db924633ca 100644
--- a/actionpack/test/abstract/render_test.rb
+++ b/actionpack/test/abstract/render_test.rb
@@ -17,7 +17,11 @@ module AbstractController
"renderer/symbol.erb" => "With Symbol",
"renderer/template_name.erb" => "With Template Name",
"string/with_path.erb" => "With String With Path",
- "some/file.erb" => "With File"
+ "some/file.erb" => "With File",
+ "with_format.html.erb" => "With html format",
+ "with_format.xml.erb" => "With xml format",
+ "with_locale.en.erb" => "With en locale",
+ "with_locale.pl.erb" => "With pl locale"
)]
def template
@@ -59,6 +63,22 @@ module AbstractController
def object
render :_template => ActionView::Template::Text.new("With Object")
end
+
+ def with_html_format
+ render :template => "with_format", :format => :html
+ end
+
+ def with_xml_format
+ render :template => "with_format", :format => :xml
+ end
+
+ def with_en_locale
+ render :template => "with_locale"
+ end
+
+ def with_pl_locale
+ render :template => "with_locale", :locale => :pl
+ end
end
class TestRenderer < ActiveSupport::TestCase
@@ -117,6 +137,25 @@ module AbstractController
assert_equal "With Object", @controller.response_body
end
+ def test_render_with_html_format
+ @controller.process(:with_html_format)
+ assert_equal "With html format", @controller.response_body
+ end
+
+ def test_render_with_xml_format
+ @controller.process(:with_xml_format)
+ assert_equal "With xml format", @controller.response_body
+ end
+
+ def test_render_with_en_locale
+ @controller.process(:with_en_locale)
+ assert_equal "With en locale", @controller.response_body
+ end
+
+ def test_render_with_pl_locale
+ @controller.process(:with_pl_locale)
+ assert_equal "With pl locale", @controller.response_body
+ end
end
end
end