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
fix for sprockets-3.0.x #143
Conversation
Hello, @masarakki . Thanks for pull request. But also need fix tests, because https://github.com/rails/sprockets/blob/v3.0.0/lib/sprockets/context.rb also changed in sprockets 3.0. |
How can I write spec for both 3.0.x and 2.x? use Appraisal? |
Yes, you can use Appraisal and also you can write conditions inside specs (you have access to |
Thanks @masarakki, this pull request looks like good. Need review from @bogdan (I think better remove 1.9.3 from CI matrix - it is already unsupported). |
@@ -2,9 +2,13 @@ class JsRoutes | |||
class Engine < ::Rails::Engine | |||
JS_ROUTES_ASSET = 'js-routes' | |||
|
|||
initializer 'js-routes.append_assets_path', group: :all, after: :append_assets_path do |app| | |||
app.config.assets.paths.unshift Rails.root.join('config').to_s |
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.
Why do we need to add config
to assets path? Can you describe with details?
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.
https://github.com/rails/sprockets/blob/master/lib/sprockets/resolve.rb#L69 |
Hello @masarakki . I think we don't need add initializer 'js-routes.append_assets_path', group: :all, after: :append_assets_path do |app|
app.config.assets.paths.unshift Rails.root.join('config').to_s
end to assets_paths, because we render js-routes from https://github.com/railsware/js-routes/blob/master/app/assets/javascripts/js-routes.js.erb file, which is located in assets_path (I hope). Does it work without this? |
It is technically necessary since sprockets checks that all dependencies are themselves under the asset paths and routes.rb is not. However, adding config to the asset paths is not good in my opinion. It may have other unwanted side effects. A mechanism seems to exist to declare external environmental dependencies in sprockets 3. I've taken a shot at implementing using it myself and this seems to work: I've left the original |
@pbhogan |
update code. |
|
||
# only sprockets >= 3.0 | ||
if Rails.application.assets.respond_to?(:depend_on) | ||
Rails.application.assets.depend_on "file-digetst://#{routes}" |
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.
Little typo: file-digest://
should be.
oh, thx! |
waiting @bogdan |
FileUtils.rm_f(NAME) | ||
after(:each) do | ||
FileUtils.rm_rf Rails.root.join('tmp/cache') | ||
FileUtils.rm_f NAME |
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.
I think remove those files in before
is enough. Why do you think after
makes sense?
Looks good in general. Only one small comment regarding rspec callbacks. |
ping @bogdan :) |
after sprockets-3.0.x, I can't find depend_on files when assets.paths dosen't include directory.