From e0f834267642c526299189916ad9c97318c1b121 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 8 Apr 2007 17:16:36 +0000 Subject: Change default respond_to templates for xml and rjs formats. [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6507 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 5 +++++ actionpack/lib/action_controller/mime_responds.rb | 9 +++++---- actionpack/test/controller/mime_responds_test.rb | 2 +- .../test/fixtures/respond_to/all_types_with_layout.html.erb | 1 + actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs | 1 + actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml | 1 - actionpack/test/fixtures/respond_to/all_types_with_layout.rjs | 1 - actionpack/test/fixtures/respond_to/using_defaults.html.erb | 1 + actionpack/test/fixtures/respond_to/using_defaults.js.rjs | 1 + actionpack/test/fixtures/respond_to/using_defaults.rhtml | 1 - actionpack/test/fixtures/respond_to/using_defaults.rjs | 1 - actionpack/test/fixtures/respond_to/using_defaults.rxml | 1 - actionpack/test/fixtures/respond_to/using_defaults.xml.builder | 1 + .../fixtures/respond_to/using_defaults_with_type_list.html.erb | 1 + .../fixtures/respond_to/using_defaults_with_type_list.js.rjs | 1 + .../test/fixtures/respond_to/using_defaults_with_type_list.rhtml | 1 - .../test/fixtures/respond_to/using_defaults_with_type_list.rjs | 1 - .../test/fixtures/respond_to/using_defaults_with_type_list.rxml | 1 - .../respond_to/using_defaults_with_type_list.xml.builder | 1 + 19 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 actionpack/test/fixtures/respond_to/all_types_with_layout.html.erb create mode 100644 actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs delete mode 100644 actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml delete mode 100644 actionpack/test/fixtures/respond_to/all_types_with_layout.rjs create mode 100644 actionpack/test/fixtures/respond_to/using_defaults.html.erb create mode 100644 actionpack/test/fixtures/respond_to/using_defaults.js.rjs delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults.rhtml delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults.rjs delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults.rxml create mode 100644 actionpack/test/fixtures/respond_to/using_defaults.xml.builder create mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_type_list.html.erb create mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rhtml delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rjs delete mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rxml create mode 100644 actionpack/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 57fdda48a5..018a720c94 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,10 @@ *SVN* +* Change default respond_to templates for xml and rjs formats. [Rick] + + * Default xml template goes from #{action_name}.rxml => #{action_name}.xml.builder. + * Default rjs template goes from #{action_name}.rjs => #{action_name}.js.rjs. + * Fix WSOD due to modification of a formatted template extension so that requests to templates like 'foo.html.erb' fail on the second hit. [Rick] * Fix WSOD when template compilation fails [Rick] diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index ff07c3c12e..e4d1dbbccc 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -107,10 +107,11 @@ module ActionController #:nodoc: end class Responder #:nodoc: - DEFAULT_BLOCKS = [:html, :js, :xml].inject({}) do |blocks, ext| - template_extension = (ext == :html ? '' : ".r#{ext}") - blocks.update ext => %(Proc.new { render :action => "\#{action_name}#{template_extension}", :content_type => Mime::#{ext.to_s.upcase} }) - end + default_block_format = %(Proc.new { render :action => "\#{action_name}%s", :content_type => Mime::%s }) + DEFAULT_BLOCKS = {} + DEFAULT_BLOCKS[:html] = default_block_format % ['', 'HTML'] + DEFAULT_BLOCKS[:js] = default_block_format % ['.js.rjs', 'JS'] + DEFAULT_BLOCKS[:xml] = default_block_format % ['.xml.builder', 'XML'] def initialize(block_binding) @block_binding = block_binding diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 3a1df02a7f..aa31d5b649 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -351,6 +351,6 @@ class MimeControllerTest < Test::Unit::TestCase assert_equal "using_defaults", @response.body get :using_defaults, :format => "xml" - assert_equal "using_defaults.rxml", @response.body + assert_equal "using_defaults.xml.builder", @response.body end end diff --git a/actionpack/test/fixtures/respond_to/all_types_with_layout.html.erb b/actionpack/test/fixtures/respond_to/all_types_with_layout.html.erb new file mode 100644 index 0000000000..84a84049f8 --- /dev/null +++ b/actionpack/test/fixtures/respond_to/all_types_with_layout.html.erb @@ -0,0 +1 @@ +HTML for all_types_with_layout \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs b/actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs new file mode 100644 index 0000000000..b7aec7c505 --- /dev/null +++ b/actionpack/test/fixtures/respond_to/all_types_with_layout.js.rjs @@ -0,0 +1 @@ +page << "RJS for all_types_with_layout" \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml b/actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml deleted file mode 100644 index 84a84049f8..0000000000 --- a/actionpack/test/fixtures/respond_to/all_types_with_layout.rhtml +++ /dev/null @@ -1 +0,0 @@ -HTML for all_types_with_layout \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/all_types_with_layout.rjs b/actionpack/test/fixtures/respond_to/all_types_with_layout.rjs deleted file mode 100644 index b7aec7c505..0000000000 --- a/actionpack/test/fixtures/respond_to/all_types_with_layout.rjs +++ /dev/null @@ -1 +0,0 @@ -page << "RJS for all_types_with_layout" \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults.html.erb b/actionpack/test/fixtures/respond_to/using_defaults.html.erb new file mode 100644 index 0000000000..6769dd60bd --- /dev/null +++ b/actionpack/test/fixtures/respond_to/using_defaults.html.erb @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults.js.rjs b/actionpack/test/fixtures/respond_to/using_defaults.js.rjs new file mode 100644 index 0000000000..469fcd8e15 --- /dev/null +++ b/actionpack/test/fixtures/respond_to/using_defaults.js.rjs @@ -0,0 +1 @@ +page[:body].visual_effect :highlight \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults.rhtml b/actionpack/test/fixtures/respond_to/using_defaults.rhtml deleted file mode 100644 index 6769dd60bd..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults.rhtml +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults.rjs b/actionpack/test/fixtures/respond_to/using_defaults.rjs deleted file mode 100644 index 469fcd8e15..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults.rjs +++ /dev/null @@ -1 +0,0 @@ -page[:body].visual_effect :highlight \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults.rxml b/actionpack/test/fixtures/respond_to/using_defaults.rxml deleted file mode 100644 index 598d62e2fc..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults.rxml +++ /dev/null @@ -1 +0,0 @@ -xml.p "Hello world!" \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults.xml.builder b/actionpack/test/fixtures/respond_to/using_defaults.xml.builder new file mode 100644 index 0000000000..598d62e2fc --- /dev/null +++ b/actionpack/test/fixtures/respond_to/using_defaults.xml.builder @@ -0,0 +1 @@ +xml.p "Hello world!" \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.html.erb b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.html.erb new file mode 100644 index 0000000000..6769dd60bd --- /dev/null +++ b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.html.erb @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs new file mode 100644 index 0000000000..469fcd8e15 --- /dev/null +++ b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs @@ -0,0 +1 @@ +page[:body].visual_effect :highlight \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rhtml b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rhtml deleted file mode 100644 index 6769dd60bd..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rjs b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rjs deleted file mode 100644 index 469fcd8e15..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rjs +++ /dev/null @@ -1 +0,0 @@ -page[:body].visual_effect :highlight \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rxml b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rxml deleted file mode 100644 index 598d62e2fc..0000000000 --- a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.rxml +++ /dev/null @@ -1 +0,0 @@ -xml.p "Hello world!" \ No newline at end of file diff --git a/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder new file mode 100644 index 0000000000..598d62e2fc --- /dev/null +++ b/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder @@ -0,0 +1 @@ +xml.p "Hello world!" \ No newline at end of file -- cgit v1.2.3