grape_documenter 0.1.0 → 0.2.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/README.md +1 -3
- data/bin/grape_documenter +16 -1
- data/lib/grape_documenter/generator.rb +4 -1
- data/lib/grape_documenter/route_doc.rb +3 -2
- data/lib/grape_documenter/version.rb +1 -1
- data/spec/generator_spec.rb +22 -0
- data/spec/route_doc_spec.rb +8 -0
- metadata +4 -3
data/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
|
20
20
|
|
|
21
21
|
Within the root of you Rails Application run the following rake task...
|
|
22
22
|
|
|
23
|
-
$ bundle exec
|
|
23
|
+
$ bundle exec grape_docuementer 'MyApp::Api' '/path/to/docs' --format='html' --mounted-path='/api
|
|
24
24
|
|
|
25
25
|
The first argument is the a string of the class of Grape::API. If you have multiple APIs within the same application you can run the task as many times as you like with different output paths.
|
|
26
26
|
|
|
@@ -28,8 +28,6 @@ The first argument is the a string of the class of Grape::API. If you have multi
|
|
|
28
28
|
|
|
29
29
|
Currently 2 formats are supported: 'html'; 'textile'. The default is html. You can change the format as shown below...
|
|
30
30
|
|
|
31
|
-
$ bundle exec grape_doc 'MyApplication::API' '/path/to/where/you/want/your/docs' 'textile'
|
|
32
|
-
|
|
33
31
|
## Contributing
|
|
34
32
|
|
|
35
33
|
1. Fork it
|
data/bin/grape_documenter
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
require 'grape_documenter'
|
|
4
|
+
require 'optparse'
|
|
4
5
|
|
|
5
6
|
begin
|
|
6
7
|
require File.expand_path(Dir.pwd + "/config/environment")
|
|
@@ -8,5 +9,19 @@ rescue LoadError => ex
|
|
|
8
9
|
puts "#{ex}"
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
options = {}
|
|
13
|
+
|
|
14
|
+
OptionParser.new do |opts|
|
|
15
|
+
opts.banner = "Usage: bundle exec grape_docuementer 'MyApp::Api' '/path/to/docs' --format='html' --mounted-path='/api'"
|
|
16
|
+
|
|
17
|
+
opts.on('--format [OPT]', "Output format. Defaults to html" ) do |f|
|
|
18
|
+
options[:format] = f
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
opts.on('--mounted-path [OPT]', "Path to where API is mounted. Defaults to /" ) do |path|
|
|
22
|
+
options[:mounted_path] = path
|
|
23
|
+
end
|
|
24
|
+
end.parse!
|
|
25
|
+
|
|
26
|
+
generator = GrapeDocumenter::Generator.new(ARGV[0], ARGV[1], options)
|
|
12
27
|
generator.output
|
|
@@ -3,6 +3,8 @@ require 'active_support/inflector'
|
|
|
3
3
|
|
|
4
4
|
module GrapeDocumenter
|
|
5
5
|
class Generator
|
|
6
|
+
attr_reader :mounted_path
|
|
7
|
+
|
|
6
8
|
def initialize(api_class, output_path, options = {})
|
|
7
9
|
raise 'api_class must be specified' if api_class.nil?
|
|
8
10
|
raise 'output_path must be specified' if output_path.nil?
|
|
@@ -10,6 +12,7 @@ module GrapeDocumenter
|
|
|
10
12
|
@output_path = output_path
|
|
11
13
|
@api_class = api_class.constantize
|
|
12
14
|
@format = options[:format] || 'html'
|
|
15
|
+
@mounted_path = options[:mounted_path] || ''
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def generate_namespace_docs
|
|
@@ -79,7 +82,7 @@ module GrapeDocumenter
|
|
|
79
82
|
end
|
|
80
83
|
|
|
81
84
|
def routes_for_version_and_namespace(version, namespace)
|
|
82
|
-
routes_for_version(version).select { |r| normalize_route_namespace(r) == namespace }.map{|r| RouteDoc.new(r)}
|
|
85
|
+
routes_for_version(version).select { |r| normalize_route_namespace(r) == namespace }.map{|r| RouteDoc.new(r, :mounted_path => @mounted_path)}
|
|
83
86
|
end
|
|
84
87
|
|
|
85
88
|
def titleize(string)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module GrapeDocumenter
|
|
2
2
|
class RouteDoc
|
|
3
|
-
def initialize(route)
|
|
3
|
+
def initialize(route, options = {})
|
|
4
4
|
@route = route
|
|
5
|
+
@mounted_path = options[:mounted_path] || ''
|
|
5
6
|
end
|
|
6
7
|
|
|
7
8
|
def http_method
|
|
@@ -9,7 +10,7 @@ module GrapeDocumenter
|
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def path
|
|
12
|
-
@route.route_path
|
|
13
|
+
@mounted_path + @route.route_path.gsub('(.:format)', '')
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def description
|
data/spec/generator_spec.rb
CHANGED
|
@@ -21,11 +21,23 @@ describe GrapeDocumenter::Generator do
|
|
|
21
21
|
let(:routes) { subject.generate_namespace_docs.first.routes }
|
|
22
22
|
|
|
23
23
|
describe 'index' do
|
|
24
|
+
describe 'method' do
|
|
25
|
+
it 'returns get' do
|
|
26
|
+
routes.first.http_method.should == 'GET'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
24
30
|
describe 'description' do
|
|
25
31
|
it 'returns Get all users' do
|
|
26
32
|
routes.first.description.should == 'Get all users'
|
|
27
33
|
end
|
|
28
34
|
end
|
|
35
|
+
|
|
36
|
+
describe 'path' do
|
|
37
|
+
it 'returns /users' do
|
|
38
|
+
routes.first.path.should == '/:version/user'
|
|
39
|
+
end
|
|
40
|
+
end
|
|
29
41
|
end
|
|
30
42
|
|
|
31
43
|
describe 'show' do
|
|
@@ -50,4 +62,14 @@ describe GrapeDocumenter::Generator do
|
|
|
50
62
|
end
|
|
51
63
|
end
|
|
52
64
|
end
|
|
65
|
+
|
|
66
|
+
describe 'options' do
|
|
67
|
+
describe 'prefix' do
|
|
68
|
+
subject { described_class.new 'MyApplication::API', '/tmp/grape_documenter', :mounted_path => '/mounted_path' }
|
|
69
|
+
|
|
70
|
+
it 'sets the prefix' do
|
|
71
|
+
subject.mounted_path.should == '/mounted_path'
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
53
75
|
end
|
data/spec/route_doc_spec.rb
CHANGED
|
@@ -33,4 +33,12 @@ describe GrapeDocumenter::RouteDoc do
|
|
|
33
33
|
subject.optional_params.should == {'foo' => {:type => 'string', :desc => 'fooness'}}
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
context 'with mounted_path' do
|
|
38
|
+
subject { described_class.new(mock_route, :mounted_path => '/foo') }
|
|
39
|
+
|
|
40
|
+
it 'returns the path with mounted path' do
|
|
41
|
+
subject.path.should == '/foo/users'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
36
44
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grape_documenter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2012-08-
|
|
13
|
+
date: 2012-08-23 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: grape
|
|
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
161
161
|
version: '0'
|
|
162
162
|
requirements: []
|
|
163
163
|
rubyforge_project:
|
|
164
|
-
rubygems_version: 1.8.
|
|
164
|
+
rubygems_version: 1.8.24
|
|
165
165
|
signing_key:
|
|
166
166
|
specification_version: 3
|
|
167
167
|
summary: This adds a task to Rails Applications to generate documentation for Grape
|
|
@@ -173,3 +173,4 @@ test_files:
|
|
|
173
173
|
- spec/route_doc_spec.rb
|
|
174
174
|
- spec/spec_helper.rb
|
|
175
175
|
- spec/support/test_api.rb
|
|
176
|
+
has_rdoc:
|