Skip to content

Commit

Permalink
Fix asset tags for files with more than one dot
Browse files Browse the repository at this point in the history
After the fix done in 39f9f02a, there are cases that will not work
correctly. If you have file with "2 extensions", like foo.min.js and you
reference the file without extension, like:

    javascript_include_tag "foo.min"

it will fail because sprockets finds foo.min.js with foo.min argument.

This commit fixes this case and will get the right file even when
referrencing it without extension.
  • Loading branch information
drogus committed Jun 7, 2012
1 parent b040b33 commit f83bc14
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sprockets/rails/helpers/rails_helper.rb
Expand Up @@ -160,7 +160,8 @@ def rewrite_asset_path(source, dir, options = {})
def rewrite_extension(source, dir, ext)
source_ext = File.extname(source)
if ext && source_ext != ".#{ext}"
if !source_ext.empty? && asset_environment[source]
if !source_ext.empty? && (asset = asset_environment[source]) &&
asset.pathname.to_s =~ /#{source}\Z/
source
else
"#{source}.#{ext}"
Expand Down
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions test/sprockets_helper_test.rb
Expand Up @@ -254,6 +254,9 @@ def compute_host(source, request, options = {})
assert_match %r{\A<script src="/assets/xmlhr-[0-9a-f]+.js"></script>\Z},
javascript_include_tag("xmlhr", "xmlhr")

assert_match %r{\A<script src="/assets/foo.min-[0-9a-f]+.js"></script>\Z},
javascript_include_tag("foo.min")

@config.assets.compile = true
@config.assets.debug = true
assert_match %r{<script src="/javascripts/application.js"></script>},
Expand Down Expand Up @@ -307,6 +310,9 @@ def compute_host(source, request, options = {})
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.ext" media="screen" rel="stylesheet" />\Z},
stylesheet_link_tag("style.ext")

assert_match %r{\A<link href="/assets/style.min-[0-9a-f]+.css" media="screen" rel="stylesheet" />\Z},
stylesheet_link_tag("style.min")

@config.assets.compile = true
@config.assets.debug = true
assert_match %r{<link href="/stylesheets/application.css" media="screen" rel="stylesheet" />},
Expand Down

0 comments on commit f83bc14

Please sign in to comment.