-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate asset fallback #375
Changes from all commits
03533fe
5902abe
e2f615d
d00b8ed
1af59d2
230b7e1
dfae4c5
09730f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
module Sprockets | ||
module Rails | ||
module Helper | ||
class AssetNotFound < StandardError; end | ||
|
||
class AssetNotPrecompiled < StandardError | ||
include Sprockets::Rails::Utils | ||
def initialize(source) | ||
|
@@ -33,7 +35,8 @@ def initialize(source) | |
:assets_environment, :assets_manifest, | ||
:assets_precompile, :precompiled_asset_checker, | ||
:assets_prefix, :digest_assets, :debug_assets, | ||
:resolve_assets_with, :check_precompiled_asset | ||
:resolve_assets_with, :check_precompiled_asset, | ||
:unknown_asset_fallback | ||
] | ||
|
||
def self.included(klass) | ||
|
@@ -68,12 +71,26 @@ def assets_environment | |
end | ||
end | ||
|
||
# Writes over the built in ActionView::Helpers::AssetUrlHelper#compute_asset_path | ||
# to use the asset pipeline. | ||
def compute_asset_path(path, options = {}) | ||
debug = options[:debug] | ||
|
||
if asset_path = resolve_asset_path(path, debug) | ||
File.join(assets_prefix || "/", legacy_debug_path(asset_path, debug)) | ||
else | ||
message = "The asset #{ path.inspect } is not present in the asset pipeline." | ||
raise AssetNotFound, message unless unknown_asset_fallback | ||
|
||
if respond_to?(:public_compute_asset_path) | ||
message << "Falling back to an asset that may be in the public folder.\n" | ||
message << "This behavior is deprecated and will be removed.\n" | ||
message << "To bypass the asset pipeline and preserve this behavior,\n" | ||
message << "use the `skip_pipeline: true` option.\n" | ||
|
||
call_stack = respond_to?(:caller_locations) ? caller_locations : caller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're on a Rails new enough to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests don't actually use Rails 5.1, we define the method, and the tests get run on all Ruby versions. The alternative to this would be detecting ruby versions and skipping the tests, which is less clean. I also want to be able to make a gem so that older versions of Rails can use this flag to get the error/deprecation behavior. |
||
ActiveSupport::Deprecation.warn(message, call_stack) | ||
end | ||
super | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add a newline after this class definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done