autodoc 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/autodoc.gemspec +1 -1
- data/lib/autodoc/configuration.rb +17 -1
- data/lib/autodoc/document.rb +12 -20
- data/lib/autodoc/version.rb +1 -1
- data/spec/autodoc/document_spec.rb +116 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9ef350c9fbfa8f0c91c49ea5c5acb2a629c6523
|
4
|
+
data.tar.gz: 39392c1e2cf3561ce80697fdbcd9218fb84978ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e798ec5836925fe93635c501839d496097730c16bb3aca7687429f2ada856be3ecdce649e7aa30e9fd006c21e7ace1b9cfdafc08cb6b0baeef18e40305d8ef00
|
7
|
+
data.tar.gz: b2fe73a5cc1732fca123ebcad91f4c60935ac238fbae10727a2125d181a79114019fe0d935efc94cecb6609a7460eafb270e99c5947d481b2c18f2286bc395ac
|
data/README.md
CHANGED
@@ -58,3 +58,35 @@ response:
|
|
58
58
|
}
|
59
59
|
```
|
60
60
|
</pre>
|
61
|
+
|
62
|
+
## Custom template
|
63
|
+
You can customize autodoc's template ([Example](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/document.rb#L126-L139)).
|
64
|
+
Here are avilable variables:
|
65
|
+
|
66
|
+
* description
|
67
|
+
* method
|
68
|
+
* parameters_section
|
69
|
+
* path
|
70
|
+
* request_body_section
|
71
|
+
* response_body
|
72
|
+
* response_headers
|
73
|
+
* response_status
|
74
|
+
|
75
|
+
<pre>
|
76
|
+
Autodoc.configuration.template = <<-EOF
|
77
|
+
## <%= request.method %> <%= path %>
|
78
|
+
<%= example.description.capitalize %>.
|
79
|
+
<%= parameters_section %>
|
80
|
+
### request
|
81
|
+
```
|
82
|
+
<%= request.method %> <%= request.path %>
|
83
|
+
```
|
84
|
+
<%= request_body_section %>
|
85
|
+
### response
|
86
|
+
```ruby
|
87
|
+
Status: <%= response.status %><%= headers %>
|
88
|
+
response: <%= response_body %>
|
89
|
+
```
|
90
|
+
|
91
|
+
EOF
|
92
|
+
</pre>
|
data/autodoc.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Autodoc::VERSION
|
9
9
|
spec.authors = ["Ryo Nakamura"]
|
10
10
|
spec.email = ["r7kamura@gmail.com"]
|
11
|
-
spec.summary = "Auto-generate API documents from your request-specs."
|
11
|
+
spec.summary = "Auto-generate JSON API documents from your request-specs."
|
12
12
|
spec.homepage = "https://github.com/r7kamura/autodoc"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
@@ -7,7 +7,7 @@
|
|
7
7
|
#
|
8
8
|
module Autodoc
|
9
9
|
class Configuration
|
10
|
-
attr_accessor :headers
|
10
|
+
attr_accessor :headers, :template
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
reset
|
@@ -15,6 +15,22 @@ module Autodoc
|
|
15
15
|
|
16
16
|
def reset
|
17
17
|
@headers = %w[location]
|
18
|
+
@template = <<-EOF.strip_heredoc
|
19
|
+
## <%= method %> <%= path %>
|
20
|
+
<%= description %>
|
21
|
+
<%= parameters_section %>
|
22
|
+
### request
|
23
|
+
```
|
24
|
+
<%= method %> <%= path %>
|
25
|
+
```
|
26
|
+
<%= request_body_section %>
|
27
|
+
### response
|
28
|
+
```ruby
|
29
|
+
Status: <%= response_status %><%= response_headers %>
|
30
|
+
response: <%= response_body %>
|
31
|
+
```
|
32
|
+
|
33
|
+
EOF
|
18
34
|
end
|
19
35
|
end
|
20
36
|
end
|
data/lib/autodoc/document.rb
CHANGED
@@ -14,13 +14,17 @@ module Autodoc
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def render
|
17
|
-
ERB.new(template).result(binding)
|
17
|
+
ERB.new(Autodoc.configuration.template).result(binding)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def description
|
23
|
+
"#{example.description.capitalize}."
|
24
|
+
end
|
25
|
+
|
26
|
+
def method
|
27
|
+
request.method
|
24
28
|
end
|
25
29
|
|
26
30
|
def path
|
@@ -44,6 +48,10 @@ module Autodoc
|
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
51
|
+
def response_status
|
52
|
+
response.status
|
53
|
+
end
|
54
|
+
|
47
55
|
def parameters
|
48
56
|
validators.map {|validator| Parameter.new(validator) }.join("\n")
|
49
57
|
end
|
@@ -64,7 +72,7 @@ module Autodoc
|
|
64
72
|
WeakParameters.stats[request.params[:controller]][request.params[:action]].try(:validators)
|
65
73
|
end
|
66
74
|
|
67
|
-
def
|
75
|
+
def response_headers
|
68
76
|
Autodoc.configuration.headers.map do |header|
|
69
77
|
"\n#{header}: #{response.headers[header]}" if response.headers[header]
|
70
78
|
end.compact.join
|
@@ -109,19 +117,3 @@ module Autodoc
|
|
109
117
|
end
|
110
118
|
end
|
111
119
|
end
|
112
|
-
|
113
|
-
__END__
|
114
|
-
## <%= request.method %> <%= path %>
|
115
|
-
<%= example.description.capitalize %>.
|
116
|
-
<%= parameters_section %>
|
117
|
-
### request
|
118
|
-
```
|
119
|
-
<%= request.method %> <%= request.path %>
|
120
|
-
```
|
121
|
-
<%= request_body_section %>
|
122
|
-
### response
|
123
|
-
```ruby
|
124
|
-
Status: <%= response.status %><%= headers %>
|
125
|
-
response: <%= response_body %>
|
126
|
-
```
|
127
|
-
|
data/lib/autodoc/version.rb
CHANGED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Autodoc::Document do
|
4
|
+
describe ".render" do
|
5
|
+
subject do
|
6
|
+
described_class.render(example, request, response)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:example) do
|
10
|
+
double(
|
11
|
+
description: description,
|
12
|
+
full_description: "#{method} #{path} #{description}",
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:description) do
|
17
|
+
"returns a recipe"
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:request) do
|
21
|
+
double(
|
22
|
+
body: StringIO.new,
|
23
|
+
params: {},
|
24
|
+
method: method,
|
25
|
+
path: path,
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:response) do
|
30
|
+
double(
|
31
|
+
body: response_body,
|
32
|
+
headers: {},
|
33
|
+
status: 200,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:method) do
|
38
|
+
"GET"
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:path) do
|
42
|
+
"/recipes/1"
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:response_body) do
|
46
|
+
{}.to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
context "without Autodoc.configuration.template" do
|
50
|
+
it "uses default template" do
|
51
|
+
should == <<-EOF.strip_heredoc
|
52
|
+
## GET /recipes/1
|
53
|
+
Returns a recipe.
|
54
|
+
|
55
|
+
### request
|
56
|
+
```
|
57
|
+
GET /recipes/1
|
58
|
+
```
|
59
|
+
|
60
|
+
### response
|
61
|
+
```ruby
|
62
|
+
Status: 200
|
63
|
+
response:
|
64
|
+
{}
|
65
|
+
```
|
66
|
+
|
67
|
+
EOF
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with Autodoc.configuration.template" do
|
72
|
+
before do
|
73
|
+
Autodoc.configuration.template = <<-EOF.strip_heredoc
|
74
|
+
### request
|
75
|
+
```
|
76
|
+
<%= method %> <%= path %>
|
77
|
+
```
|
78
|
+
<%= request_body_section %>
|
79
|
+
### response
|
80
|
+
```ruby
|
81
|
+
Status: <%= response_status %><%= response_headers %>
|
82
|
+
response: <%= response_body %>
|
83
|
+
```
|
84
|
+
|
85
|
+
## <%= method %> <%= path %>
|
86
|
+
<%= description %>
|
87
|
+
<%= parameters_section %>
|
88
|
+
EOF
|
89
|
+
end
|
90
|
+
|
91
|
+
after do
|
92
|
+
Autodoc.configuration.reset
|
93
|
+
end
|
94
|
+
|
95
|
+
it "uses custom template" do
|
96
|
+
should == <<-EOF.strip_heredoc
|
97
|
+
### request
|
98
|
+
```
|
99
|
+
GET /recipes/1
|
100
|
+
```
|
101
|
+
|
102
|
+
### response
|
103
|
+
```ruby
|
104
|
+
Status: 200
|
105
|
+
response:
|
106
|
+
{}
|
107
|
+
```
|
108
|
+
|
109
|
+
## GET /recipes/1
|
110
|
+
Returns a recipe.
|
111
|
+
|
112
|
+
EOF
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autodoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/autodoc/configuration.rb
|
113
113
|
- lib/autodoc/document.rb
|
114
114
|
- lib/autodoc/version.rb
|
115
|
+
- spec/autodoc/document_spec.rb
|
115
116
|
- spec/dummy/Rakefile
|
116
117
|
- spec/dummy/app/assets/javascripts/application.js
|
117
118
|
- spec/dummy/app/assets/stylesheets/application.css
|
@@ -173,8 +174,9 @@ rubyforge_project:
|
|
173
174
|
rubygems_version: 2.0.3
|
174
175
|
signing_key:
|
175
176
|
specification_version: 4
|
176
|
-
summary: Auto-generate API documents from your request-specs.
|
177
|
+
summary: Auto-generate JSON API documents from your request-specs.
|
177
178
|
test_files:
|
179
|
+
- spec/autodoc/document_spec.rb
|
178
180
|
- spec/dummy/Rakefile
|
179
181
|
- spec/dummy/app/assets/javascripts/application.js
|
180
182
|
- spec/dummy/app/assets/stylesheets/application.css
|