mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Set relative url root in assets when controller isn't available for Sprockets. Fix #2435
See https://github.com/rails/sass-rails/issues/42 for details
This commit is contained in:
parent
a9509284ca
commit
9279d1102c
3 changed files with 22 additions and 3 deletions
|
@ -48,6 +48,8 @@
|
||||||
|
|
||||||
*Rails 3.1.1 (unreleased)*
|
*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.
|
* 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]
|
Before the requested asset were compiled anyway ignoring that the config.assets.compile flag is false. [Guillermo Iguaran]
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ module Sprockets
|
||||||
paths.asset_digests = asset_digests
|
paths.asset_digests = asset_digests
|
||||||
paths.compile_assets = compile_assets?
|
paths.compile_assets = compile_assets?
|
||||||
paths.digest_assets = digest_assets?
|
paths.digest_assets = digest_assets?
|
||||||
|
paths.relative_url_root = config.action_controller.relative_url_root
|
||||||
paths
|
paths
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -96,12 +97,17 @@ module Sprockets
|
||||||
end
|
end
|
||||||
|
|
||||||
class AssetPaths < ::ActionView::AssetPaths #:nodoc:
|
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
|
class AssetNotPrecompiledError < StandardError; end
|
||||||
|
|
||||||
def compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil)
|
def compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil)
|
||||||
super(source, asset_prefix, ext, include_host, protocol)
|
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
|
end
|
||||||
|
|
||||||
# Return the filesystem path for the source
|
# Return the filesystem path for the source
|
||||||
|
@ -149,6 +155,10 @@ module Sprockets
|
||||||
source
|
source
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def relative_url_root
|
||||||
|
has_request? ? super : @relative_url_root
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -124,6 +124,13 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||||
asset_path("/images/logo.gif")
|
asset_path("/images/logo.gif")
|
||||||
end
|
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
|
test "javascript path" do
|
||||||
assert_match %r{/assets/application-[0-9a-f]+.js},
|
assert_match %r{/assets/application-[0-9a-f]+.js},
|
||||||
asset_path(:application, "js")
|
asset_path(:application, "js")
|
||||||
|
|
Loading…
Reference in a new issue