From 201e8986b15f4d815355e0ca96e02cf16dba9372 Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 28 Mar 2010 18:45:52 -0700 Subject: Updated asset_template_path to asset_path and have it also support a String [#4247 state:resolved] --- .../lib/action_view/helpers/asset_tag_helper.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 635c58bc35..e4ec17467e 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -108,7 +108,7 @@ module ActionView # "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 ActionView # 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 - # ActionController::Base.config.asset_path_template to a proc + # ActionController::Base.config.asset_path 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 # config/environments/production.rb: @@ -163,7 +163,7 @@ module ActionView # stylesheet_link_tag("application") # # => # - # 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 @@ module ActionView 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 @@ module ActionView # 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 -- cgit v1.2.3