aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/asset_url_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_view/helpers/asset_url_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/asset_url_helper.rb22
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',