-
Notifications
You must be signed in to change notification settings - Fork 196
Automatically register assets with Sprockets #132
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
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 |
---|---|---|
|
@@ -18,8 +18,6 @@ Swagger UI as Rails Engine for grape-swagger gem. | |
- [Integration with DoorKeeper](#integration-with-doorkeeper) | ||
- [Hiding the API or Authorization text boxes](#hiding-the-api-or-authorization-text-boxes) | ||
- [Updating Swagger UI from Dist](#updating-swagger-ui-from-dist) | ||
- [Enabling in a Rails-API Project](#enabling-in-a-rails-api-project) | ||
- [Enabling in Rails 6 (Sprokets 5)](#enabling-in-rails-6-sprokets-5) | ||
- [Contributors](#contributors) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
@@ -217,42 +215,6 @@ NOTE: This action should be run part of this gem (not your application). In case | |
make it up-to-date, clone the repo, run the rake task, examine the diff, fix any bugs, make sure | ||
tests pass and then send PR here. | ||
|
||
### Enabling in a Rails-API Project | ||
|
||
The grape-swagger-rails gem uses the Rails asset pipeline for its Javascript and CSS. Enable the asset pipeline with [rails-api](https://github.com/rails-api/rails-api). | ||
|
||
Add sprockets to `config/application.rb`. | ||
|
||
```ruby | ||
require 'sprockets/railtie' | ||
``` | ||
|
||
Include JavaScript in `app/assets/javascripts/application.js`. | ||
|
||
```javascript | ||
// | ||
//= require_tree . | ||
``` | ||
|
||
Include CSS stylesheets in `app/assets/stylesheets/application.css`. | ||
|
||
```css | ||
/* | ||
*= require_tree . | ||
*/ | ||
``` | ||
|
||
### Enabling in Rails 6 (Sprokets 5) | ||
|
||
Rails 6 top-level targets are determined via `./app/assets/config/manifest.js`. Specify `grape-swagger-rails` asset files as follows. | ||
|
||
```javascript | ||
//= link grape_swagger_rails/application.css | ||
//= link grape_swagger_rails/application.js | ||
``` | ||
|
||
See [Upgrading Sprokets](https://github.com/rails/sprockets/blob/master/UPGRADING.md#manifestjs) for more information. | ||
|
||
Comment on lines
-245
to
-255
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. This is no longer necessary, as the Railtie will now automatically register assets with Sprockets. |
||
## Contributors | ||
|
||
* [unloved](https://github.com/unloved) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,21 @@ | |
module GrapeSwaggerRails | ||
class Engine < ::Rails::Engine | ||
paths['lib/tasks'] = 'lib/tasks/exported' | ||
|
||
isolate_namespace GrapeSwaggerRails | ||
|
||
initializer 'grape_swagger_rails.assets', group: :all do |app| | ||
if app.config.respond_to?(:assets) && defined?(Sprockets) | ||
sprockets_4_or_later = Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('4') | ||
|
||
[ | ||
'grape_swagger_rails/application.js', | ||
'grape_swagger_rails/application.css', | ||
'grape_swagger_rails/favicon.ico' | ||
].each do |asset_path| | ||
app.config.assets.precompile << (sprockets_4_or_later ? asset_path : proc { |path| path == asset_path }) | ||
end | ||
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. Nitpicking, maybe this is better? Don't feel strongly about it at all. PATHS = ['grape_swagger_rails/application.js', ...]
app.config.assets.precompile.concat Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("4.0.0") ? paths : proc { |path| PATHS.include?(path) }
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. I've tweaked the code to avoid duplicating the list of asset paths, lmk what you think! |
||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module GrapeSwaggerRails | ||
VERSION = '0.6.1' | ||
VERSION = '0.7.0' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
//= link_directory ../stylesheets .css | ||
//= link_directory ../javascripts .js | ||
//= link grape_swagger_rails_manifest.js | ||
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. I verified that the test suite doesn't pass without the change in this PR when this line is removed, and does pass with the change. |
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.
Rails now natively supports API-only mode and the rails-api repo has long gone stale, so this entire section is no longer relevant.