Skip to content

Commit 075d3eb

Browse files
Automatically register assets with Sprockets
1 parent c4c7fd1 commit 075d3eb

File tree

4 files changed

+17
-37
lines changed

4 files changed

+17
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 0.6.1 (Next)
22

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

56
### 0.6.0 (2024/11/21)
67

README.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -217,42 +217,6 @@ NOTE: This action should be run part of this gem (not your application). In case
217217
make it up-to-date, clone the repo, run the rake task, examine the diff, fix any bugs, make sure
218218
tests pass and then send PR here.
219219

220-
### Enabling in a Rails-API Project
221-
222-
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).
223-
224-
Add sprockets to `config/application.rb`.
225-
226-
```ruby
227-
require 'sprockets/railtie'
228-
```
229-
230-
Include JavaScript in `app/assets/javascripts/application.js`.
231-
232-
```javascript
233-
//
234-
//= require_tree .
235-
```
236-
237-
Include CSS stylesheets in `app/assets/stylesheets/application.css`.
238-
239-
```css
240-
/*
241-
*= require_tree .
242-
*/
243-
```
244-
245-
### Enabling in Rails 6 (Sprokets 5)
246-
247-
Rails 6 top-level targets are determined via `./app/assets/config/manifest.js`. Specify `grape-swagger-rails` asset files as follows.
248-
249-
```javascript
250-
//= link grape_swagger_rails/application.css
251-
//= link grape_swagger_rails/application.js
252-
```
253-
254-
See [Upgrading Sprokets](https://github.com/rails/sprockets/blob/master/UPGRADING.md#manifestjs) for more information.
255-
256220
## Contributors
257221

258222
* [unloved](https://github.com/unloved)

lib/grape-swagger-rails/engine.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
module GrapeSwaggerRails
44
class Engine < ::Rails::Engine
55
paths['lib/tasks'] = 'lib/tasks/exported'
6+
67
isolate_namespace GrapeSwaggerRails
8+
9+
initializer 'grape_swagger_rails.assets', group: :all do |app|
10+
if app.config.respond_to?(:assets) && defined?(Sprockets)
11+
if Sprockets::VERSION.to_i >= 4
12+
app.config.assets.precompile << 'grape_swagger_rails/application.js'
13+
app.config.assets.precompile << 'grape_swagger_rails/application.css'
14+
app.config.assets.precompile << 'grape_swagger_rails/favicon.ico'
15+
else
16+
# use a proc instead of a string
17+
app.config.assets.precompile << proc { |path| path == 'grape_swagger_rails/application.js' }
18+
app.config.assets.precompile << proc { |path| path == 'grape_swagger_rails/application.css' }
19+
app.config.assets.precompile << proc { |path| path == 'grape_swagger_rails/favicon.ico' }
20+
end
21+
end
22+
end
723
end
824
end
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
//= link_directory ../stylesheets .css
22
//= link_directory ../javascripts .js
3-
//= link grape_swagger_rails_manifest.js

0 commit comments

Comments
 (0)