aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2011-04-19 18:07:14 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2011-04-19 18:07:42 +0200
commita3a5c7eba39c64413abd0fb4766282c9f071d248 (patch)
treeb7015e1ca2f5026a62f1882a163e97ad4a32519d /actionpack
parentdca31b9224bd9feb23208d668a77d85ce062cf93 (diff)
downloadrails-a3a5c7eba39c64413abd0fb4766282c9f071d248.tar.gz
rails-a3a5c7eba39c64413abd0fb4766282c9f071d248.tar.bz2
rails-a3a5c7eba39c64413abd0fb4766282c9f071d248.zip
All assets, including images, audio, and video, now uses the asset pipeline when its on
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb18
-rw-r--r--actionpack/lib/action_view/helpers/sprockets_helper.rb15
-rw-r--r--actionpack/test/fixtures/sprockets/app/images/logo.pngbin0 -> 6646 bytes
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb19
4 files changed, 44 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index f6b2d4f3f4..10bdede1b4 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -274,7 +274,11 @@ module ActionView
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
# plugin authors are encouraged to do so.
def image_path(source)
- asset_paths.compute_public_path(source, 'images')
+ if config.use_sprockets
+ sprockets_asset_path(source)
+ else
+ asset_paths.compute_public_path(source, 'images')
+ end
end
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
@@ -289,7 +293,11 @@ module ActionView
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
# video_path("http://www.railsapplication.com/vid/hd.avi") # => http://www.railsapplication.com/vid/hd.avi
def video_path(source)
- asset_paths.compute_public_path(source, 'videos')
+ if config.use_sprockets
+ sprockets_asset_path(source)
+ else
+ asset_paths.compute_public_path(source, 'videos')
+ end
end
alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
@@ -304,7 +312,11 @@ module ActionView
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
# audio_path("http://www.railsapplication.com/sounds/horse.wav") # => http://www.railsapplication.com/sounds/horse.wav
def audio_path(source)
- asset_paths.compute_public_path(source, 'audios')
+ if config.use_sprockets
+ sprockets_asset_path(source)
+ else
+ asset_paths.compute_public_path(source, 'audios')
+ end
end
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb
index 408a2030ab..fee13be886 100644
--- a/actionpack/lib/action_view/helpers/sprockets_helper.rb
+++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb
@@ -3,8 +3,12 @@ require 'uri'
module ActionView
module Helpers
module SprocketsHelper
+ def sprockets_asset_path(source, default_ext = nil)
+ compute_sprockets_path(source, 'assets', default_ext)
+ end
+
def sprockets_javascript_path(source)
- compute_sprockets_path source, 'assets', 'js'
+ sprockets_asset_path(source, 'js')
end
def sprockets_javascript_include_tag(source, options = {})
@@ -17,9 +21,9 @@ module ActionView
end
def sprockets_stylesheet_path(source)
- compute_sprockets_path source, 'assets', 'css'
+ sprockets_asset_path(source, 'css')
end
-
+
def sprockets_stylesheet_link_tag(source, options = {})
options = {
'rel' => "stylesheet",
@@ -31,13 +35,14 @@ module ActionView
tag 'link', options
end
+
private
- def compute_sprockets_path(source, dir, default_ext)
+ def compute_sprockets_path(source, dir, default_ext = nil)
source = source.to_s
return source if URI.parse(source).host
- # Add /javscripts to relative paths
+ # Add /assets to relative paths
if source[0] != ?/
source = "/#{dir}/#{source}"
end
diff --git a/actionpack/test/fixtures/sprockets/app/images/logo.png b/actionpack/test/fixtures/sprockets/app/images/logo.png
new file mode 100644
index 0000000000..d5edc04e65
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/images/logo.png
Binary files differ
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index 67aee86d02..67774c1893 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -22,6 +22,7 @@ class SprocketsHelperTest < ActionView::TestCase
@assets = Sprockets::Environment.new
@assets.paths << FIXTURES.join("sprockets/app/javascripts")
@assets.paths << FIXTURES.join("sprockets/app/stylesheets")
+ @assets.paths << FIXTURES.join("sprockets/app/images")
config.perform_caching = true
end
@@ -30,6 +31,24 @@ class SprocketsHelperTest < ActionView::TestCase
"http://www.example.com"
end
+ test "asset path" do
+ assert_equal "/assets/logo-9c0a079bdd7701d7e729bd956823d153.png",
+ sprockets_asset_path("logo.png")
+
+ assert_equal "/images/logo",
+ sprockets_asset_path("/images/logo")
+ assert_equal "/images/logo.gif",
+ sprockets_asset_path("/images/logo.gif")
+
+ assert_equal "/dir/audio",
+ sprockets_asset_path("/dir/audio")
+
+ assert_equal "http://www.example.com/video/play",
+ sprockets_asset_path("http://www.example.com/video/play")
+ assert_equal "http://www.example.com/video/play.mp4",
+ sprockets_asset_path("http://www.example.com/video/play.mp4")
+ end
+
test "javascript path" do
assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js",
sprockets_javascript_path(:application)