-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of complaining, add the dependency automatically
We need to use *both* `depend_on` and `depend_on_asset`, because the latter (bugfully?) considers changes to the referenced asset's dependencies, but not the file itself (making it entirely useless for an image). In the corresponding test, we call a protected Sprockets method... by design, this isn't something we're supposed to care about / access. But actually manipulating assets to ensure the dependency has taken hold seems rather like overkill.
- Loading branch information
Showing
4 changed files
with
9 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,6 @@ def raise_runtime_errors | |
Sprockets::Rails::Helper.raise_runtime_errors | ||
end | ||
|
||
class DependencyError < StandardError | ||
def initialize(path, dep) | ||
msg = "Asset depends on '#{dep}' to generate properly but has not declared the dependency\n" | ||
msg << "Please add: `//= depend_on_asset \"#{dep}\"` to '#{path}'" | ||
super msg | ||
end | ||
end | ||
|
||
class AssetFilteredError < StandardError | ||
def initialize(source) | ||
msg = "Asset filtered out and will not be served: " << | ||
|
@@ -71,7 +63,7 @@ def self.extended(obj) | |
|
||
def compute_asset_path(path, options = {}) | ||
# Check if we are inside Sprockets context before calling check_dependencies!. | ||
check_dependencies!(path) if defined?(_dependency_assets) | ||
check_dependencies!(path) if defined?(depend_on) | ||
|
||
if digest_path = asset_digest_path(path) | ||
path = digest_path if digest_assets | ||
|
@@ -177,11 +169,10 @@ def stylesheet_link_tag(*sources) | |
end | ||
|
||
protected | ||
# Checks if the asset is included in the dependencies list. | ||
# Ensures the asset is included in the dependencies list. | ||
def check_dependencies!(dep) | ||
if raise_runtime_errors && !_dependency_assets.detect { |asset| asset.include?(dep) } | ||
raise DependencyError.new(self.pathname, dep) | ||
end | ||
depend_on(dep) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rafaelfranca
Member
|
||
depend_on_asset(dep) | ||
end | ||
|
||
# Raise errors when source does not exist or is not in the precompiled list | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
//= depend_on_asset "logo.png" | ||
p { background: url(<%= image_path "logo.png" %>); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
//= depend_on_asset "foo.js" | ||
var url = '<%= javascript_path :foo %>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Unfortunately this line makes the sass-rails build red. Would you mind taking a look please ?