diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2011-09-12 23:25:28 -0700 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-09-12 23:25:28 -0700 |
commit | b0cee703547a12adeb0fe43e121ad2da8c73422a (patch) | |
tree | c43c5e18e489a94abad497236e436c707b77213e | |
parent | 038e45a2b6a71175ffe368ae9d7c920f7d1230a6 (diff) | |
parent | 9279d1102c7d96810813cad0d0a666db0a549b1f (diff) | |
download | rails-b0cee703547a12adeb0fe43e121ad2da8c73422a.tar.gz rails-b0cee703547a12adeb0fe43e121ad2da8c73422a.tar.bz2 rails-b0cee703547a12adeb0fe43e121ad2da8c73422a.zip |
Merge pull request #2977 from guilleiguaran/fix-relative-root-in-assets
Set relative url root in assets when controller isn't available for Sprockets
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 16 | ||||
-rw-r--r-- | actionpack/test/template/sprockets_helper_test.rb | 7 |
3 files changed, 22 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index b757df6f22..d55064bf6d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -48,6 +48,8 @@ *Rails 3.1.1 (unreleased)* +* Set relative url root in assets when controller isn't available for Sprockets (eg. Sass files using asset_path). Fixes #2435 [Guillermo Iguaran] + * Fixed the behavior of asset pipeline when config.assets.digest and config.assets.compile are false and requested asset isn't precompiled. Before the requested asset were compiled anyway ignoring that the config.assets.compile flag is false. [Guillermo Iguaran] diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 3987e6e17f..7d9296fa90 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -17,6 +17,7 @@ module Sprockets paths.asset_digests = asset_digests paths.compile_assets = compile_assets? paths.digest_assets = digest_assets? + paths.relative_url_root = config.action_controller.relative_url_root paths end end @@ -96,12 +97,17 @@ module Sprockets end class AssetPaths < ::ActionView::AssetPaths #:nodoc: - attr_accessor :asset_environment, :asset_prefix, :asset_digests, :compile_assets, :digest_assets + attr_accessor :asset_environment, :asset_prefix, :asset_digests, :compile_assets, + :digest_assets, :relative_url_root class AssetNotPrecompiledError < StandardError; end - def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil) - super(source, asset_prefix, ext, include_host, protocol) + def compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil) + public_path = super(source, asset_prefix, ext, include_host, protocol) + if !is_uri?(public_path) && relative_url_root + public_path = rewrite_relative_url_root(public_path, relative_url_root) + end + public_path end # Return the filesystem path for the source @@ -149,6 +155,10 @@ module Sprockets source end end + + def relative_url_root + has_request? ? super : @relative_url_root + end end end end diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index ae4cb1f0aa..105c641712 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -124,6 +124,13 @@ class SprocketsHelperTest < ActionView::TestCase asset_path("/images/logo.gif") end + test "asset path with relative url root when controller isn't present but relative_url_root is" do + @controller = nil + @config.action_controller.relative_url_root = "/collaboration/hieraki" + assert_equal "/collaboration/hieraki/images/logo.gif", + asset_path("/images/logo.gif") + end + test "javascript path" do assert_match %r{/assets/application-[0-9a-f]+.js}, asset_path(:application, "js") |