提交 c9260c55 编写于 作者: J Jeremy Kemper

Add request protocol to asset host if not given. Prefer setting asset host as...

Add request protocol to asset host if not given. Prefer setting asset host as hostname only, no request protocol.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6162 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 90c1207c
......@@ -10,7 +10,7 @@ module Helpers #:nodoc:
# in your environment.rb. These methods do not verify the assets exist before
# linking to them.
#
# ActionController::Base.asset_host = "http://assets.example.com"
# ActionController::Base.asset_host = "assets.example.com"
# image_tag("rails.png")
# => <img src="http://assets.example.com/images/rails.png" alt="Rails" />
# stylesheet_include_tag("application")
......@@ -212,7 +212,8 @@ def image_tag(source, options = {})
# Add the .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
# a single or wildcarded asset host if configured.
# a single or wildcarded asset host, if configured, with the correct
# request protocol.
def compute_public_path(source, dir, ext)
source += ".#{ext}" if File.extname(source).blank?
if source =~ %r{^[-a-z]+://}
......@@ -221,7 +222,13 @@ def compute_public_path(source, dir, ext)
source = "/#{dir}/#{source}" unless source[0] == ?/
source = "#{@controller.request.relative_url_root}#{source}"
rewrite_asset_path!(source)
"#{compute_asset_host(source)}#{source}"
host = compute_asset_host(source)
unless host.blank? or host =~ %r{^[-a-z]+://}
host = "#{@controller.request.protocol}#{host}"
end
"#{host}#{source}"
end
end
......
......@@ -189,6 +189,10 @@ def url_for(options, *parameters_for_method_reference)
def relative_url_root
"/collaboration/hieraki"
end
def protocol
'gopher://'
end
end.new
@controller.request = @request
......@@ -230,4 +234,11 @@ def test_should_wildcard_asset_host_between_zero_and_four
ensure
ActionController::Base.asset_host = nil
end
def test_asset_host_without_protocol_should_use_request_protocol
ActionController::Base.asset_host = 'a.example.com'
assert_equal 'gopher://a.example.com/collaboration/hieraki/images/xml.png', image_path('xml.png')
ensure
ActionController::Base.asset_host = nil
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册