From 5c6e6936b4aba0fc1ecd6454c22182e825589d59 Mon Sep 17 00:00:00 2001 From: Seth Fitzsimmons Date: Sun, 14 Dec 2008 10:49:28 -0800 Subject: [PATCH] change default MIME type for javascript to 'application/javascript' per RFC 4329, section 7 --- actionpack/lib/action_controller/base.rb | 2 +- actionpack/lib/action_controller/mime_types.rb | 4 +- .../lib/action_view/helpers/asset_tag_helper.rb | 54 ++++++++++---------- .../lib/action_view/helpers/capture_helper.rb | 2 +- .../lib/action_view/helpers/javascript_helper.rb | 4 +- .../lib/action_view/helpers/prototype_helper.rb | 2 +- actionpack/lib/action_view/helpers/url_helper.rb | 2 +- actionpack/test/controller/render_test.rb | 6 +- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 13f2e90..05caf9d 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -849,7 +849,7 @@ module ActionController #:nodoc: # # In addition to using RJS with render :update, you can also just render vanilla JavaScript with :js. # - # # Renders "alert('hello')" and sets the mime type to text/javascript + # # Renders "alert('hello')" and sets the mime type to application/javascript # render :js => "alert('hello')" # # === Rendering with status and location headers diff --git a/actionpack/lib/action_controller/mime_types.rb b/actionpack/lib/action_controller/mime_types.rb index 2d7fba1..5df4614 100644 --- a/actionpack/lib/action_controller/mime_types.rb +++ b/actionpack/lib/action_controller/mime_types.rb @@ -4,7 +4,7 @@ Mime::Type.register "*/*", :all Mime::Type.register "text/plain", :text, [], %w(txt) Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml ) -Mime::Type.register "text/javascript", :js, %w( application/javascript application/x-javascript ) +Mime::Type.register "application/javascript", :js, %w( application/x-javascript text/javascript ) Mime::Type.register "text/css", :css Mime::Type.register "text/calendar", :ics Mime::Type.register "text/csv", :csv @@ -18,4 +18,4 @@ Mime::Type.register "application/x-www-form-urlencoded", :url_encoded_form # http://www.ietf.org/rfc/rfc4627.txt # http://www.json.org/JSONRequest.html -Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest ) \ No newline at end of file +Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest ) diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 0633d54..948d2c4 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -173,26 +173,26 @@ module ActionView # # ==== Examples # javascript_include_tag "xmlhr" # => - # + # # # javascript_include_tag "xmlhr.js" # => - # + # # # javascript_include_tag "common.javascript", "/elsewhere/cools" # => - # - # + # + # # # javascript_include_tag "http://www.railsapplication.com/xmlhr" # => - # + # # # javascript_include_tag "http://www.railsapplication.com/xmlhr.js" # => - # + # # # javascript_include_tag :defaults # => - # - # + # + # # ... - # + # # # * = The application.js file is only referenced if it exists # @@ -202,12 +202,12 @@ module ActionView # You can also include all javascripts in the javascripts directory using :all as the source: # # javascript_include_tag :all # => - # - # + # + # # ... - # - # - # + # + # + # # # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to # all subsequently included files. @@ -225,23 +225,23 @@ module ActionView # # ==== Examples # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false => - # - # + # + # # ... - # - # - # + # + # + # # # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is true => - # + # # # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false => - # - # - # + # + # + # # # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is true => - # + # # # The :recursive option is also available for caching: # @@ -274,9 +274,9 @@ module ActionView # ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey => ["head", "body", "tail"] # # javascript_include_tag :monkey # => - # - # - # + # + # + # def self.register_javascript_expansion(expansions) JavaScriptSources.expansions.merge!(expansions) end diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index e86ca27..85e1887 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -74,7 +74,7 @@ module ActionView # Please login! # # <% content_for :script do %> - # + # # <% end %> # # Then, in another view, you could to do something like this: diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 8f64acf..6721634 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -150,7 +150,7 @@ module ActionView # javascript_tag "alert('All is good')" # # Returns: - # + # # => # # Instead of passing the content as an argument, you can also use a block # in which case, you pass your +html_options+ as the first parameter. diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 7fab310..1ddfa01 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -598,7 +598,7 @@ module ActionView # JavaScriptGenerator generates blocks of JavaScript code that allow you # to change the content and presentation of multiple DOM elements. Use # this in your Ajax response bodies, either in a + # # => # # mail_to "me@domain.com", "My email", :encode => "hex" # # => My email diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 4e6c56d..28ce9a9 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1095,14 +1095,14 @@ class RenderTest < ActionController::TestCase def test_update_page get :update_page assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers['type'] + assert_equal 'application/javascript; charset=utf-8', @response.headers['type'] assert_equal 2, @response.body.split($/).length end def test_update_page_with_instance_variables get :update_page_with_instance_variables assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers['type'] + assert_equal 'application/javascript; charset=utf-8', @response.headers['type'] assert_match /balance/, @response.body assert_match /\$37/, @response.body end @@ -1110,7 +1110,7 @@ class RenderTest < ActionController::TestCase def test_update_page_with_view_method get :update_page_with_view_method assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers['type'] + assert_equal 'application/javascript; charset=utf-8', @response.headers['type'] assert_match /2 people/, @response.body end -- 1.6.0.4