autodoc 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c9fe5187c39c827ab6be62b63806e00ac493ded
4
- data.tar.gz: 7a818753de51a40957017592b3d4eae69b07ad77
3
+ metadata.gz: a9ef350c9fbfa8f0c91c49ea5c5acb2a629c6523
4
+ data.tar.gz: 39392c1e2cf3561ce80697fdbcd9218fb84978ac
5
5
  SHA512:
6
- metadata.gz: 804a15e5737d47de9b21d636b95973dcc489be4ea92f4c640b7a6349406d955d94cfbb7eb1259b77d48fc1fd762c85fe07115737933efc67adef931d40d3d8b7
7
- data.tar.gz: 8e026ef386e3c3c255264965f8ebb7f215a437e1082e004472bf34a380dc6054f6c2bbc292dc79b579d461776e22bf05c0051da0269a686a3868cab5a0066d71
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 = &lt;&lt;-EOF
77
+ ## &lt;%= request.method %&gt; &lt;%= path %&gt;
78
+ &lt;%= example.description.capitalize %&gt;.
79
+ &lt;%= parameters_section %&gt;
80
+ ### request
81
+ ```
82
+ &lt;%= request.method %&gt; &lt;%= request.path %&gt;
83
+ ```
84
+ &lt;%= request_body_section %&gt;
85
+ ### response
86
+ ```ruby
87
+ Status: &lt;%= response.status %&gt;&lt;%= headers %&gt;
88
+ response: &lt;%= response_body %&gt;
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
@@ -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 template
23
- File.read(__FILE__).split("__END__\n", 2).last
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 headers
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
-
@@ -1,3 +1,3 @@
1
1
  module Autodoc
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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-12 00:00:00.000000000 Z
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