Skip to content
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

Merged
merged 3 commits into from
Jan 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/sprockets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ def assets
# Returns Sprockets::Manifest for app config.
attr_accessor :assets_manifest
end

class Engine < Railtie
Copy link
Contributor Author

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?

Copy link
Member

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 a Sprockets::Rails::Engine instead of a Railtie.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we drop support to Rails 4 we can change it to instead of reopening Rails::Engine just define a Sprockets::Rails::Engine instead of a Railtie.

Ah, cool, I didn't realize that would work.

# 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)
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down