Make sure that the filesystem is not involved with asset hosting

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6187 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2007-02-21 15:28:37 +00:00
parent de0a0d700e
commit 7f55931f80
2 changed files with 26 additions and 12 deletions

@ -148,7 +148,10 @@ def javascript_include_tag(*sources)
if !File.exists?(joined_javascript_path)
File.open(joined_javascript_path, "w+") do |cache|
javascript_paths = expand_javascript_sources(sources).collect { |source| javascript_path(source) }
javascript_paths = expand_javascript_sources(sources).collect do |source|
compute_public_path(source, 'javascripts', 'js', false)
end
cache.write(join_asset_file_contents(javascript_paths))
end
end
@ -240,7 +243,10 @@ def stylesheet_link_tag(*sources)
if !File.exists?(joined_stylesheet_path)
File.open(joined_stylesheet_path, "w+") do |cache|
stylesheet_paths = expand_stylesheet_sources(sources).collect { |source| stylesheet_path(source) }
stylesheet_paths = expand_stylesheet_sources(sources).collect do |source|
compute_public_path(source, 'stylesheets', 'css', false)
end
cache.write(join_asset_file_contents(stylesheet_paths))
end
end
@ -318,7 +324,7 @@ def image_tag(source, options = {})
# roots. Rewrite the asset path for cache-busting asset ids. Include
# a single or wildcarded asset host, if configured, with the correct
# request protocol.
def compute_public_path(source, dir, ext)
def compute_public_path(source, dir, ext, include_host = true)
source += ".#{ext}" if File.extname(source).blank?
if source =~ %r{^[-a-z]+://}
@ -328,12 +334,17 @@ def compute_public_path(source, dir, ext)
source = "#{@controller.request.relative_url_root}#{source}"
rewrite_asset_path!(source)
host = compute_asset_host(source)
unless host.blank? or host =~ %r{^[-a-z]+://}
host = "#{@controller.request.protocol}#{host}"
end
if include_host
host = compute_asset_host(source)
"#{host}#{source}"
unless host.blank? or host =~ %r{^[-a-z]+://}
host = "#{@controller.request.protocol}#{host}"
end
"#{host}#{source}"
else
source
end
end
end

@ -42,6 +42,7 @@ def relative_url_root() "" end
def teardown
ActionController::Base.perform_caching = false
ActionController::Base.asset_host = nil
ENV["RAILS_ASSET_ID"] = nil
end
@ -194,17 +195,18 @@ def test_should_not_modify_source_string
def test_caching_javascript_include_tag_when_caching_on
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.asset_host = 'http://a%d.example.com'
ActionController::Base.perform_caching = true
assert_dom_equal(
%(<script src="/javascripts/all.js" type="text/javascript"></script>),
%(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>),
javascript_include_tag(:all, :cache => true)
)
assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
assert_dom_equal(
%(<script src="/javascripts/money.js" type="text/javascript"></script>),
%(<script src="http://a2.example.com/javascripts/money.js" type="text/javascript"></script>),
javascript_include_tag(:all, :cache => "money")
)
@ -235,17 +237,18 @@ def test_caching_javascript_include_tag_when_caching_off
def test_caching_stylesheet_link_tag_when_caching_on
ENV["RAILS_ASSET_ID"] = ""
ActionController::Base.asset_host = 'http://a%d.example.com'
ActionController::Base.perform_caching = true
assert_dom_equal(
%(<link href="/stylesheets/all.css" media="screen" rel="Stylesheet" type="text/css" />),
%(<link href="http://a3.example.com/stylesheets/all.css" media="screen" rel="Stylesheet" type="text/css" />),
stylesheet_link_tag(:all, :cache => true)
)
assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
assert_dom_equal(
%(<link href="/stylesheets/money.css" media="screen" rel="Stylesheet" type="text/css" />),
%(<link href="http://a3.example.com/stylesheets/money.css" media="screen" rel="Stylesheet" type="text/css" />),
stylesheet_link_tag(:all, :cache => "money")
)