Skip to content

Fix running on sprockets-rails master #322

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

Merged
merged 3 commits into from
Jul 23, 2015
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion lib/react/rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module React
module Rails
class Engine < ::Rails::Engine
initializer "react_rails.setup_engine", :group => :all do |app|
app.assets.register_engine '.jsx', React::JSX::Template
if app.assets.nil?
Sprockets.register_engine '.jsx', React::JSX::Template
else
app.assets.register_engine '.jsx', React::JSX::Template
end
Copy link
Contributor

Choose a reason for hiding this comment

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

(app.assets || Sprockets).register_engine '.jsx', React::JSX::Template```

Maybe this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually its harder to read that way and make the intent clear why we are doing it.

Copy link
Member

Choose a reason for hiding this comment

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

I also like the idea of removing that duplication, maybe:

sprockets_env = app.assets || Sprockets # Sprockets 3.x expects this in a different place 
sprockets_env.register_engine(".jsx", React::JSX::Template)

IMO less duplication = easier to maintain in the future!

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

end
end
end
Expand Down
10 changes: 6 additions & 4 deletions lib/react/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ class Railtie < ::Rails::Railtie
addons: app.config.react.addons,
})

app.assets.version = [
app.assets.version,
"react-#{asset_variant.react_build}",
].compact.join('-')
if app.assets.nil?
app.config.assets.version = [app.config.assets.version, "react-#{asset_variant.react_build}",].compact.join('-')
else
app.assets.version = [app.assets.version, "react-#{asset_variant.react_build}",].compact.join('-')
Copy link
Member

Choose a reason for hiding this comment

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

I think this could also be DRYer, eg

sprockets_env = app.assets || app.config.assets # sprockets-rails 3.x attaches this at a different config
sprockets_env.version = [ ... ].compact.join("-")

end

end

config.before_initialize do |app|
Expand Down