grape-doc 0.1.1 → 0.3.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/grape-doc.gemspec +1 -1
- data/lib/grape/doc/doc_class/parser.rb +18 -0
- data/lib/grape/doc/generator.rb +44 -26
- data/test/sample.html +28 -1
- data/test/test_all.rb +4 -0
- data/test/test_generator.rb +11 -0
- data/test/test_sample_api.rb +2 -0
- metadata +10 -8
- data/test/test_doc_gen.rb +0 -15
- /data/test/{test_object_space_collector.rb → test_collector.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c9c454799bd7aea1036f9f1a05aa6a4105d9676
|
4
|
+
data.tar.gz: 39921c04e363881c8f85c037a322c06dfd10ce10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8c0d7e1916d2dcaeaa8940d61fbf71c449da3ba5fe57306d7b4fae1e267c64ed10e826b8331853e03e72a82c1b6f6ccd4eee7e8c69985c27e036de32b6fa870
|
7
|
+
data.tar.gz: e57b8ce60926e4f2eff95e8c4818332042c9a580e044b385e5cad0b6ceaa065da35618164da8f3a00c4c1c1f792bd3cbab018fa4eac8193d138ca4f88e9c5e69
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/grape-doc.gemspec
CHANGED
@@ -48,6 +48,24 @@ module GrapeDoc
|
|
48
48
|
|
49
49
|
end
|
50
50
|
|
51
|
+
def typer(obj)
|
52
|
+
case obj
|
53
|
+
|
54
|
+
when Array
|
55
|
+
obj.map(&:typer)
|
56
|
+
|
57
|
+
when Hash
|
58
|
+
obj.reduce({}){|m,o| m.merge!(o[0] => typer(o[1]) ) ;m}
|
59
|
+
|
60
|
+
when Class,Module
|
61
|
+
obj
|
62
|
+
|
63
|
+
else
|
64
|
+
obj.class
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
51
69
|
|
52
70
|
end
|
53
71
|
end
|
data/lib/grape/doc/generator.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
+
require 'json'
|
1
2
|
module GrapeDoc
|
2
3
|
class Generator
|
3
4
|
|
4
|
-
|
5
|
+
attr_reader :options
|
5
6
|
def initialize(opts={})
|
6
7
|
|
7
8
|
raise(ArgumentError,'invalid options given') unless opts.class <= Hash
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
)
|
13
|
-
|
14
|
-
self.file_path= opts[:path] || opts['path'] || File.join(Helpers.doc_folder_path,'api_doc.html')
|
9
|
+
@options = {
|
10
|
+
'format' => 'html',
|
11
|
+
'path' => File.join(Helpers.doc_folder_path,'api_doc.html')
|
12
|
+
}.merge(opts.reduce({}){|m,o| m.merge!(o[0].to_s => o[1]) ;m})
|
15
13
|
|
16
14
|
process_head
|
17
15
|
process_table_of_content
|
@@ -25,7 +23,7 @@ module GrapeDoc
|
|
25
23
|
|
26
24
|
def save
|
27
25
|
|
28
|
-
File.write self.
|
26
|
+
File.write self.options['path'],
|
29
27
|
document.to_textile.to_html
|
30
28
|
|
31
29
|
true;rescue;false
|
@@ -47,6 +45,8 @@ module GrapeDoc
|
|
47
45
|
Helpers.each_grape_class do |rest_api_model|
|
48
46
|
rest_api_model.routes.each do |route|
|
49
47
|
|
48
|
+
next if route.route_path =~ /\(\.:format\)\(\.:format\)$/
|
49
|
+
|
50
50
|
document.add :h2, "#{route.route_method.to_s.upcase}: #{route.route_path}"
|
51
51
|
document.add :h3, 'Request'
|
52
52
|
document.add :h4, 'description'
|
@@ -81,33 +81,51 @@ module GrapeDoc
|
|
81
81
|
route_path_var = route.route_path.to_s.sub(/\(\.:format\)$/,'')
|
82
82
|
@poc_data ||= Helpers.poc_data
|
83
83
|
if @poc_data && @poc_data.find{|k,v| k =~ /^#{route_path_var}/ }
|
84
|
-
|
85
|
-
poc_opts = @poc_data[route_path_var][route.route_method.to_s.upcase]
|
84
|
+
route_method_var = route.route_method.to_s.upcase
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
document.add :raw,poc_opts['response']['raw_body']
|
86
|
+
poc_cases = @poc_data.select{|k,v|
|
87
|
+
k =~ /^#{route_path_var}\.?/ && v.keys.include?(route_method_var)
|
88
|
+
}
|
91
89
|
|
92
|
-
|
93
|
-
|
94
|
-
document.add :list,[
|
95
|
-
"'status code: #{poc_opts['response']['status']}",
|
96
|
-
"format: #{poc_opts['response']['format']}"
|
97
|
-
]
|
90
|
+
document.add :h3,'Response'
|
98
91
|
|
92
|
+
poc_cases.each do |poc_path,poc_data|
|
93
|
+
poc_opts = poc_data[route_method_var] || next
|
99
94
|
|
100
95
|
document.add :h4,'example'
|
101
96
|
|
102
97
|
document.add :h5,'curl sample'
|
103
|
-
|
104
98
|
document.add :raw,[
|
105
|
-
"curl ",
|
106
|
-
"-X #{
|
107
|
-
"\"http
|
108
|
-
"#{poc_opts['request']['query']['raw']}\""
|
99
|
+
"$ curl ",
|
100
|
+
"-X #{route_method_var} ",
|
101
|
+
"\"http://#{ -> { poc_opts['response']['headers']['HTTP_HOST'] rescue 'example.org' }.call}",
|
102
|
+
"#{poc_path}?","#{poc_opts['request']['query']['raw']}\" ",
|
103
|
+
poc_opts['request']['headers'].map{|k,v| "-H \"#{k}: #{v}\"" }.join(' ')
|
109
104
|
].join
|
110
105
|
|
106
|
+
document.add :list,[
|
107
|
+
"status code: #{poc_opts['response']['status']}",
|
108
|
+
"format type: #{poc_opts['response']['format']}"
|
109
|
+
]
|
110
|
+
|
111
|
+
document.add :h6,'raw body'
|
112
|
+
document.add :raw,poc_opts['response']['raw_body']
|
113
|
+
|
114
|
+
if JSON.respond_to?(:pretty_generate)
|
115
|
+
|
116
|
+
document.add :h6,'json formatted body with Class types'
|
117
|
+
document.add :raw,
|
118
|
+
JSON.pretty_generate(
|
119
|
+
ApiDocParts::Parser.typer(poc_opts['response']['body'])
|
120
|
+
)
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
if -> { @poc_data[route_path_var][route.route_method.to_s.upcase] rescue nil }.call
|
128
|
+
poc_opts = @poc_data[route_path_var][route.route_method.to_s.upcase]
|
111
129
|
|
112
130
|
|
113
131
|
end
|
data/test/sample.html
CHANGED
@@ -13,4 +13,31 @@
|
|
13
13
|
<li>type: String</li>
|
14
14
|
<li>desc: it’s a test string</li>
|
15
15
|
</ul></li>
|
16
|
-
</ul>
|
16
|
+
</ul>
|
17
|
+
<h3>Response</h3>
|
18
|
+
<h4>example</h4>
|
19
|
+
<h5>curl sample</h5>
|
20
|
+
<pre>$ curl -X GET "http://example.org/hello?test=hy" -H "Accept-Version: v1" -H "X-Token: blabla"</pre>
|
21
|
+
<ul>
|
22
|
+
<li>status code: 200</li>
|
23
|
+
<li>format type: json</li>
|
24
|
+
</ul>
|
25
|
+
<h6>raw body</h6>
|
26
|
+
<pre>{"hello":"world!"}</pre>
|
27
|
+
<h6>json formatted body with Class types</h6>
|
28
|
+
<pre>{
|
29
|
+
"hello": "String"
|
30
|
+
}</pre>
|
31
|
+
<h4>example</h4>
|
32
|
+
<h5>curl sample</h5>
|
33
|
+
<pre>$ curl -X GET "http://example.org/hello.json?" -H "Accept-Version: v1" -H "X-Token: blabla"</pre>
|
34
|
+
<ul>
|
35
|
+
<li>status code: 200</li>
|
36
|
+
<li>format type: json</li>
|
37
|
+
</ul>
|
38
|
+
<h6>raw body</h6>
|
39
|
+
<pre>{"hello":"world!"}</pre>
|
40
|
+
<h6>json formatted body with Class types</h6>
|
41
|
+
<pre>{
|
42
|
+
"hello": "String"
|
43
|
+
}</pre>
|
data/test/test_all.rb
ADDED
data/test/test_sample_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.0
|
103
|
+
version: 1.1.0
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.0
|
110
|
+
version: 1.1.0
|
111
111
|
description: " Documentation generator for Grape module compatible with Redmine and
|
112
112
|
Github formats "
|
113
113
|
email:
|
@@ -136,9 +136,10 @@ files:
|
|
136
136
|
- lib/grape/doc/helper.rb
|
137
137
|
- lib/grape/doc/prototype.rb
|
138
138
|
- test/sample.html
|
139
|
-
- test/
|
139
|
+
- test/test_all.rb
|
140
|
+
- test/test_collector.rb
|
141
|
+
- test/test_generator.rb
|
140
142
|
- test/test_helper.rb
|
141
|
-
- test/test_object_space_collector.rb
|
142
143
|
- test/test_sample_api.rb
|
143
144
|
homepage: https://github.com/adamluzsi/grape-doc
|
144
145
|
licenses: []
|
@@ -165,8 +166,9 @@ specification_version: 4
|
|
165
166
|
summary: Documentation generator for Grape module
|
166
167
|
test_files:
|
167
168
|
- test/sample.html
|
168
|
-
- test/
|
169
|
+
- test/test_all.rb
|
170
|
+
- test/test_collector.rb
|
171
|
+
- test/test_generator.rb
|
169
172
|
- test/test_helper.rb
|
170
|
-
- test/test_object_space_collector.rb
|
171
173
|
- test/test_sample_api.rb
|
172
174
|
has_rdoc:
|
data/test/test_doc_gen.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
describe 'Doc generating' do
|
3
|
-
|
4
|
-
specify 'test documentation generator' do
|
5
|
-
|
6
|
-
var = GrapeDoc.new
|
7
|
-
puts var.document.to_textile
|
8
|
-
File.write File.join(RackTestPoc.root,'test','sample.html'),
|
9
|
-
var.document.to_textile.to_html
|
10
|
-
|
11
|
-
GrapeDoc.generate
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
File without changes
|