Add the the extension ext if not present. Return full URLs
otherwise untouched. Prefix with /dir/ 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.
# File actionpack/lib/action_view/helpers/asset_tag_helper.rb, line 528
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 && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(ASSETS_DIR, dir, "#{source}.#{ext}"))))
source += ".#{ext}"
end
unless source =~ %r{^[-a-z]+://}
source = "/#{dir}/#{source}" unless source[0] == ?/
source = rewrite_asset_path(source)
if has_request && include_host
unless source =~ %r{^#{ActionController::Base.relative_url_root}/}
source = "#{ActionController::Base.relative_url_root}#{source}"
end
end
end
if include_host && source !~ %r{^[-a-z]+://}
host = compute_asset_host(source)
if has_request && !host.blank? && host !~ %r{^[-a-z]+://}
host = "#{@controller.request.protocol}#{host}"
end
"#{host}#{source}"
else
source
end
end