From 6601917ad96aa7e0fdaf96058cafe01fbf00bc12 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 15 Oct 2012 10:57:32 -0500 Subject: Extract compute_asset_extname and allow extname to be disabled --- .../lib/action_view/helpers/asset_url_helper.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_view/helpers/asset_url_helper.rb') 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', -- cgit v1.2.3