diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2011-04-19 19:05:07 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-04-19 19:05:07 +0200 |
commit | 626bcc9bf415ca9872bbdaceac30a4df9aca86bb (patch) | |
tree | 2e3ccb325690ff6051d867676a773732ddd2b805 /actionpack/lib | |
parent | d35c91225e8eea967358328ba618e6608222a615 (diff) | |
download | rails-626bcc9bf415ca9872bbdaceac30a4df9aca86bb.tar.gz rails-626bcc9bf415ca9872bbdaceac30a4df9aca86bb.tar.bz2 rails-626bcc9bf415ca9872bbdaceac30a4df9aca86bb.zip |
Switch to asset_path and make it available in the Sprockets::Context (now you can do asset_path("logo.png") in a stylesheet.css.erb file and get fingerprinting)
Diffstat (limited to 'actionpack/lib')
4 files changed, 24 insertions, 18 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 10bdede1b4..e859b3ae49 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -275,7 +275,7 @@ module ActionView # plugin authors are encouraged to do so. def image_path(source) if config.use_sprockets - sprockets_asset_path(source) + asset_path(source) else asset_paths.compute_public_path(source, 'images') end @@ -294,7 +294,7 @@ module ActionView # video_path("http://www.railsapplication.com/vid/hd.avi") # => http://www.railsapplication.com/vid/hd.avi def video_path(source) if config.use_sprockets - sprockets_asset_path(source) + asset_path(source) else asset_paths.compute_public_path(source, 'videos') end @@ -313,7 +313,7 @@ module ActionView # audio_path("http://www.railsapplication.com/sounds/horse.wav") # => http://www.railsapplication.com/sounds/horse.wav def audio_path(source) if config.use_sprockets - sprockets_asset_path(source) + asset_path(source) else asset_paths.compute_public_path(source, 'audios') end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index ce5a7dc2e5..a0f6fb5692 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -87,7 +87,7 @@ module ActionView # javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js def javascript_path(source) if config.use_sprockets - sprockets_javascript_path(source) + asset_path(source, 'js') else asset_paths.compute_public_path(source, 'javascripts', 'js') end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index a994afb65e..309762ee05 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -64,7 +64,7 @@ module ActionView # stylesheet_path "http://www.railsapplication.com/css/style.css" # => http://www.railsapplication.com/css/style.css def stylesheet_path(source) if config.use_sprockets - sprockets_stylesheet_path(source) + asset_path(source, 'css') else asset_paths.compute_public_path(source, 'stylesheets', 'css') end diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb index d2a31c02d4..bf47af6e10 100644 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb @@ -3,23 +3,14 @@ require 'uri' module ActionView module Helpers module SprocketsHelper - def sprockets_asset_path(source, default_ext = nil) + def asset_path(source, default_ext = nil) compute_sprockets_path(source, 'assets', default_ext) end - def sprockets_javascript_path(source) - sprockets_asset_path(source, 'js') - end - - def sprockets_stylesheet_path(source) - sprockets_asset_path(source, 'css') - end - - def sprockets_javascript_include_tag(source, options = {}) options = { 'type' => "text/javascript", - 'src' => sprockets_javascript_path(source) + 'src' => asset_path(source, 'js') }.merge(options.stringify_keys) content_tag 'script', "", options @@ -30,7 +21,7 @@ module ActionView 'rel' => "stylesheet", 'type' => "text/css", 'media' => "screen", - 'href' => sprockets_stylesheet_path(source) + 'href' => asset_path(source, 'css') }.merge(options.stringify_keys) tag 'link', options @@ -60,10 +51,15 @@ module ActionView end def add_fingerprint(source, dir) - source.replace(assets.path($1, config.perform_caching, dir)) if source =~ /^\/#{dir}\/(.+)/ + if source =~ /^\/#{dir}\/(.+)/ + source.replace(assets.path($1, performing_caching?, dir)) + end end def add_asset_host(source) + # When included in Sprockets::Context, there's no controller + return unless respond_to?(:controller) + host = compute_asset_host(source) if controller.respond_to?(:request) && host && URI.parse(host).host @@ -94,6 +90,16 @@ module ActionView def assets Rails.application.assets end + + def performing_caching? + # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available + respond_to?(:config) ? config.perform_caching : Rails.application.config.action_controller.perform_caching + end end end end + +# FIXME: Temp hack for extending Sprockets::Context so +class Sprockets::Context + include ActionView::Helpers::SprocketsHelper +end if defined?(Sprockets)
\ No newline at end of file |