api_docs 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +8 -0
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +67 -148
- data/Rakefile +29 -14
- data/VERSION +1 -1
- data/api_docs.gemspec +66 -25
- data/app/assets/javascripts/api_docs.js +11 -0
- data/app/assets/stylesheets/api_docs.css +62 -0
- data/app/controllers/api_docs/docs_controller.rb +8 -0
- data/app/views/api_docs/docs/_action.html.erb +41 -0
- data/app/views/api_docs/docs/_request_params.html.erb +16 -0
- data/app/views/api_docs/docs/index.html.erb +32 -0
- data/config/routes.rb +3 -0
- data/lib/api_docs/configuration.rb +16 -11
- data/lib/api_docs/engine.rb +3 -6
- data/lib/api_docs/test_helper.rb +81 -0
- data/lib/api_docs.rb +4 -26
- data/script/rails +8 -0
- data/test/api_docs_test.rb +15 -0
- data/test/docs_controller_test.rb +11 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/images/glyphicons-halflings-white.png +0 -0
- data/test/dummy/app/assets/images/glyphicons-halflings.png +0 -0
- data/test/dummy/app/assets/javascripts/application.js +16 -0
- data/test/dummy/app/assets/javascripts/bootstrap.min.js +6 -0
- data/test/dummy/app/assets/stylesheets/application.css +14 -0
- data/test/dummy/app/assets/stylesheets/bootstrap.min.css +9 -0
- data/test/dummy/app/controllers/application_controller.rb +25 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +16 -0
- data/test/dummy/config/application.rb +65 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +31 -0
- data/test/dummy/config/environments/production.rb +64 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/test_helper.rb +14 -0
- data/test/test_helper_test.rb +104 -0
- metadata +119 -79
- data/app/assets/javascripts/api_docs.js.coffee +0 -37
- data/app/assets/javascripts/prettify.js +0 -28
- data/app/assets/stylesheets/prettify.css +0 -53
- data/app/views/api_docs/_api_docs.html.haml +0 -11
- data/app/views/api_docs/_curl.html.haml +0 -4
- data/app/views/api_docs/_form.html.haml +0 -18
- data/app/views/api_docs/_panel.html.haml +0 -33
- data/app/views/api_docs/_params.html.haml +0 -15
- data/app/views/api_docs/_response.html.haml +0 -16
- data/lib/api_docs/railtie.rb +0 -12
data/Gemfile
ADDED
data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,166 +1,82 @@
|
|
1
|
-
# API
|
2
|
-
|
3
|
-
A tool to help you generate documentation for you API
|
1
|
+
# API Docs [](http://travis-ci.org/twg/api_docs)
|
2
|
+
A tool to help you generate documentation for your API using integration tests in Rails 3.
|
4
3
|
|
5
4
|
|
6
5
|
## Installation
|
6
|
+
Add gem definition to your Gemfile and `bundle install`:
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
``` ruby
|
8
|
+
```
|
11
9
|
gem 'api_docs'
|
12
10
|
```
|
13
|
-
|
14
|
-
Bundle it:
|
15
|
-
|
16
|
-
bundle install
|
17
11
|
|
18
|
-
|
12
|
+
To access generated docs mount it to a path in your `routes.rb` like this:
|
19
13
|
|
20
|
-
```
|
21
|
-
|
22
|
-
//= require prettify
|
14
|
+
``` ruby
|
15
|
+
mount ApiDocs::Engine => '/api-docs'
|
23
16
|
```
|
24
17
|
|
25
|
-
|
18
|
+
You may also want to add js/css to your asset pipeline manifests:
|
26
19
|
|
27
|
-
``` js
|
28
|
-
//= require jquery
|
29
|
-
//= require jquery_ujs
|
30
|
-
//= require bootstrap
|
31
|
-
//= require prettify
|
32
|
-
//= require api_docs
|
33
20
|
```
|
21
|
+
require api_docs
|
22
|
+
```
|
23
|
+
|
24
|
+
Documents view is made to work with [Twitter Bootstrap](http://twitter.github.com/bootstrap) css and js libraries.
|
34
25
|
|
35
|
-
|
26
|
+
## Generating Api Docs
|
27
|
+
Documentation is automatically generated into yaml files from tests you create to test your api controllers. To start, let's create integration test by running `rails g integration_test users`. This will create a file for you to work with. Here's a simple test we can do:
|
36
28
|
|
37
29
|
``` ruby
|
38
|
-
|
30
|
+
class UsersTest < ActionDispatch::IntegrationTest
|
31
|
+
def test_get_user
|
32
|
+
user = users(:default)
|
33
|
+
api_call(:get, '/users/:id', :id => user.to_param) do |doc|
|
34
|
+
assert_response :success
|
35
|
+
assert_equal ({
|
36
|
+
'id' => user.id,
|
37
|
+
'name' => user.name
|
38
|
+
}), JSON.parse(response.body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_user_failure
|
43
|
+
api_call(:get, '/users/:id', :id => 'invalid') do |doc|
|
44
|
+
doc.description = 'When bad user id is passed'
|
45
|
+
assert_response :not_found
|
46
|
+
assert_equal ({
|
47
|
+
'message' => 'User not found'
|
48
|
+
}), JSON.parse(response.body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
39
52
|
```
|
40
53
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
"updated_at": "2012-04-26T20:21:43-04:00"
|
64
|
-
},
|
65
|
-
{
|
66
|
-
"id": 3,
|
67
|
-
"first_name": "Anna",
|
68
|
-
"last_name": "Brown",
|
69
|
-
"created_at": "2011-06-13T00:28:36-04:00",
|
70
|
-
"updated_at": "2012-04-26T20:21:43-04:00"
|
71
|
-
},
|
72
|
-
...
|
73
|
-
]
|
74
|
-
}
|
75
|
-
fail:
|
76
|
-
response: 'HTTP/1.1 422 Unprocessable Entity'
|
77
|
-
data: |
|
78
|
-
{
|
79
|
-
"message": "Failed to create User",
|
80
|
-
"errors" : {
|
81
|
-
"email": "Email is invalid",
|
82
|
-
...
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
curl: curl -i :api_url/users?api_key=7gR9hZt3DBqcuzi2mZKN
|
87
|
-
|
88
|
-
# ------------------------------
|
89
|
-
|
90
|
-
'Show':
|
91
|
-
url: '/users/:id'
|
92
|
-
method: GET
|
93
|
-
description: |
|
94
|
-
Returns profile details for a specified user.
|
95
|
-
<span class=label>NOTE</span> If showing details of another user the email is ommited
|
96
|
-
params:
|
97
|
-
api_key:
|
98
|
-
id: the id of a user
|
99
|
-
success:
|
100
|
-
response: 'HTTP/1.1 200 OK'
|
101
|
-
data: |
|
102
|
-
{
|
103
|
-
"user": {
|
104
|
-
"id": 917,
|
105
|
-
"api_key": "7gR9hZt3DBqcuzi2mZKN",
|
106
|
-
"email": "john_smith@gmail.com",
|
107
|
-
"first_name": "John",
|
108
|
-
"last_name": "Smith",
|
109
|
-
"created_at": "2011-06-13T00:28:36-04:00",
|
110
|
-
"updated_at": "2012-04-26T20:21:43-04:00"
|
111
|
-
}
|
112
|
-
}
|
113
|
-
fail:
|
114
|
-
response: 'HTTP/1.1 404 Not Found'
|
115
|
-
data: |
|
116
|
-
{
|
117
|
-
"message": "User not found"
|
118
|
-
}
|
119
|
-
curl: curl -i :api_url/users/197?api_key=2a10K5ipBd2qapJsPvCso90kMO
|
120
|
-
|
121
|
-
# ------------------------------
|
122
|
-
|
123
|
-
'Create':
|
124
|
-
url: '/users'
|
125
|
-
method: POST
|
126
|
-
description: Create a user
|
127
|
-
params:
|
128
|
-
user[first_name]:
|
129
|
-
user[last_name]:
|
130
|
-
user[email]:
|
131
|
-
user[password]:
|
132
|
-
success:
|
133
|
-
response: 'HTTP/1.1 201 Created'
|
134
|
-
data: |
|
135
|
-
{
|
136
|
-
"user": {
|
137
|
-
"id": 917,
|
138
|
-
"api_key": "7gR9hZt3DBqcuzi2mZKN",
|
139
|
-
"email": "john_smith@gmail.com",
|
140
|
-
"first_name": "John",
|
141
|
-
"last_name": "Smith",
|
142
|
-
"created_at": "2011-06-13T00:28:36-04:00",
|
143
|
-
"updated_at": "2012-04-26T20:21:43-04:00"
|
144
|
-
}
|
145
|
-
}
|
146
|
-
fail:
|
147
|
-
response: 'HTTP/1.1 422 Unprocessable Entity'
|
148
|
-
data: |
|
149
|
-
{
|
150
|
-
"message": "Failed to create User",
|
151
|
-
"errors" : {
|
152
|
-
"email": "Email is invalid",
|
153
|
-
...
|
154
|
-
}
|
155
|
-
}
|
156
|
-
curl: |
|
157
|
-
curl -i :api_url/v1/users \
|
158
|
-
-d "user[first_name]=John" \
|
159
|
-
-d "user[last_name]=Smith" \
|
160
|
-
-d "user[email]=john_smith@twg.ca" \
|
161
|
-
-d "user[password]=passpass"
|
54
|
+
Assuming that tests pass their details are doing to be recorded into `docs/api/users.yml` and they will look like this:
|
55
|
+
|
56
|
+
``` yml
|
57
|
+
show:
|
58
|
+
1YGvw8qQDy0Te4oEAxFdTEiS3eQ=:
|
59
|
+
method: GET
|
60
|
+
path: /users/:id
|
61
|
+
params:
|
62
|
+
id: 12345
|
63
|
+
status: 200
|
64
|
+
body:
|
65
|
+
id: 12345
|
66
|
+
name: John Doe
|
67
|
+
YaEdGJRDZy0nsljmpJmOtcLxdUg=:
|
68
|
+
description: When bad user id is passed
|
69
|
+
method: GET
|
70
|
+
path: /users/:id
|
71
|
+
params:
|
72
|
+
id: invalid
|
73
|
+
status: 404
|
74
|
+
body:
|
75
|
+
message: User not found
|
162
76
|
```
|
163
77
|
|
78
|
+
## Usage
|
79
|
+
Just navigate to the path you mounted *api_docs* to. Perhaps `http://yourapp/api-docs`.
|
164
80
|
|
165
81
|
## Configuration
|
166
82
|
|
@@ -168,12 +84,15 @@ You can change the default configuration of this gem by adding the following cod
|
|
168
84
|
|
169
85
|
``` ruby
|
170
86
|
ApiDocs.configure do |config|
|
171
|
-
|
87
|
+
# folder path where api docs are saved to
|
88
|
+
config.docs_path = Rails.root.join('doc/api')
|
89
|
+
|
90
|
+
# controller that ApiDocs controller inherits from.
|
91
|
+
# Useful for hiding it behind admin controller.
|
92
|
+
config.base_controller = 'ApplicationController'
|
172
93
|
end
|
173
94
|
```
|
174
95
|
|
175
|
-
|
176
96
|
---
|
177
97
|
|
178
|
-
Copyright 2012 Jack Neto, [The Working Group, Inc](http://
|
179
|
-
|
98
|
+
Copyright 2012 Oleg Khabarov, Jack Neto, [The Working Group, Inc](http://twg.ca)
|
data/Rakefile
CHANGED
@@ -1,16 +1,31 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = 'api_docs'
|
11
|
+
gem.homepage = 'http://github.com/twg/api_docs'
|
12
|
+
gem.license = 'MIT'
|
13
|
+
gem.summary = 'Generate API documentation using integration tests in Ruby on Rails 3'
|
14
|
+
gem.description = 'Generate API documentation using integration tests in Ruby on Rails 3'
|
15
|
+
gem.email = 'jack@twg.ca'
|
16
|
+
gem.authors = ['Oleg Khabarov', 'Jack Neto', 'The Working Group Inc.']
|
17
|
+
end
|
18
|
+
Jeweler::RubygemsDotOrgTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
4
23
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
gem.email = "jack@twg.ca"
|
12
|
-
gem.authors = ["Jack Neto", 'The Working Group Inc.']
|
13
|
-
gem.add_dependency('rails', '>=3.1.0')
|
14
|
-
gem.add_dependency('bootstrap_builder', '>=0.2.6')
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |t|
|
26
|
+
t.libs << 'lib'
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
15
30
|
end
|
16
|
-
|
31
|
+
task :default => :test
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/api_docs.gemspec
CHANGED
@@ -4,58 +4,99 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.0
|
7
|
+
s.name = "api_docs"
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jack Neto", "The Working Group Inc."]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
11
|
+
s.authors = ["Oleg Khabarov", "Jack Neto", "The Working Group Inc."]
|
12
|
+
s.date = "2012-09-11"
|
13
|
+
s.description = "Generate API documentation using integration tests in Ruby on Rails 3"
|
14
|
+
s.email = "jack@twg.ca"
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"LICENSE
|
16
|
+
"LICENSE",
|
17
17
|
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
20
|
+
"Gemfile",
|
21
|
+
"LICENSE",
|
21
22
|
"README.md",
|
22
23
|
"Rakefile",
|
23
24
|
"VERSION",
|
24
25
|
"api_docs.gemspec",
|
25
|
-
"app/assets/javascripts/api_docs.js
|
26
|
-
"app/assets/
|
27
|
-
"app/
|
28
|
-
"app/views/api_docs/
|
29
|
-
"app/views/api_docs/
|
30
|
-
"app/views/api_docs/
|
31
|
-
"
|
32
|
-
"app/views/api_docs/_params.html.haml",
|
33
|
-
"app/views/api_docs/_response.html.haml",
|
26
|
+
"app/assets/javascripts/api_docs.js",
|
27
|
+
"app/assets/stylesheets/api_docs.css",
|
28
|
+
"app/controllers/api_docs/docs_controller.rb",
|
29
|
+
"app/views/api_docs/docs/_action.html.erb",
|
30
|
+
"app/views/api_docs/docs/_request_params.html.erb",
|
31
|
+
"app/views/api_docs/docs/index.html.erb",
|
32
|
+
"config/routes.rb",
|
34
33
|
"lib/api_docs.rb",
|
35
34
|
"lib/api_docs/configuration.rb",
|
36
35
|
"lib/api_docs/engine.rb",
|
37
|
-
"lib/api_docs/
|
36
|
+
"lib/api_docs/test_helper.rb",
|
37
|
+
"script/rails",
|
38
|
+
"test/api_docs_test.rb",
|
39
|
+
"test/docs_controller_test.rb",
|
40
|
+
"test/dummy/README.rdoc",
|
41
|
+
"test/dummy/Rakefile",
|
42
|
+
"test/dummy/app/assets/images/glyphicons-halflings-white.png",
|
43
|
+
"test/dummy/app/assets/images/glyphicons-halflings.png",
|
44
|
+
"test/dummy/app/assets/javascripts/application.js",
|
45
|
+
"test/dummy/app/assets/javascripts/bootstrap.min.js",
|
46
|
+
"test/dummy/app/assets/stylesheets/application.css",
|
47
|
+
"test/dummy/app/assets/stylesheets/bootstrap.min.css",
|
48
|
+
"test/dummy/app/controllers/application_controller.rb",
|
49
|
+
"test/dummy/app/helpers/application_helper.rb",
|
50
|
+
"test/dummy/app/mailers/.gitkeep",
|
51
|
+
"test/dummy/app/models/.gitkeep",
|
52
|
+
"test/dummy/app/views/layouts/application.html.erb",
|
53
|
+
"test/dummy/config.ru",
|
54
|
+
"test/dummy/config/application.rb",
|
55
|
+
"test/dummy/config/boot.rb",
|
56
|
+
"test/dummy/config/environment.rb",
|
57
|
+
"test/dummy/config/environments/development.rb",
|
58
|
+
"test/dummy/config/environments/production.rb",
|
59
|
+
"test/dummy/config/environments/test.rb",
|
60
|
+
"test/dummy/config/initializers/backtrace_silencers.rb",
|
61
|
+
"test/dummy/config/initializers/inflections.rb",
|
62
|
+
"test/dummy/config/initializers/mime_types.rb",
|
63
|
+
"test/dummy/config/initializers/secret_token.rb",
|
64
|
+
"test/dummy/config/initializers/session_store.rb",
|
65
|
+
"test/dummy/config/initializers/wrap_parameters.rb",
|
66
|
+
"test/dummy/config/locales/en.yml",
|
67
|
+
"test/dummy/config/routes.rb",
|
68
|
+
"test/dummy/lib/assets/.gitkeep",
|
69
|
+
"test/dummy/log/.gitkeep",
|
70
|
+
"test/dummy/public/404.html",
|
71
|
+
"test/dummy/public/422.html",
|
72
|
+
"test/dummy/public/500.html",
|
73
|
+
"test/dummy/public/favicon.ico",
|
74
|
+
"test/dummy/script/rails",
|
75
|
+
"test/test_helper.rb",
|
76
|
+
"test/test_helper_test.rb"
|
38
77
|
]
|
39
|
-
s.homepage =
|
78
|
+
s.homepage = "http://github.com/twg/api_docs"
|
40
79
|
s.licenses = ["MIT"]
|
41
80
|
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version =
|
43
|
-
s.summary =
|
81
|
+
s.rubygems_version = "1.8.23"
|
82
|
+
s.summary = "Generate API documentation using integration tests in Ruby on Rails 3"
|
44
83
|
|
45
84
|
if s.respond_to? :specification_version then
|
46
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
85
|
s.specification_version = 3
|
48
86
|
|
49
87
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
88
|
s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
|
51
|
-
s.add_runtime_dependency(%q<
|
89
|
+
s.add_runtime_dependency(%q<jquery-rails>, [">= 0"])
|
90
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
52
91
|
else
|
53
92
|
s.add_dependency(%q<rails>, [">= 3.1.0"])
|
54
|
-
s.add_dependency(%q<
|
93
|
+
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
94
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
55
95
|
end
|
56
96
|
else
|
57
97
|
s.add_dependency(%q<rails>, [">= 3.1.0"])
|
58
|
-
s.add_dependency(%q<
|
98
|
+
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
99
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
59
100
|
end
|
60
101
|
end
|
61
102
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_self
|
10
|
+
|
11
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*/
|
7
|
+
|
8
|
+
ul#api-doc-nav {
|
9
|
+
box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.067);
|
10
|
+
border-radius: 6px;
|
11
|
+
}
|
12
|
+
ul#api-doc-nav li {
|
13
|
+
font: 14px/20px 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
14
|
+
}
|
15
|
+
ul#api-doc-nav li.nav-header {
|
16
|
+
background-color: #e5e5e5;
|
17
|
+
margin-top: 0px;
|
18
|
+
padding-top: 5px;
|
19
|
+
}
|
20
|
+
ul#api-doc-nav a {
|
21
|
+
border: 1px solid #e5e5e5;
|
22
|
+
padding: 8px 14px;
|
23
|
+
margin-top: -1px;
|
24
|
+
text-align: right;
|
25
|
+
}
|
26
|
+
ul#api-doc-nav > li:first-child {
|
27
|
+
border-radius: 6px 6px 0px 0px;
|
28
|
+
}
|
29
|
+
ul#api-doc-nav > li:last-child > a {
|
30
|
+
border-radius: 0px 0px 6px 6px;
|
31
|
+
}
|
32
|
+
|
33
|
+
table#api-doc-table th {
|
34
|
+
text-align: right;
|
35
|
+
min-width: 100px;
|
36
|
+
}
|
37
|
+
table#api-doc-table td {
|
38
|
+
width: 100%;
|
39
|
+
}
|
40
|
+
table#api-doc-table tr.info th {
|
41
|
+
background-color: #D9EDF7 !important;
|
42
|
+
}
|
43
|
+
table#api-doc-table tr.info td {
|
44
|
+
background-color: #F0F8FC !important;
|
45
|
+
}
|
46
|
+
table#api-doc-table tr.info td code {
|
47
|
+
color: #3A87AD !important;
|
48
|
+
}
|
49
|
+
table#api-doc-table td pre {
|
50
|
+
margin-bottom: 0px;
|
51
|
+
}
|
52
|
+
table#api-doc-table td table {
|
53
|
+
width: auto;
|
54
|
+
}
|
55
|
+
table#api-doc-table td table th {
|
56
|
+
width: auto;
|
57
|
+
min-width: 0px;
|
58
|
+
border-left: 0px;
|
59
|
+
}
|
60
|
+
table#api-doc-table td table td {
|
61
|
+
width: auto;
|
62
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class ApiDocs::DocsController < ApiDocs.config.base_controller.to_s.constantize
|
2
|
+
def index
|
3
|
+
@api_controllers = { }
|
4
|
+
Dir.glob(ApiDocs.config.docs_path.join('*.yml')).each do |file_path|
|
5
|
+
@api_controllers[File.basename(file_path, '.yml')] = YAML.load_file(file_path)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<table class='table table-bordered table-condensed' id='api-doc-table'>
|
2
|
+
|
3
|
+
<tr class='info'>
|
4
|
+
<th>Request</th>
|
5
|
+
<td>
|
6
|
+
<span class='label label-info'><%= action['method']%></span>
|
7
|
+
<code><%= action['path']%></code>
|
8
|
+
</td>
|
9
|
+
</tr>
|
10
|
+
|
11
|
+
<% if action['description'].present? %>
|
12
|
+
<tr>
|
13
|
+
<th>Description</th>
|
14
|
+
<td><%= action['description']%></td>
|
15
|
+
</tr>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<% if action['params'].is_a?(Hash) %>
|
19
|
+
<tr>
|
20
|
+
<th>Parameters</th>
|
21
|
+
<td>
|
22
|
+
<%= render :partial => 'request_params', :object => action['params'] %>
|
23
|
+
</td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
<tr class='info'>
|
28
|
+
<th>Response</th>
|
29
|
+
<td>
|
30
|
+
<span class='label <%= action['status'].to_s[0] == '4' ? 'label-important' : 'label-success' %>'>
|
31
|
+
<%= action['status'] %>
|
32
|
+
</span>
|
33
|
+
</td>
|
34
|
+
</tr>
|
35
|
+
|
36
|
+
<tr>
|
37
|
+
<th>Body</th>
|
38
|
+
<td><pre><%= JSON.pretty_generate(action['body']) %></pre></td>
|
39
|
+
</tr>
|
40
|
+
|
41
|
+
</table>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<div class='row'>
|
2
|
+
<div class='span3'>
|
3
|
+
<ul class='nav nav-list' id='api-doc-nav'>
|
4
|
+
<% @api_controllers.each_with_index do |(controller, actions), ci| %>
|
5
|
+
<li class='nav-header'>
|
6
|
+
<%= controller.gsub(/\W/, '_').humanize.titleize %>
|
7
|
+
</li>
|
8
|
+
<% actions.each_with_index do |(action, data), ai| %>
|
9
|
+
<li class='<%= ci == 0 && ai == 0 ? 'active' : '' %>'>
|
10
|
+
<% tab_id = "#{controller.gsub(/\W/, '_')}_#{action}" %>
|
11
|
+
<%= link_to action.humanize.titleize, "##{tab_id}", :data => {:toggle => 'tab'} %>
|
12
|
+
</li>
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
15
|
+
</ul>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="span9">
|
19
|
+
<div class='tab-content'>
|
20
|
+
<% @api_controllers.each_with_index do |(controller, actions), ci| %>
|
21
|
+
<% actions.each_with_index do |(action, data), ai| %>
|
22
|
+
<% tab_id = "#{controller.gsub(/\W/, '_')}_#{action}" %>
|
23
|
+
<div class='tab-pane <%= ci == 0 && ai == 0 ? 'active' : '' %>' id='<%= tab_id %>'>
|
24
|
+
<% data.each do |key, data| %>
|
25
|
+
<%= render :partial => 'action', :object => data %>
|
26
|
+
<% end %>
|
27
|
+
</div>
|
28
|
+
<% end %>
|
29
|
+
<% end %>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -1,14 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
class ApiDocs::Configuration
|
2
|
+
|
3
|
+
# Where to find the folder with documentation files
|
4
|
+
attr_accessor :docs_path
|
5
|
+
|
6
|
+
# Controller that ApiDocs::DocsController inherits from
|
7
|
+
attr_accessor :base_controller
|
8
|
+
|
9
|
+
# Array of ignored attributes. Attributes that don't really change
|
10
|
+
# the content like timestamps.
|
11
|
+
attr_accessor :ignored_attributes
|
12
12
|
|
13
|
+
# Configuration defaults
|
14
|
+
def initialize
|
15
|
+
@docs_path = Rails.root.join('doc/api')
|
16
|
+
@base_controller = 'ApplicationController'
|
17
|
+
@ignored_attributes = %w(created_at updated_at)
|
13
18
|
end
|
14
19
|
end
|