diff options
author | José Valim <jose.valim@gmail.com> | 2010-03-19 17:23:44 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-19 17:23:44 +0100 |
commit | ae499b53ef275b27e460da9f1b8e7a547dc85d9d (patch) | |
tree | 210975c56d5c9334272b954701eecbd1a105f5db /actionpack/lib/action_view/helpers | |
parent | f28d856cece877d1b2f306f54aeb12cce1db1023 (diff) | |
parent | f3743362c2642cc043fcfc7cd214f3d82e291c55 (diff) | |
download | rails-ae499b53ef275b27e460da9f1b8e7a547dc85d9d.tar.gz rails-ae499b53ef275b27e460da9f1b8e7a547dc85d9d.tar.bz2 rails-ae499b53ef275b27e460da9f1b8e7a547dc85d9d.zip |
Merge branch 'master' of gitproxy:rails/rails
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 03ae8ce0d8..64d8eebcfc 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -3,6 +3,7 @@ require 'cgi' require 'action_view/helpers/url_helper' require 'action_view/helpers/tag_helper' require 'active_support/core_ext/file' +require 'active_support/core_ext/object/blank' module ActionView module Helpers #:nodoc: @@ -623,41 +624,37 @@ module ActionView @@cache_asset_timestamps = true private + def rewrite_extension?(source, dir, ext) + source_ext = File.extname(source)[1..-1] + ext && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}")))) + end + + def rewrite_host_and_protocol(source, has_request) + host = compute_asset_host(source) + if has_request && host.present? && !is_uri?(host) + host = "#{controller.request.protocol}#{host}" + end + "#{host}#{source}" + end + # Add the the extension +ext+ if not present. Return full URLs otherwise untouched. # Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL # roots. Rewrite the asset path for cache-busting asset ids. Include # asset host, if configured, with the correct request protocol. def compute_public_path(source, dir, ext = nil, include_host = true) - has_request = controller.respond_to?(:request) - - source_ext = File.extname(source)[1..-1] - if ext && !is_uri?(source) && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}")))) - source += ".#{ext}" - end + return source if is_uri?(source) - unless is_uri?(source) - source = "/#{dir}/#{source}" unless source[0] == ?/ + source += ".#{ext}" if rewrite_extension?(source, dir, ext) + source = "/#{dir}/#{source}" unless source[0] == ?/ + source = rewrite_asset_path(source) - source = rewrite_asset_path(source) - - if has_request && include_host - unless source =~ %r{^#{controller.config.relative_url_root}/} - source = "#{controller.config.relative_url_root}#{source}" - end - end + has_request = controller.respond_to?(:request) + if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/} + source = "#{controller.config.relative_url_root}#{source}" end + source = rewrite_host_and_protocol(source, has_request) if include_host - if include_host && !is_uri?(source) - host = compute_asset_host(source) - - if has_request && !host.blank? && !is_uri?(host) - host = "#{controller.request.protocol}#{host}" - end - - "#{host}#{source}" - else - source - end + source end def is_uri?(path) |