diff options
author | wycats <wycats@gmail.com> | 2010-03-28 18:45:52 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-28 18:46:18 -0700 |
commit | 201e8986b15f4d815355e0ca96e02cf16dba9372 (patch) | |
tree | 4160f1a01034b520c0968b16557b50c220ae0c86 | |
parent | 49bc6a249e2a200216f8a96c36093a2c7a471c9b (diff) | |
download | rails-201e8986b15f4d815355e0ca96e02cf16dba9372.tar.gz rails-201e8986b15f4d815355e0ca96e02cf16dba9372.tar.bz2 rails-201e8986b15f4d815355e0ca96e02cf16dba9372.zip |
Updated asset_template_path to asset_path and have it also support a String [#4247 state:resolved]
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 21 | ||||
-rw-r--r-- | actionpack/test/template/asset_tag_helper_test.rb | 9 | ||||
-rw-r--r-- | railties/guides/source/configuring.textile | 2 |
3 files changed, 20 insertions, 12 deletions
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 - # <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 ActionView # 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 @@ 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 diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 43d11df8fe..fbd504ae7d 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -373,8 +373,15 @@ class AssetTagHelperTest < ActionView::TestCase 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 diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index e438d4cc0a..e35126fc5a 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -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. |