Don't repeatedly add relative_url_root to asset sources. Closes #10767 [tomtoday, Koz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8740 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
5ac3a9bd0b
commit
10aa728e8b
@ -450,9 +450,11 @@ def compute_public_path(source, dir, ext = nil, include_host = true)
|
||||
else
|
||||
source = "/#{dir}/#{source}" unless source[0] == ?/
|
||||
if has_request
|
||||
unless source =~ %r{^#{@controller.request.relative_url_root}/}
|
||||
source = "#{@controller.request.relative_url_root}#{source}"
|
||||
end
|
||||
rewrite_asset_path!(source)
|
||||
end
|
||||
source = rewrite_asset_path(source)
|
||||
|
||||
if include_host
|
||||
host = compute_asset_host(source)
|
||||
@ -504,11 +506,15 @@ def rails_asset_id(source)
|
||||
end
|
||||
end
|
||||
|
||||
# Break out the asset path rewrite so you wish to put the asset id
|
||||
# Break out the asset path rewrite in case plugins wish to put the asset id
|
||||
# someplace other than the query string.
|
||||
def rewrite_asset_path!(source)
|
||||
def rewrite_asset_path(source)
|
||||
asset_id = rails_asset_id(source)
|
||||
source << "?#{asset_id}" if !asset_id.blank?
|
||||
if asset_id.blank?
|
||||
source
|
||||
else
|
||||
source + "?#{asset_id}"
|
||||
end
|
||||
end
|
||||
|
||||
def javascript_src_tag(source, options)
|
||||
|
@ -432,6 +432,8 @@ def test_should_compute_proper_path
|
||||
assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
|
||||
assert_dom_equal(%(/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
|
||||
assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png"))
|
||||
assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse.png'" src="/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
|
||||
assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse2.png'" src="/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
|
||||
end
|
||||
|
||||
def test_should_ignore_relative_root_path_on_complete_url
|
||||
@ -444,6 +446,8 @@ def test_should_compute_proper_path_with_asset_host
|
||||
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
|
||||
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
|
||||
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png"))
|
||||
assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
|
||||
assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse2.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
|
||||
ensure
|
||||
ActionController::Base.asset_host = ""
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user