autodoc 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +12 -66
- data/lib/autodoc/configuration.rb +27 -11
- data/lib/autodoc/document.rb +16 -0
- data/lib/autodoc/documents.rb +24 -4
- data/lib/autodoc/{template.md.erb → templates/document.md.erb} +1 -1
- data/lib/autodoc/templates/toc.md.erb +11 -0
- data/lib/autodoc/version.rb +1 -1
- data/spec/dummy/doc/recipes.md +4 -5
- data/spec/dummy/doc/toc.md +4 -0
- data/spec/spec_helper.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b183416b270d62f730b447ecf874adbe4a98a3c
|
4
|
+
data.tar.gz: f97bce1b7f34b7cd873027f161c8dbe03fb881fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d82ae6802bd524f235ac12354426c7938ff6cb03984f6fd7e0b21433b851368b6cb41b0cdf49a3cba9b18c96bac9b83aa03b5db6fd45b03f615dfc4b783fb50
|
7
|
+
data.tar.gz: 6025d431e657cc03a59f80875c1fbaf2b797e5ef0faa5f2c7c60f21a4f75ea2924b29fab7fdfef991e5d20cc209905ef2af35f31b3876e1d574300397d401978
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -7,12 +7,7 @@ gem "autodoc", group: :test
|
|
7
7
|
```
|
8
8
|
|
9
9
|
## Usage
|
10
|
-
All request-specs tagged with `:autodoc` will be auto-documented.
|
11
|
-
You must include a HTTP method and request path in the example description.
|
12
|
-
|
13
|
-
```
|
14
|
-
$ AUTODOC=1 rspec
|
15
|
-
```
|
10
|
+
All request-specs tagged with `:autodoc` will be auto-documented.
|
16
11
|
|
17
12
|
```ruby
|
18
13
|
# spec/requests/recipes_spec.rb
|
@@ -30,67 +25,18 @@ describe "Recipes" do
|
|
30
25
|
end
|
31
26
|
```
|
32
27
|
|
33
|
-
|
28
|
+
Run rspec with AUTODOC=1 to generate documents. ([example](https://github.com/r7kamura/autodoc/blob/master/spec/dummy/doc/recipes.md))
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
```
|
40
|
-
POST /recipes
|
30
|
+
```sh
|
31
|
+
# shell-command
|
32
|
+
AUTODOC=1 rspec
|
41
33
|
```
|
42
34
|
|
43
|
-
###
|
44
|
-
|
45
|
-
* `type` integer
|
46
|
-
|
47
|
-
### response
|
48
|
-
```
|
49
|
-
Status: 201
|
50
|
-
location: http://www.example.com/recipes/1
|
51
|
-
response:
|
52
|
-
{
|
53
|
-
"created_at" => "2013-06-07T08:28:35Z",
|
54
|
-
"id" => 1,
|
55
|
-
"name" => "alice",
|
56
|
-
"type" => 1,
|
57
|
-
"updated_at" => "2013-06-07T08:28:35Z"
|
58
|
-
}
|
59
|
-
```
|
60
|
-
</pre>
|
61
|
-
|
62
|
-
## Custom template
|
63
|
-
You can customize autodoc's template ([Example](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/configuration.rb#L18-L33)).
|
64
|
-
Here are avilable variables:
|
65
|
-
|
66
|
-
* description
|
67
|
-
* example
|
68
|
-
* method
|
69
|
-
* parameters_section
|
70
|
-
* path
|
71
|
-
* request
|
72
|
-
* request_body_section
|
73
|
-
* response
|
74
|
-
* response_body
|
75
|
-
* response_headers
|
76
|
-
* response_status
|
77
|
-
|
78
|
-
### Example
|
79
|
-
<pre>
|
80
|
-
Autodoc.configuration.template = <<-EOF
|
81
|
-
## <%= method %> <%= path %>
|
82
|
-
<%= description %>
|
83
|
-
<%= parameters_section %>
|
84
|
-
### request
|
85
|
-
```
|
86
|
-
<%= method %> <%= path %>
|
87
|
-
```
|
88
|
-
<%= request_body_section %>
|
89
|
-
### response
|
90
|
-
```ruby
|
91
|
-
Status: <%= response_status %><%= response_headers %>
|
92
|
-
response: <%= response_body %>
|
93
|
-
```
|
35
|
+
### Configuration
|
36
|
+
You can configure `Autodoc.configuration` to change its behavior:
|
94
37
|
|
95
|
-
|
96
|
-
|
38
|
+
* path - [String] location to put files (default: ./doc)
|
39
|
+
* headers - [Array] keys of documented response header (default: ["Location"])
|
40
|
+
* template - [String] ERB template for each document (default: [document.md.erb](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/templates/document.md.erb))
|
41
|
+
* toc_template - [String] ERB template for ToC (default: [toc.md.erb](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/templates/toc.md.erb))
|
42
|
+
* toc - [Boolean] whether to generate toc.md (default: false)
|
@@ -1,21 +1,37 @@
|
|
1
1
|
module Autodoc
|
2
2
|
class Configuration
|
3
|
-
|
3
|
+
class << self
|
4
|
+
def property(name, &default)
|
5
|
+
define_method(name) do
|
6
|
+
if instance_variable_defined?("@#{name}")
|
7
|
+
instance_variable_get("@#{name}")
|
8
|
+
else
|
9
|
+
instance_variable_set("@#{name}", instance_exec(&default))
|
10
|
+
end
|
11
|
+
end
|
4
12
|
|
5
|
-
|
6
|
-
|
13
|
+
attr_writer name
|
14
|
+
end
|
7
15
|
end
|
8
16
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
property :path do
|
18
|
+
"doc"
|
19
|
+
end
|
20
|
+
|
21
|
+
property :headers do
|
22
|
+
%w[Location]
|
23
|
+
end
|
24
|
+
|
25
|
+
property :template do
|
26
|
+
File.read(File.expand_path("../templates/document.md.erb", __FILE__))
|
27
|
+
end
|
28
|
+
|
29
|
+
property :toc_template do
|
30
|
+
File.read(File.expand_path("../templates/toc.md.erb", __FILE__))
|
15
31
|
end
|
16
32
|
|
17
|
-
|
18
|
-
|
33
|
+
property :toc do
|
34
|
+
false
|
19
35
|
end
|
20
36
|
end
|
21
37
|
end
|
data/lib/autodoc/document.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "action_dispatch/http/request"
|
2
2
|
require "erb"
|
3
|
+
require "pathname"
|
3
4
|
|
4
5
|
module Autodoc
|
5
6
|
class Document
|
@@ -11,10 +12,25 @@ module Autodoc
|
|
11
12
|
@context = context
|
12
13
|
end
|
13
14
|
|
15
|
+
def pathname
|
16
|
+
@path ||= begin
|
17
|
+
payload = @context.example.file_path.gsub(%r<\./spec/requests/(.+)_spec\.rb>, '\1.md')
|
18
|
+
Pathname.new(Autodoc.configuration.path) + payload
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
def render
|
15
23
|
ERB.new(Autodoc.configuration.template, nil, "-").result(binding)
|
16
24
|
end
|
17
25
|
|
26
|
+
def title
|
27
|
+
"#{method} #{path}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def identifier
|
31
|
+
title.gsub(" ", "-").gsub(/[:_\/]/, "").downcase
|
32
|
+
end
|
33
|
+
|
18
34
|
private
|
19
35
|
|
20
36
|
def request
|
data/lib/autodoc/documents.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
module Autodoc
|
2
4
|
class Documents
|
3
5
|
def initialize
|
@@ -5,16 +7,34 @@ module Autodoc
|
|
5
7
|
end
|
6
8
|
|
7
9
|
def append(context)
|
8
|
-
|
9
|
-
|
10
|
-
@table[key] << Autodoc::Document.render(context)
|
10
|
+
document = Autodoc::Document.new(context.clone)
|
11
|
+
@table[document.pathname] << document
|
11
12
|
end
|
12
13
|
|
13
14
|
def write
|
15
|
+
write_toc if Autodoc.configuration.toc
|
16
|
+
write_documents
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def write_documents
|
14
22
|
@table.each do |pathname, documents|
|
15
23
|
pathname.parent.mkpath
|
16
|
-
pathname.open("w") {|file| file << documents.join("\n").rstrip + "\n" }
|
24
|
+
pathname.open("w") {|file| file << documents.map(&:render).join("\n").rstrip + "\n" }
|
17
25
|
end
|
18
26
|
end
|
27
|
+
|
28
|
+
def write_toc
|
29
|
+
toc_path.open("w") {|file| file << render_toc }
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_toc
|
33
|
+
ERB.new(Autodoc.configuration.toc_template, nil, "-").result(binding)
|
34
|
+
end
|
35
|
+
|
36
|
+
def toc_path
|
37
|
+
Pathname.new(Autodoc.configuration.path) + "toc.md"
|
38
|
+
end
|
19
39
|
end
|
20
40
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# coding: UTF-8 -%>
|
2
|
+
## Table of Contents
|
3
|
+
<% @table.each do |pathname, documents| -%>
|
4
|
+
* [<%= pathname.basename %>](<%= pathname.basename %>)
|
5
|
+
<% documents.group_by(&:title).each do |title, documents| -%>
|
6
|
+
<% documents.each_with_index do |document, index| -%>
|
7
|
+
<% suffix = index == 0 ? "" : "-#{index}" -%>
|
8
|
+
* [<%= title %>](<%= "#{pathname.basename}##{document.identifier}#{suffix}" %>)
|
9
|
+
<% end -%>
|
10
|
+
<% end -%>
|
11
|
+
<% end -%>
|
data/lib/autodoc/version.rb
CHANGED
data/spec/dummy/doc/recipes.md
CHANGED
@@ -23,12 +23,11 @@ response:
|
|
23
23
|
"id": 1,
|
24
24
|
"name": "name",
|
25
25
|
"type": 1,
|
26
|
-
"created_at": "2013-11-
|
27
|
-
"updated_at": "2013-11-
|
26
|
+
"created_at": "2013-11-30T18:15:08.928Z",
|
27
|
+
"updated_at": "2013-11-30T18:15:08.928Z"
|
28
28
|
}
|
29
29
|
```
|
30
30
|
|
31
|
-
|
32
31
|
## POST /recipes
|
33
32
|
Creates a new recipe.
|
34
33
|
|
@@ -54,7 +53,7 @@ response:
|
|
54
53
|
"id": 1,
|
55
54
|
"name": "name",
|
56
55
|
"type": 1,
|
57
|
-
"created_at": "2013-11-
|
58
|
-
"updated_at": "2013-11-
|
56
|
+
"created_at": "2013-11-30T18:15:08.938Z",
|
57
|
+
"updated_at": "2013-11-30T18:15:08.938Z"
|
59
58
|
}
|
60
59
|
```
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,9 @@ require File.expand_path("../../spec/dummy/config/environment", __FILE__)
|
|
3
3
|
require "rspec/rails"
|
4
4
|
require "rspec/autorun"
|
5
5
|
|
6
|
+
Autodoc.configuration.toc = true
|
7
|
+
Autodoc.configuration.path = "spec/dummy/doc"
|
8
|
+
|
6
9
|
RSpec.configure do |config|
|
7
10
|
# If you"re not using ActiveRecord, or you"d prefer not to run each of your
|
8
11
|
# examples within a transaction, remove the following line or assign false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autodoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -113,7 +113,8 @@ files:
|
|
113
113
|
- lib/autodoc/document.rb
|
114
114
|
- lib/autodoc/documents.rb
|
115
115
|
- lib/autodoc/rspec.rb
|
116
|
-
- lib/autodoc/
|
116
|
+
- lib/autodoc/templates/document.md.erb
|
117
|
+
- lib/autodoc/templates/toc.md.erb
|
117
118
|
- lib/autodoc/version.rb
|
118
119
|
- spec/dummy/Rakefile
|
119
120
|
- spec/dummy/app/assets/javascripts/application.js
|
@@ -144,6 +145,7 @@ files:
|
|
144
145
|
- spec/dummy/db/migrate/20130607075126_create_recipes.rb
|
145
146
|
- spec/dummy/db/schema.rb
|
146
147
|
- spec/dummy/doc/recipes.md
|
148
|
+
- spec/dummy/doc/toc.md
|
147
149
|
- spec/dummy/lib/assets/.gitkeep
|
148
150
|
- spec/dummy/log/.gitkeep
|
149
151
|
- spec/dummy/public/404.html
|
@@ -207,6 +209,7 @@ test_files:
|
|
207
209
|
- spec/dummy/db/migrate/20130607075126_create_recipes.rb
|
208
210
|
- spec/dummy/db/schema.rb
|
209
211
|
- spec/dummy/doc/recipes.md
|
212
|
+
- spec/dummy/doc/toc.md
|
210
213
|
- spec/dummy/lib/assets/.gitkeep
|
211
214
|
- spec/dummy/log/.gitkeep
|
212
215
|
- spec/dummy/public/404.html
|