From 500206ce134bd4ec3cfec1ff27f91ad4af8cd605 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Mon, 29 Dec 2008 17:44:22 +0000 Subject: [PATCH] javascript_include_tag shouldn't automatically append a ".js" onto external urls eg. javascript_include_tag("http://www.google.com/jsapi") because "http://www.google.com/jsapi.js" doesn't exist --- .../lib/action_view/helpers/asset_tag_helper.rb | 6 +++--- actionpack/test/template/asset_tag_helper_test.rb | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 0633d54..06dd816 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -154,7 +154,7 @@ module ActionView # javascript_path "xmlhr" # => /javascripts/xmlhr.js # javascript_path "dir/xmlhr.js" # => /javascripts/dir/xmlhr.js # javascript_path "/dir/xmlhr" # => /dir/xmlhr.js - # javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr.js + # javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr # javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js def javascript_path(source) JavaScriptTag.new(self, @controller, source).public_path @@ -183,7 +183,7 @@ module ActionView # # # javascript_include_tag "http://www.railsapplication.com/xmlhr" # => - # + # # # javascript_include_tag "http://www.railsapplication.com/xmlhr.js" # => # @@ -605,7 +605,7 @@ module ActionView end def missing_extension?(source) - extension && File.extname(source).blank? + !source.start_with?("http") && extension && File.extname(source).blank? end def file_exists_with_extension?(source) diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 7597927..c9795e9 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -66,18 +66,23 @@ class AssetTagHelperTest < ActionView::TestCase JavascriptPathToTag = { %(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js), %(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js), - %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js) + %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js), + %(javascript_path("http://example.com/all")) => %(http://example.com/all), + %(javascript_path("http://example.com/all.js")) => %(http://example.com/all.js) } PathToJavascriptToTag = { %(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js), %(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js), - %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js) + %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js), + %(path_to_javascript("http://example.com/all")) => %(http://example.com/all), + %(path_to_javascript("http://example.com/all.js")) => %(http://example.com/all.js) } JavascriptIncludeToTag = { %(javascript_include_tag("xmlhr")) => %(), %(javascript_include_tag("xmlhr.js")) => %(), + %(javascript_include_tag("http://www.google.com/jsapi")) => %(), %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(), %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n), %(javascript_include_tag(:defaults)) => %(\n\n\n\n), @@ -111,7 +116,8 @@ class AssetTagHelperTest < ActionView::TestCase %(stylesheet_link_tag(:all, :recursive => true)) => %(\n\n\n), %(stylesheet_link_tag(:all, :media => "all")) => %(\n\n), %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(\n), - %(stylesheet_link_tag("http://www.example.com/styles/style")) => %() + %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(), + %(stylesheet_link_tag("http://www.example.com/styles/style.css")) => %() } ImagePathToTag = { -- 1.5.6.3