Skip to content

Commit

Permalink
Add rails 5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-gomez committed Dec 7, 2016
1 parent c03af99 commit 3996375
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 33 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
rvm:
- 2.0
- 2.1
- 2.2.2
- 2.2.4
- 2.3.0

env:
- 'RAILS_MAJOR_VERSION=4'
- 'RAILS_MAJOR_VERSION=5'
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ source "http://rubygems.org"

gemspec

rails_version = case ENV['RAILS_MAJOR_VERSION']
when '4'
'~> 4.0'
else
'~> 5.0'
end

gem 'rails', rails_version

# jquery-rails is used by the dummy application
gem 'jquery-rails'

Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Swaggard
========

Swaggard is a Rails Engine that can be used to document a REST api. It does this by generating a
json that is compliant with [Swagger](http://swagger.io) and displaying it using [Swagger-ui](https://github.com/wordnik/swagger-ui).
Swaggard is a Rails Engine that can be used to document a REST api. It does this by generating a json that is compliant with [Swagger](http://swagger.io) and displaying it using [Swagger-ui](https://github.com/wordnik/swagger-ui).
This gem is inspired and based on [SwaggerYard](https://github.com/synctv/swagger_yard) by [Chris Trinh](https://github.com/chtrinh).

Swagger UI versions
-----------------------
This table tracks the version of Swagger UI used on each Swaggard version:

Swaggard Version | Swagger UI Version
---------------- | ------------------
0.4.0 | 2.2.8
0.3.0 | 2.1.3
0.2.1 | 2.1.3
0.2.0 | 2.1.3
0.1.1 | 2.1.3
0.1.0 | 2.1.3
0.0.4 | 2.1.8-M1
Compatibility
-------------
This table tracks the version of Swagger UI used on each Swaggard version and
the supported rails version.

Swaggard Version | Swagger UI Version | Supported Rails Versions
---------------- | -------------------| ------------------------
0.4.0 | 2.2.8 | 4
0.3.0 | 2.1.3 | 4
0.2.1 | 2.1.3 | 4
0.2.0 | 2.1.3 | 4
0.1.1 | 2.1.3 | 4
0.1.0 | 2.1.3 | 4
0.0.4 | 2.1.8-M1 | 4

Swaggard vs SwaggerYard
-----------------------
Expand Down Expand Up @@ -207,7 +207,7 @@ If you not set `access_username`, everyone will have access to Swagger documenta
Additional parameters
--------------

Swaggard additional parameters to be sent on every request, either as a header or as part of the query.
Swaggard supports additional parameters to be sent on every request, either as a header or as part of the query.

You can configure it as follows:

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/swaggard/swagger_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Swaggard
class SwaggerController < ApplicationController

before_filter :authorize
before_action :authorize

def index
respond_to do |format|
Expand Down Expand Up @@ -43,4 +43,4 @@ def get_swaggard_doc_json
end

end
end
end
4 changes: 2 additions & 2 deletions app/views/swaggard/swagger/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<%= favicon_link_tag 'swaggard/favicon-32x32.png', sizes: '32x32' %>
<%= favicon_link_tag 'swaggard/favicon-16x16.png', sizes: '16x16' %>
<%= stylesheet_link_tag 'swaggard/application', media: :screen %>
<%= stylesheet_link_tag 'swaggard/application_print', media: :print %>
<%= stylesheet_link_tag 'swaggard/application', media: :screen %>
<%= stylesheet_link_tag 'swaggard/application_print', media: :print %>
<%= javascript_include_tag 'swaggard/application' %>
<%= javascript_include_tag "swaggard/lang/#{Swaggard.configuration.language}" %>
Expand Down
7 changes: 5 additions & 2 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Rails.application.config.assets.precompile += %w[swaggard/application_print.css]
Rails.application.config.assets.precompile += %w[swaggard/lang/*.js]
Rails.application.config.assets.precompile += %w[swaggard/application_print.css
swaggard/favicon-32x32.png
swaggard/favicon-16x16.png
swaggard/lang/*.js
swaggard/logo_small.png]
13 changes: 11 additions & 2 deletions lib/swaggard/engine.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
unless Rails::Application.instance_methods.include?(:assets_manifest)
warn <<-END
[Swaggard] It seems you are using an api only rails setup but swaggard
[Swaggard] neeeds sprockets in order to work. This might have undesired side effects,
[Swaggard] if thats not the case you can ignore this warning.
END
require 'sprockets/railtie'
end

module Swaggard
class Engine < ::Rails::Engine
isolate_namespace Swaggard

initializer 'swaggard.finisher_hook', :after => :finisher_hook do |app|
initializer 'swaggard.finisher_hook', after: :finisher_hook do |app|
app.reload_routes!

Swaggard.configure do |config|
Expand All @@ -21,4 +30,4 @@ class Engine < ::Rails::Engine
end

end
end
end
7 changes: 5 additions & 2 deletions lib/swaggard/parsers/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def route_action(route)
end

def route_verb(route)
route.verb.source.gsub(/[$^]/, '')
verb = route.verb
verb = route.verb.source unless verb.is_a?(String)

verb.gsub(/[$^]/, '')
end

def route_path(route)
Expand All @@ -51,4 +54,4 @@ def route_path_params(route)

end
end
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class Application < Rails::Application
end
end

Dummy::Application.initialize!
Dummy::Application.initialize!
6 changes: 3 additions & 3 deletions swaggard.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Gem::Specification.new do |s|
s.name = 'swaggard'
s.version = Swaggard::VERSION
s.authors = ['Adrian Gomez']
s.email = ['adrian.gomez@moove-it.com']
s.homepage = 'https://github.com/Moove-it/swaggard'
s.email = ['adri4n.steam@gmail.com']
s.homepage = 'https://github.com/adrian-gomez/swaggard'
s.summary = %q{Swaggard: Swagger Rails REST API doc using yard YARD}
s.description = %q{Generate swagger documentation for your Rails REST API using YARD}
s.licenses = ['MIT']

s.files = Dir['{app,config,public,lib}/**/*'] + ['MIT-LICENSE', 'Rakefile', 'README.md']
s.test_files = Dir['spec/**/*']

s.add_dependency 'rails', '~> 4.0'
s.add_dependency 'rails', '>= 4.0', '< 6.0'
s.add_dependency 'sass-rails'

s.add_development_dependency 'rspec'
Expand Down

0 comments on commit 3996375

Please sign in to comment.