Skip to content

Conversation

olivier-thatch
Copy link
Contributor

Automatically register assets with Sprockets.

This removes the need for users of the gem to add //= link grape_swagger_rails_manifest.{css,js} to their own app/assets/config/manifest.js.

Copy link
Contributor Author

@olivier-thatch olivier-thatch left a comment

Choose a reason for hiding this comment

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

CI won't pass until #131 is merged and this branch is rebased.

Comment on lines -220 to -222
### 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).
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.

Comment on lines -245 to -255
### 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.

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.

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

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Since we support sprockets < and > 4, lets add that to CI?

app.config.assets.precompile << proc { |path| path == 'grape_swagger_rails/application.js' }
app.config.assets.precompile << proc { |path| path == 'grape_swagger_rails/application.css' }
app.config.assets.precompile << proc { |path| path == 'grape_swagger_rails/favicon.ico' }
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!

@olivier-thatch olivier-thatch force-pushed the sprockets-initializer branch 2 times, most recently from 84839be to ffaadd4 Compare September 12, 2025 17:04
@olivier-thatch
Copy link
Contributor Author

Since we support sprockets < and > 4, lets add that to CI?

I'm not sure it's worth adding a new dimension to the matrix just for this. Nevertheless, I've added support for specifying the Sprockets version via the SPROCKETS_VERSION env variable, and verified that tests pass with SPROCKETS_VERSION="3.7.5".

If you'd like to proceed with adding this to the CI matrix, let's merge #133 first as it will make it a lot easier (one line vs. a bunch of new entries).

@dblock
Copy link
Member

dblock commented Sep 12, 2025

I merged #133, want to rebase?

@olivier-thatch olivier-thatch force-pushed the sprockets-initializer branch 2 times, most recently from f3f771d to b22e05c Compare September 12, 2025 19:05
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

@dblock
Copy link
Member

dblock commented Sep 12, 2025

@olivier-thatch Do you know what the issue in the HEAD tests is?

@olivier-thatch
Copy link
Contributor Author

@dblock Not sure, but I think these are transient failures. I'm pretty sure the tests were passing before I updated version.rb.

@olivier-thatch olivier-thatch mentioned this pull request Sep 12, 2025
@dblock
Copy link
Member

dblock commented Sep 15, 2025

@dblock Not sure, but I think these are transient failures. I'm pretty sure the tests were passing before I updated version.rb.

Retrying those fails them again, but I don't understand why the error happens either. Let's look at it later.

@dblock dblock merged commit 1cfa642 into ruby-grape:master Sep 15, 2025
37 of 44 checks passed
@olivier-thatch olivier-thatch deleted the sprockets-initializer branch September 15, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants