Permalink
Browse files

Optimize relative_url_root rewriting code.

  • Loading branch information...
thedarkone committed Sep 22, 2010
1 parent f2e0b35 commit 05e53b4c1a3422131f73598848b0332cdc793f69
Showing with 5 additions and 3 deletions.
  1. +5 −3 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -718,6 +718,10 @@ def rewrite_host_and_protocol(source, has_request)
"#{host}#{source}"
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
+
# Add the the extension +ext+ if not present. Return full URLs otherwise untouched.
# Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL
# roots. Rewrite the asset path for cache-busting asset ids. Include
@@ -733,9 +737,7 @@ def compute_public_path(source, dir, ext = nil, include_host = true)
source = rewrite_asset_path(source, config.asset_path)
has_request = controller.respond_to?(:request)
- if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/}
- source = "#{controller.config.relative_url_root}#{source}"
- end
+ source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request && include_host
source = rewrite_host_and_protocol(source, has_request) if include_host
source

0 comments on commit 05e53b4

Please sign in to comment.