Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.6.1 (Next)
### 0.7.0 (Next)

* Your contribution here.
* [#132](https://github.com/ruby-grape/grape-swagger-rails/pull/132): Automatically register assets with Sprockets - [@olivier-thatch](https://github.com/olivier-thatch).

### 0.6.0 (2024/11/21)

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ group :development, :test do
gem 'rubocop-rspec'
gem 'ruby-grape-danger', '~> 0.2.0', require: false
gem 'selenium-webdriver'
gem 'sprockets', ENV.fetch('SPROCKETS_VERSION', '>= 4.0.0')
gem 'sprockets-rails', require: 'sprockets/railtie'
gem 'uglifier'
gem 'webrick'
Expand Down
38 changes: 0 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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).
Comment on lines -220 to -222
Copy link
Contributor Author

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.


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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down
15 changes: 15 additions & 0 deletions lib/grape-swagger-rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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) }

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
2 changes: 1 addition & 1 deletion lib/grape-swagger-rails/version.rb
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
1 change: 0 additions & 1 deletion spec/dummy/app/assets/config/manifest.js
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Loading