aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/asset_paths.rb
diff options
context:
space:
mode:
authorChris Eppstein <chris@eppsteins.net>2011-06-27 13:58:51 -0700
committerChris Eppstein <chris@eppsteins.net>2011-06-27 13:58:51 -0700
commit024bed387b067519de64af5b89ce2b534c99155f (patch)
tree8f0fceafd1a99c8fa4dbf48580eba9f9e99b6139 /actionpack/lib/action_view/asset_paths.rb
parent2cc1bc37732a5f89c8364e6724e8c39e14216a0a (diff)
downloadrails-024bed387b067519de64af5b89ce2b534c99155f.tar.gz
rails-024bed387b067519de64af5b89ce2b534c99155f.tar.bz2
rails-024bed387b067519de64af5b89ce2b534c99155f.zip
Added a configuration setting:
config.action_controller.default_asset_host_protocol It's best to leave this unset. When unset the :request protocol is used whenever it can be and :relative is used in the other situations. When set to :request then assets hosts will be disabled when there is no request in scope and will use the request protocol whenever a request is in scope. If set to :relative, then a relative protocol is always used except for stylesheet link tags which must use the :request protocol to avoid double downloads in IE6&7. Conflicts: actionpack/lib/sprockets/helpers/rails_helper.rb actionpack/test/template/sprockets_helper_test.rb
Diffstat (limited to 'actionpack/lib/action_view/asset_paths.rb')
-rw-r--r--actionpack/lib/action_view/asset_paths.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/asset_paths.rb b/actionpack/lib/action_view/asset_paths.rb
index a768a0b882..4dd02755d3 100644
--- a/actionpack/lib/action_view/asset_paths.rb
+++ b/actionpack/lib/action_view/asset_paths.rb
@@ -19,7 +19,7 @@ module ActionView
# When :relative (default), the protocol will be determined by the client using current protocol
# When :request, the protocol will be the request protocol
# Otherwise, the protocol is used (E.g. :http, :https, etc)
- def compute_public_path(source, dir, ext = nil, include_host = true, protocol = :relative)
+ def compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil)
source = source.to_s
return source if is_uri?(source)
@@ -58,16 +58,20 @@ module ActionView
controller.respond_to?(:request)
end
- def rewrite_host_and_protocol(source, protocol = :relative)
+ def rewrite_host_and_protocol(source, protocol = nil)
host = compute_asset_host(source)
if host && !is_uri?(host)
- host = "#{compute_protocol(protocol)}#{host}"
+ if (protocol || default_protocol) == :request && !has_request?
+ host = nil
+ else
+ host = "#{compute_protocol(protocol)}#{host}"
+ end
end
host.nil? ? source : "#{host}#{source}"
end
def compute_protocol(protocol)
- protocol ||= :relative
+ protocol ||= default_protocol
case protocol
when :relative
"//"
@@ -81,6 +85,12 @@ module ActionView
end
end
+ def default_protocol
+ protocol = @config.action_controller.default_asset_host_protocol if @config.action_controller.present?
+ protocol ||= @config.default_asset_host_protocol
+ protocol || (has_request? ? :request : :relative)
+ end
+
def invalid_asset_host!(help_message)
raise ActionController::RoutingError, "This asset host cannot be computed without a request in scope. #{help_message}"
end