Skip to content

Commit 84839be

Browse files
Automatically register assets with Sprockets
1 parent 2e9e5f8 commit 84839be

File tree

5 files changed

+17
-37
lines changed

5 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

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ group :development, :test do
3737
gem 'rubocop-rspec'
3838
gem 'ruby-grape-danger', '~> 0.2.0', require: false
3939
gem 'selenium-webdriver'
40+
gem 'sprockets', ENV.fetch('SPROCKETS_VERSION', '>= 4.0.0')
4041
gem 'sprockets-rails', require: 'sprockets/railtie'
4142
gem 'uglifier'
4243
gem 'webrick'

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
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+
sprockets_4_or_later = Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('4')
12+
13+
[
14+
'grape_swagger_rails/application.js',
15+
'grape_swagger_rails/application.css',
16+
'grape_swagger_rails/favicon.ico'
17+
].each do |asset_path|
18+
app.config.assets.precompile << (sprockets_4_or_later ? asset_path : proc { |path| path == asset_path })
19+
end
20+
end
21+
end
722
end
823
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)