aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb6
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb2
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb2
-rw-r--r--actionpack/lib/action_view/helpers/sprockets_helper.rb32
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb40
5 files changed, 42 insertions, 40 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
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index 67774c1893..863e473697 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -33,38 +33,38 @@ class SprocketsHelperTest < ActionView::TestCase
test "asset path" do
assert_equal "/assets/logo-9c0a079bdd7701d7e729bd956823d153.png",
- sprockets_asset_path("logo.png")
+ asset_path("logo.png")
assert_equal "/images/logo",
- sprockets_asset_path("/images/logo")
+ asset_path("/images/logo")
assert_equal "/images/logo.gif",
- sprockets_asset_path("/images/logo.gif")
+ asset_path("/images/logo.gif")
assert_equal "/dir/audio",
- sprockets_asset_path("/dir/audio")
+ asset_path("/dir/audio")
assert_equal "http://www.example.com/video/play",
- sprockets_asset_path("http://www.example.com/video/play")
+ 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")
+ asset_path("http://www.example.com/video/play.mp4")
end
test "javascript path" do
assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js",
- sprockets_javascript_path(:application)
+ asset_path(:application, "js")
assert_equal "/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
- sprockets_javascript_path("xmlhr")
+ asset_path("xmlhr", "js")
assert_equal "/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
- sprockets_javascript_path("dir/xmlhr.js")
+ asset_path("dir/xmlhr.js", "js")
assert_equal "/dir/xmlhr.js",
- sprockets_javascript_path("/dir/xmlhr")
+ asset_path("/dir/xmlhr", "js")
assert_equal "http://www.railsapplication.com/js/xmlhr",
- sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr")
+ asset_path("http://www.railsapplication.com/js/xmlhr", "js")
assert_equal "http://www.railsapplication.com/js/xmlhr.js",
- sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr.js")
+ asset_path("http://www.railsapplication.com/js/xmlhr.js", "js")
end
test "javascript include tag" do
@@ -80,20 +80,16 @@ class SprocketsHelperTest < ActionView::TestCase
end
test "stylesheet path" do
- assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css",
- sprockets_stylesheet_path(:application)
+ assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", asset_path(:application, "css")
- assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css",
- sprockets_stylesheet_path("style")
- assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css",
- sprockets_stylesheet_path("dir/style.css")
- assert_equal "/dir/style.css",
- sprockets_stylesheet_path("/dir/style.css")
+ assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("style", "css")
+ assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css")
+ assert_equal "/dir/style.css", asset_path("/dir/style.css", "css")
assert_equal "http://www.railsapplication.com/css/style",
- sprockets_stylesheet_path("http://www.railsapplication.com/css/style")
+ asset_path("http://www.railsapplication.com/css/style", "css")
assert_equal "http://www.railsapplication.com/css/style.css",
- sprockets_stylesheet_path("http://www.railsapplication.com/css/style.css")
+ asset_path("http://www.railsapplication.com/css/style.css", "css")
end
test "stylesheet link tag" do