-
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 5 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,7 @@ | |
module Sprockets | ||
module Rails | ||
module Helper | ||
class AssetNotFound < StandardError; end | ||
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. Shouldn't we add a newline after this class definition? 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. done |
||
class AssetNotPrecompiled < StandardError | ||
include Sprockets::Rails::Utils | ||
def initialize(source) | ||
|
@@ -33,7 +34,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 +70,24 @@ 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 } you are looking for is not present in the asset pipeline." | ||
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. Don't use "you" in an exception message (or a deprecation). I think this should have separate phrasings for the exception vs the deprecation, actually, even though the intent is similar. The deprecation wants a softer "we didn't find it in the place [but we're doing this other thing]" ('not present in'); for the exception, that feels too gentle... a more definitive "not found" / "unknown asset" seems called for. |
||
raise AssetNotFound, message unless unknown_asset_fallback | ||
|
||
if respond_to?(:public_compute_asset_path) | ||
message << "The public fallback behavior is being deprecaed and will be removed.\n" | ||
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 users see this message it's because we have deprecated this type of lookup. So I'd go with |
||
message << "pass in `skip_pipeline: true` instead.\n" | ||
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.
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. How is this?
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. I'd consider something more terse, e.g.:
Because of where/how they show up (i.e., often many times in a row), overly-helpful deprecation messages can just be overwhelming. IMO to-the-point + Google-able are the most valuable attributes here. |
||
|
||
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 | ||
|
@@ -244,6 +258,19 @@ def legacy_debug_path(path, debug) | |
path | ||
end | ||
end | ||
|
||
private | ||
# Emits a deprecation warning when asset pipeline | ||
# is used with an asset that is not part of the pipeline. | ||
# | ||
# Attempts to determine proper method name based on caller. | ||
def deprecate_invalid_asset_lookup(name, call_stack) | ||
message = "The asset #{ name.inspect } you are looking for is not present in the asset pipeline.\n" | ||
message << "The public fallback behavior is being deprecated and will be removed.\n" | ||
message << "pass in `skip_pipeline: true` instead.\n" | ||
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.
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. Not sure why this comment shows twice. 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. Ahh, i need to remove this method, we're not using it anymore. Added this in when we tried to get fancy computing exactly where in the call stack you were when trying to look up the asset. |
||
|
||
ActiveSupport::Deprecation.warn(message, call_stack) | ||
end | ||
end | ||
|
||
# Use a separate module since Helper is mixed in and we needn't pollute | ||
|
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.
You mention truthy and yet also use an explicit
false
— shouldn't a falsy value work?the a result
->the result
.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.
Does Sprockets have precedent for using 'truthy'? Rails uses 'true' (as opposed to '
true
') for that.