aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Nartimov <just.lest@gmail.com>2012-05-21 15:32:13 +0300
committerSergey Nartimov <just.lest@gmail.com>2012-05-21 15:47:12 +0300
commit39f9f02ab04973b213bef8c6f4c1a71043ed709d (patch)
tree6ba48175e1ff5b72f4b70e4f1051c264afa979ca
parent64e12ff109ad934939df317e532647c603f90520 (diff)
downloadrails-39f9f02ab04973b213bef8c6f4c1a71043ed709d.tar.gz
rails-39f9f02ab04973b213bef8c6f4c1a71043ed709d.tar.bz2
rails-39f9f02ab04973b213bef8c6f4c1a71043ed709d.zip
Assets: don't add extension if other given and file exists
We should lookup if asset without appended extension exists. When sprockets are disabled the asset tag helpers incorporate this logic. When sprockets are enabled we should have the same logic. For example, we have style.ext file in app/assets/stylesheets and we use stylesheet_link_tag in the layout. In this case we should have /assets/style.ext instead of /assets/style.ext.css in the output. Closes #6310
-rw-r--r--actionpack/lib/sprockets/helpers/rails_helper.rb9
-rw-r--r--actionpack/test/fixtures/sprockets/app/stylesheets/style.ext0
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb3
3 files changed, 10 insertions, 2 deletions
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb
index 4e11221842..8ac137b4b5 100644
--- a/actionpack/lib/sprockets/helpers/rails_helper.rb
+++ b/actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -155,8 +155,13 @@ module Sprockets
end
def rewrite_extension(source, dir, ext)
- if ext && File.extname(source) != ".#{ext}"
- "#{source}.#{ext}"
+ source_ext = File.extname(source)
+ if ext && source_ext != ".#{ext}"
+ if !source_ext.empty? && asset_environment[source]
+ source
+ else
+ "#{source}.#{ext}"
+ end
else
source
end
diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/style.ext b/actionpack/test/fixtures/sprockets/app/stylesheets/style.ext
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/stylesheets/style.ext
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index fc3c87a72e..65107b54b7 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -307,6 +307,9 @@ class SprocketsHelperTest < ActionView::TestCase
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
stylesheet_link_tag("style", "style")
+ assert_match %r{\A<link href="/assets/style-[0-9a-f]+.ext" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("style.ext")
+
@config.assets.compile = true
@config.assets.debug = true
assert_match %r{<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />},