-
Notifications
You must be signed in to change notification settings - Fork 247
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
Import append_assets_path initializer #215
Changes from all commits
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 |
---|---|---|
|
@@ -36,6 +36,23 @@ def assets | |
# Returns Sprockets::Manifest for app config. | ||
attr_accessor :assets_manifest | ||
end | ||
|
||
class Engine < Railtie | ||
# Skip defining append_assets_path on Rails <= 4.2 | ||
unless initializers.find { |init| init.name == :append_assets_path } | ||
initializer :append_assets_path, :group => :all do |app| | ||
if paths["app/assets"].respond_to?(:existent_directories) | ||
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. Why bother with versions < 4 if the initializer is defined and we will not enter this code? It is just because Rails 3.0? 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. :/ yeah, I just wanted to make the tests pass. This is merging into the old 2.x. I'll drop this condition when pulling this patch into master. |
||
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories) | ||
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories) | ||
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories) | ||
else | ||
app.config.assets.paths.unshift(*paths["vendor/assets"].paths.select { |d| File.directory?(d) }) | ||
app.config.assets.paths.unshift(*paths["lib/assets"].paths.select { |d| File.directory?(d) }) | ||
app.config.assets.paths.unshift(*paths["app/assets"].paths.select { |d| File.directory?(d) }) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
module Sprockets | ||
|
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.
Is extending initializers on
Engine
allowed?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.
Yes, it is, although it is not the best way of doing it.
Since we want to detect if the initializer was already defined I think we can't do better.
When we drop support to Rails 4 we can change it to instead of reopening
Rails::Engine
just define aSprockets::Rails::Engine
instead of aRailtie
.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.
Ah, cool, I didn't realize that would work.