Skip to content

Commit

Permalink
cleans a bit #compute_public_path
Browse files Browse the repository at this point in the history
[#4232 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
fxn authored and jeremy committed Mar 19, 2010
1 parent 0aa0c37 commit f374336
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions actionpack/lib/action_view/helpers/asset_tag_helper.rb
Expand Up @@ -3,6 +3,7 @@
require 'action_view/helpers/url_helper' require 'action_view/helpers/url_helper'
require 'action_view/helpers/tag_helper' require 'action_view/helpers/tag_helper'
require 'active_support/core_ext/file' require 'active_support/core_ext/file'
require 'active_support/core_ext/object/blank'


module ActionView module ActionView
module Helpers #:nodoc: module Helpers #:nodoc:
Expand Down Expand Up @@ -623,41 +624,37 @@ def self.cache_asset_timestamps=(value)
@@cache_asset_timestamps = true @@cache_asset_timestamps = true


private 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. # 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 # Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL
# roots. Rewrite the asset path for cache-busting asset ids. Include # roots. Rewrite the asset path for cache-busting asset ids. Include
# asset host, if configured, with the correct request protocol. # asset host, if configured, with the correct request protocol.
def compute_public_path(source, dir, ext = nil, include_host = true) def compute_public_path(source, dir, ext = nil, include_host = true)
has_request = controller.respond_to?(:request) return source if is_uri?(source)

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


unless is_uri?(source) source += ".#{ext}" if rewrite_extension?(source, dir, ext)
source = "/#{dir}/#{source}" unless source[0] == ?/ source = "/#{dir}/#{source}" unless source[0] == ?/
source = rewrite_asset_path(source)


source = rewrite_asset_path(source) has_request = controller.respond_to?(:request)

if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/}
if has_request && include_host source = "#{controller.config.relative_url_root}#{source}"
unless source =~ %r{^#{controller.config.relative_url_root}/}
source = "#{controller.config.relative_url_root}#{source}"
end
end
end end
source = rewrite_host_and_protocol(source, has_request) if include_host


if include_host && !is_uri?(source) 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
end end


def is_uri?(path) def is_uri?(path)
Expand Down

0 comments on commit f374336

Please sign in to comment.