Permalink
Browse files

Updated asset_template_path to asset_path and have it also support a …

…String [#4247 state:resolved]
  • Loading branch information...
1 parent 49bc6a2 commit 201e8986b15f4d815355e0ca96e02cf16dba9372 @wycats wycats committed Mar 29, 2010
@@ -108,7 +108,7 @@ module Helpers #:nodoc:
# "http://asset%d.example.com", "https://asset1.example.com"
# )
#
- # === Using asset path templates
+ # === Customizing the asset path
#
# By default, Rails appends asset's timestamps to all asset paths. This allows
# you to set a cache-expiration date for the asset far into the future, but
@@ -144,7 +144,7 @@ module Helpers #:nodoc:
# The easiest is to define the RAILS_ASSET_ID environment variable. The
# contents of this variable will always be used in preference to
# calculated timestamps. A more complex but flexible way is to set
- # <tt>ActionController::Base.config.asset_path_template</tt> to a proc
+ # <tt>ActionController::Base.config.asset_path</tt> to a proc
# that takes the unmodified asset path and returns the path needed for
# your asset caching to work. Typically you'd do something like this in
# <tt>config/environments/production.rb</tt>:
@@ -163,7 +163,7 @@ module Helpers #:nodoc:
# stylesheet_link_tag("application")
# # => <link href="/release-12345/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
#
- # Changing the asset_path_template does require that your web servers have
+ # Changing the asset_path does require that your web servers have
# knowledge of the asset template paths that you rewrite to so it's not
# suitable for out-of-the-box use. To use the example given above you
# could use something like this in your Apache VirtualHost configuration:
@@ -705,12 +705,7 @@ def compute_public_path(source, dir, ext = nil, include_host = true)
source += ".#{ext}" if rewrite_extension?(source, dir, ext)
source = "/#{dir}/#{source}" unless source[0] == ?/
- asset_path_template = config.asset_path_template
- if asset_path_template && asset_path_template.respond_to?(:call)
- source = asset_path_template.call(source)
- else
- source = rewrite_asset_path(source)
- end
+ 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}/}
@@ -774,7 +769,13 @@ def rails_asset_id(source)
# 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, path = nil)
+ if path && path.respond_to?(:call)
+ return path.call(source)
+ elsif path && path.is_a?(String)
+ return path % [source]
+ end
+
asset_id = rails_asset_id(source)
if asset_id.blank?
source
@@ -373,8 +373,15 @@ def test_timebased_asset_id
assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
end
+ def test_string_asset_id
+ @controller.config.asset_path = "/assets.v12345%s"
+
+ expected_path = "/assets.v12345/images/rails.png"
+ assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
+ end
+
def test_proc_asset_id
- @controller.config.asset_path_template = Proc.new do |asset_path|
+ @controller.config.asset_path = Proc.new do |asset_path|
"/assets.v12345#{asset_path}"
end
@@ -133,7 +133,7 @@ h4. Configuring Action Controller
* +config.action_controller.asset_host+ provides a string that is prepended to all of the URL-generating helpers in +AssetHelper+. This is designed to allow moving all javascript, CSS, and image files to a separate asset host.
-* +config.action_controller.asset_template_path+ allows you to override the default asset path generation by providing your own instructions.
+* +config.action_controller.asset_path+ allows you to override the default asset path generation by providing your own instructions.
* +config.action_controller.consider_all_requests_local+ is generally set to +true+ during development and +false+ during production; if it is set to +true+, then any error will cause detailed debugging information to be dumped in the HTTP response. For finer-grained control, set this to +false+ and implement +local_request?+ to specify which requests should provide debugging information on errors.

0 comments on commit 201e898

Please sign in to comment.