From db05478d92218d78aca0be22f97257fab10a90ca Mon Sep 17 00:00:00 2001 From: jacott Date: Sat, 28 May 2011 18:19:11 +1200 Subject: [PATCH] fixed asset_paths when called from sprockets for relative_url_root --- actionpack/lib/action_view/helpers/asset_paths.rb | 7 ++++++- .../helpers/asset_tag_helpers/asset_paths.rb | 11 +---------- actionpack/test/template/sprockets_helper_test.rb | 6 ++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/actionpack/lib/action_view/helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_paths.rb index 38810eea2e769..b448c8923d041 100644 --- a/actionpack/lib/action_view/helpers/asset_paths.rb +++ b/actionpack/lib/action_view/helpers/asset_paths.rb @@ -44,7 +44,12 @@ def rewrite_asset_path(source, path = nil) raise NotImplementedError end + def rewrite_relative_url_root(source, relative_url_root) + relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source + end + def rewrite_host_and_protocol(source, has_request) + source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request host = compute_asset_host(source) if has_request && host && !is_uri?(host) host = "#{controller.request.protocol}#{host}" @@ -75,4 +80,4 @@ def compute_asset_host(source) end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb index cd0f8c88789fc..2d49823412630 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb @@ -85,17 +85,8 @@ def rails_asset_id(source) end end end - - def rewrite_relative_url_root(source, relative_url_root) - relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source - end - - def rewrite_host_and_protocol(source, has_request) - source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request - super(source, has_request) - end end end end -end \ No newline at end of file +end diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index 4ce8c672cd1fa..a56a9a38be29a 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -58,6 +58,12 @@ def url_for(*args) asset_path("http://www.example.com/video/play.mp4") end + test "asset path with relavtive url root" do + @controller.config.relative_url_root = "/collaboration/hieraki" + assert_equal "/collaboration/hieraki/images/logo.gif", + asset_path("/images/logo.gif") + end + test "javascript path" do assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js", asset_path(:application, "js")