diff options
author | Joshua Peek <josh@joshpeek.com> | 2012-10-15 10:57:32 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2012-10-15 10:57:32 -0500 |
commit | 6601917ad96aa7e0fdaf96058cafe01fbf00bc12 (patch) | |
tree | 26e9172f7b7f81d590b47776fb7766d7d147439f /actionpack/lib | |
parent | 9d412388218b67a10830bdb30611198c5acdad50 (diff) | |
download | rails-6601917ad96aa7e0fdaf96058cafe01fbf00bc12.tar.gz rails-6601917ad96aa7e0fdaf96058cafe01fbf00bc12.tar.bz2 rails-6601917ad96aa7e0fdaf96058cafe01fbf00bc12.zip |
Extract compute_asset_extname and allow extname to be disabled
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_url_helper.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_url_helper.rb b/actionpack/lib/action_view/helpers/asset_url_helper.rb index 72a9dff82c..d75e4c0edc 100644 --- a/actionpack/lib/action_view/helpers/asset_url_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_url_helper.rb @@ -107,11 +107,6 @@ module ActionView module AssetUrlHelper URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//} - ASSET_EXTENSIONS = { - javascript: '.js', - stylesheet: '.css' - } - # Computes the path to asset in public directory. If :type # options is set, a file extension will be appended and scoped # to the corresponding public directory. @@ -127,8 +122,8 @@ module ActionView return "" unless source.present? return source if source =~ URI_REGEXP - if File.extname(source).empty? && (ext = ASSET_EXTENSIONS[options[:type]]) - source = "#{source}#{ext}" + if extname = compute_asset_extname(source, options) + source = "#{source}#{extname}" end if source[0] != ?/ @@ -157,6 +152,19 @@ module ActionView end alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route + ASSET_EXTENSIONS = { + javascript: '.js', + stylesheet: '.css' + } + + # Compute extname to append to asset path. Returns nil if + # nothing should be added. + def compute_asset_extname(source, options = {}) + return if options[:extname] == false + extname = options[:extname] || ASSET_EXTENSIONS[options[:type]] + extname if extname && File.extname(source) != extname + end + # Maps asset types to public directory. ASSET_PUBLIC_DIRECTORIES = { audio: '/audios', |