rapidoc 0.0.4
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/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +152 -0
- data/Rakefile +1 -0
- data/lib/rapidoc.rb +62 -0
- data/lib/rapidoc/action_doc.rb +86 -0
- data/lib/rapidoc/config.rb +127 -0
- data/lib/rapidoc/config/rapidoc.yml +4 -0
- data/lib/rapidoc/controller_extractor.rb +54 -0
- data/lib/rapidoc/http_response.rb +61 -0
- data/lib/rapidoc/param_errors.rb +43 -0
- data/lib/rapidoc/resource_doc.rb +66 -0
- data/lib/rapidoc/resources_extractor.rb +42 -0
- data/lib/rapidoc/routes_doc.rb +96 -0
- data/lib/rapidoc/templates/action.html.hbs +170 -0
- data/lib/rapidoc/templates/assets/css/bootstrap-responsive.min.css +9 -0
- data/lib/rapidoc/templates/assets/css/bootstrap.min.css +9 -0
- data/lib/rapidoc/templates/assets/css/rapidoc.css +43 -0
- data/lib/rapidoc/templates/assets/img/glyphicons-halflings.png +0 -0
- data/lib/rapidoc/templates/assets/js/bootstrap.min.js +6 -0
- data/lib/rapidoc/templates/assets/js/jquery-1.9.0.min.js +4 -0
- data/lib/rapidoc/templates/assets/js/json2.js +486 -0
- data/lib/rapidoc/templates/index.html.hbs +85 -0
- data/lib/rapidoc/templates_generator.rb +65 -0
- data/lib/rapidoc/version.rb +3 -0
- data/lib/rapidoc/yaml_parser.rb +49 -0
- data/lib/tasks/railtie.rb +7 -0
- data/lib/tasks/rapidoc.rake +18 -0
- data/rapidoc.gemspec +26 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/Gemfile +42 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/users_controller.rb +114 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +241 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/salida/users_create_response.json +12 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/fixtures/.gitkeep +0 -0
- data/spec/dummy/test/functional/.gitkeep +0 -0
- data/spec/dummy/test/integration/.gitkeep +0 -0
- data/spec/dummy/test/performance/browsing_test.rb +12 -0
- data/spec/dummy/test/test_helper.rb +13 -0
- data/spec/dummy/test/unit/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/features/action_spec.rb +212 -0
- data/spec/features/index_spec.rb +64 -0
- data/spec/lib/action_doc_spec.rb +202 -0
- data/spec/lib/config_spec.rb +186 -0
- data/spec/lib/controller_extractor_spec.rb +77 -0
- data/spec/lib/http_response_spec.rb +63 -0
- data/spec/lib/param_errors_spec.rb +69 -0
- data/spec/lib/rake_spec.rb +25 -0
- data/spec/lib/rapidoc_spec.rb +39 -0
- data/spec/lib/resource_doc_spec.rb +131 -0
- data/spec/lib/resources_extractor_spec.rb +105 -0
- data/spec/lib/routes_doc_spec.rb +150 -0
- data/spec/lib/templates_generator_spec.rb +90 -0
- data/spec/lib/yard_parser_spec.rb +55 -0
- data/spec/spec_helper.rb +10 -0
- metadata +307 -0
data/.gitignore
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
*.swp
|
|
2
|
+
*.gem
|
|
3
|
+
*.rbc
|
|
4
|
+
.bundle
|
|
5
|
+
.config
|
|
6
|
+
.yardoc
|
|
7
|
+
.rvmrc
|
|
8
|
+
Gemfile.lock
|
|
9
|
+
InstalledFiles
|
|
10
|
+
_yardoc
|
|
11
|
+
coverage
|
|
12
|
+
doc/
|
|
13
|
+
lib/bundler/man
|
|
14
|
+
pkg
|
|
15
|
+
rdoc
|
|
16
|
+
spec/reports
|
|
17
|
+
test/tmp
|
|
18
|
+
test/version_tmp
|
|
19
|
+
tmp
|
|
20
|
+
spec/dummy/rapidoc
|
|
21
|
+
spec/dummy/config/rapidoc
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
= Rapidoc
|
|
2
|
+
|
|
3
|
+
REST API documentation generator for rails projects ( 0.04 version ).
|
|
4
|
+
|
|
5
|
+
This gem let you generate API documentation of your rails project in html format.
|
|
6
|
+
It use routes information, _rapidoc_ _comments_ and json examples for generate
|
|
7
|
+
static html files.
|
|
8
|
+
|
|
9
|
+
This is how the web interface look like:
|
|
10
|
+
|
|
11
|
+
* Resources: example[http://www.v2imagen.com/RDv]
|
|
12
|
+
* Action-home: example[http://es.zimagez.com/zimage/capturadepantalla-170213-195254.php]
|
|
13
|
+
|
|
14
|
+
Rapidoc is based in restapi_doc gem: https://github.com/Alayho/restapi_doc
|
|
15
|
+
|
|
16
|
+
== Installation
|
|
17
|
+
|
|
18
|
+
Add this line to your application's Gemfile:
|
|
19
|
+
|
|
20
|
+
gem 'rapidoc', :git => 'https://github.com/drinor/rapidoc.git'
|
|
21
|
+
|
|
22
|
+
And then execute:
|
|
23
|
+
|
|
24
|
+
$ bundle
|
|
25
|
+
|
|
26
|
+
== Usage
|
|
27
|
+
|
|
28
|
+
For generate documentation run:
|
|
29
|
+
|
|
30
|
+
rake rapidoc:generate
|
|
31
|
+
|
|
32
|
+
For clean all generate files run:
|
|
33
|
+
|
|
34
|
+
rake rapidoc:clean
|
|
35
|
+
|
|
36
|
+
== Configuration
|
|
37
|
+
|
|
38
|
+
You can configure rapidoc in ``/config/rapidoc/rapidoc.yml`` file:
|
|
39
|
+
|
|
40
|
+
project_name: "Project Name"
|
|
41
|
+
company: "My company"
|
|
42
|
+
year: 2013
|
|
43
|
+
doc_route: "doc"
|
|
44
|
+
examples_route: "examples"
|
|
45
|
+
|
|
46
|
+
The first three parameters are used for show information about project.
|
|
47
|
+
|
|
48
|
+
The *doc_route* parameter let you specify where _rapidoc_ will generate all the
|
|
49
|
+
documentation:
|
|
50
|
+
|
|
51
|
+
path_project/name
|
|
52
|
+
|
|
53
|
+
The *examples_route* parameter let you specify where _rapidoc_ will search for
|
|
54
|
+
requests/responeses examples files:
|
|
55
|
+
|
|
56
|
+
path_project/name
|
|
57
|
+
|
|
58
|
+
For more details please visit the Wiki[https://github.com/drinor/rapidoc/wiki].
|
|
59
|
+
|
|
60
|
+
== Introducction
|
|
61
|
+
|
|
62
|
+
If you generate documentation without do anithing, you can get all resources list in a _index.html_ file.
|
|
63
|
+
|
|
64
|
+
For get resources documentation you need add a resource block to resource controller:
|
|
65
|
+
|
|
66
|
+
# =begin resource
|
|
67
|
+
# =end
|
|
68
|
+
|
|
69
|
+
For get action documentation you need add an action block to resource controller:
|
|
70
|
+
|
|
71
|
+
# =begin action
|
|
72
|
+
# =end
|
|
73
|
+
|
|
74
|
+
Documentation blocks use *yaml* format.
|
|
75
|
+
|
|
76
|
+
== Requests/Responses examples
|
|
77
|
+
|
|
78
|
+
Rapidoc let you define *json* files with requests/responses examples. You only need to add
|
|
79
|
+
your files to *examples_route* and _rapidoc_ load it automatically in an action tab.
|
|
80
|
+
|
|
81
|
+
Files should have the next name format:
|
|
82
|
+
|
|
83
|
+
<resource>_<action>_<type>.json
|
|
84
|
+
|
|
85
|
+
Parameters:
|
|
86
|
+
|
|
87
|
+
* *resource*: name of resource (plural)
|
|
88
|
+
* *action*: controller action (index, create, show...)
|
|
89
|
+
* *type*: request / response
|
|
90
|
+
|
|
91
|
+
Name example:
|
|
92
|
+
|
|
93
|
+
users_create_request.json
|
|
94
|
+
|
|
95
|
+
File example:
|
|
96
|
+
|
|
97
|
+
{
|
|
98
|
+
"usuario": {
|
|
99
|
+
"name": "Paul",
|
|
100
|
+
"age": 23,
|
|
101
|
+
"height": 1.7,
|
|
102
|
+
"favoriteBands": ["Band ABC", "Band XYZ"]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
== Documentation examples
|
|
107
|
+
|
|
108
|
+
Resource documentation:
|
|
109
|
+
|
|
110
|
+
# users_controller.rb
|
|
111
|
+
|
|
112
|
+
# =begin resource
|
|
113
|
+
# description: Represents an user in the system.
|
|
114
|
+
# =end
|
|
115
|
+
|
|
116
|
+
Action documentation:
|
|
117
|
+
|
|
118
|
+
# =begin action
|
|
119
|
+
# method: GET
|
|
120
|
+
# action: index
|
|
121
|
+
# requires_authentication: no
|
|
122
|
+
# response_formats: json
|
|
123
|
+
# description: Return all users of the system.
|
|
124
|
+
#
|
|
125
|
+
# http_responses:
|
|
126
|
+
# - 200
|
|
127
|
+
# - 401
|
|
128
|
+
# - 403
|
|
129
|
+
#
|
|
130
|
+
# params:
|
|
131
|
+
# - name: page
|
|
132
|
+
# description: number of page in pagination
|
|
133
|
+
# required: false
|
|
134
|
+
# type: Integer
|
|
135
|
+
#
|
|
136
|
+
# - name: limit
|
|
137
|
+
# description: number of elements by page in pagination
|
|
138
|
+
#
|
|
139
|
+
# - name: name
|
|
140
|
+
# description: name filter
|
|
141
|
+
# =end
|
|
142
|
+
def index
|
|
143
|
+
...
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
== Contributing
|
|
147
|
+
|
|
148
|
+
1. Fork it
|
|
149
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
150
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
151
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
152
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rapidoc.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'handlebars'
|
|
2
|
+
require "rapidoc/config"
|
|
3
|
+
require "rapidoc/version"
|
|
4
|
+
require "tasks/railtie.rb"
|
|
5
|
+
require "rapidoc/routes_doc"
|
|
6
|
+
require "rapidoc/resource_doc"
|
|
7
|
+
require "rapidoc/action_doc"
|
|
8
|
+
require "rapidoc/controller_extractor"
|
|
9
|
+
require "rapidoc/resources_extractor"
|
|
10
|
+
require "rapidoc/param_errors"
|
|
11
|
+
require "rapidoc/templates_generator"
|
|
12
|
+
require "rapidoc/yaml_parser"
|
|
13
|
+
|
|
14
|
+
module Rapidoc
|
|
15
|
+
|
|
16
|
+
include Config
|
|
17
|
+
include ResourcesExtractor
|
|
18
|
+
include TemplatesGenerator
|
|
19
|
+
include ParamErrors
|
|
20
|
+
include YamlParser
|
|
21
|
+
|
|
22
|
+
METHODS = [ "GET", "PUT", "DELETE", "POST" ]
|
|
23
|
+
|
|
24
|
+
def create_structure
|
|
25
|
+
# should be done in this order
|
|
26
|
+
FileUtils.mkdir target_dir unless File.directory? target_dir
|
|
27
|
+
FileUtils.mkdir actions_dir unless File.directory? actions_dir
|
|
28
|
+
FileUtils.cp_r GEM_CONFIG_DIR + "/.", config_dir unless File.directory? config_dir
|
|
29
|
+
FileUtils.cp_r GEM_ASSETS_DIR, target_dir
|
|
30
|
+
FileUtils.mkdir examples_dir unless File.directory? examples_dir
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def remove_structure
|
|
34
|
+
remove_doc
|
|
35
|
+
remove_config
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def remove_config
|
|
39
|
+
FileUtils.rm_r config_dir if File.directory? config_dir
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def remove_doc
|
|
43
|
+
FileUtils.rm_r target_dir if File.directory? target_dir
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def reset_structure
|
|
47
|
+
remove_structure
|
|
48
|
+
create_structure
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def remove_examples
|
|
52
|
+
FileUtils.rm_r examples_dir if File.directory? examples_dir
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def generate_doc
|
|
56
|
+
resources_doc = get_resources
|
|
57
|
+
|
|
58
|
+
generate_index_template( resources_doc )
|
|
59
|
+
generate_actions_templates( resources_doc )
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'rapidoc/http_response'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module Rapidoc
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# This class save information about action of resource.
|
|
10
|
+
#
|
|
11
|
+
class ActionDoc
|
|
12
|
+
attr_reader :resource, :urls, :action, :action_method, :description,
|
|
13
|
+
:response_formats, :authentication, :params, :file, :http_responses,
|
|
14
|
+
:errors, :example_res, :example_req
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# @param resource [String] resource name
|
|
18
|
+
# @param action_info [Hash] action info extracted from controller file
|
|
19
|
+
# @param urls [Array] all urls that call this method
|
|
20
|
+
#
|
|
21
|
+
def initialize( routes_info, controller_info, examples_route )
|
|
22
|
+
@resource = routes_info[:resource].to_s
|
|
23
|
+
@action = routes_info[:action].to_s
|
|
24
|
+
@action_method = routes_info[:method].to_s
|
|
25
|
+
@urls = routes_info[:urls]
|
|
26
|
+
@file = @resource + '_' + @action
|
|
27
|
+
|
|
28
|
+
add_controller_info( controller_info ) if controller_info
|
|
29
|
+
load_examples( examples_route ) if examples_route
|
|
30
|
+
load_params_errors if default_errors? @action and @params
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def has_controller_info
|
|
34
|
+
@controller_info ? true : false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def add_controller_info( controller_info )
|
|
40
|
+
@description = controller_info["description"]
|
|
41
|
+
@response_formats = default_response_formats || controller_info["response_formats"]
|
|
42
|
+
@params = controller_info["params"]
|
|
43
|
+
@http_responses = get_http_responses controller_info["http_responses"]
|
|
44
|
+
@errors = controller_info["errors"] ? controller_info["errors"].dup : []
|
|
45
|
+
@authentication = get_authentication controller_info["authentication_required"]
|
|
46
|
+
@controller_info = true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def get_authentication( required_authentication )
|
|
50
|
+
if [ true, false ].include? required_authentication
|
|
51
|
+
required_authentication
|
|
52
|
+
else
|
|
53
|
+
default_authentication
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def get_http_responses codes
|
|
58
|
+
codes.map{ |c| HttpResponse.new c } if codes
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def load_examples( examples_route )
|
|
62
|
+
return unless File.directory? examples_route + "/"
|
|
63
|
+
load_request examples_route
|
|
64
|
+
load_response examples_route
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def load_params_errors
|
|
68
|
+
@params.each do |param|
|
|
69
|
+
@errors << get_error_info( param["name"], "required" ) if param["required"]
|
|
70
|
+
@errors << get_error_info( param["name"], "inclusion" ) if param["inclusion"]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def load_request( examples_route )
|
|
75
|
+
file = examples_route + '/' + @resource + '_' + @action + '_request.json'
|
|
76
|
+
return unless File.exists?( file )
|
|
77
|
+
File.open( file ){ |f| @example_req = JSON.pretty_generate( JSON.parse(f.read) ) }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def load_response( examples_route )
|
|
81
|
+
file = examples_route + '/' + @resource + '_' + @action + '_response.json'
|
|
82
|
+
return unless File.exists?( file )
|
|
83
|
+
File.open( file ){ |f| @example_res = JSON.pretty_generate( JSON.parse(f.read) ) }
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Rapidoc
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# This module has all config information about directories and config files.
|
|
7
|
+
#
|
|
8
|
+
module Config
|
|
9
|
+
GEM_CONFIG_DIR = File.join( File.dirname(__FILE__), 'config' )
|
|
10
|
+
GEM_ASSETS_DIR = File.join( File.dirname(__FILE__), 'templates/assets' )
|
|
11
|
+
GEM_EXAMPLES_DIR = File.join( File.dirname(__FILE__), 'config/examples')
|
|
12
|
+
|
|
13
|
+
@@config = nil
|
|
14
|
+
|
|
15
|
+
def gem_templates_dir( f = nil )
|
|
16
|
+
gem_templates_dir ||= File.join( File.dirname(__FILE__), 'templates' )
|
|
17
|
+
form_file_name gem_templates_dir, f
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def config_dir( f = nil )
|
|
21
|
+
config_dir ||= File.join( ::Rails.root.to_s, 'config/rapidoc' )
|
|
22
|
+
form_file_name config_dir, f
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def controller_dir(f = nil)
|
|
26
|
+
if @@config and @@config['controllers_route']
|
|
27
|
+
controller_dir = File.join( ::Rails.root.to_s, @@config['controllers_route'] )
|
|
28
|
+
else
|
|
29
|
+
controller_dir ||= File.join( ::Rails.root.to_s, 'app/controllers' )
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
form_file_name controller_dir, f
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def config_file_path
|
|
36
|
+
config_dir 'rapidoc.yml'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def rapidoc_config
|
|
40
|
+
@@config
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def load_config
|
|
44
|
+
if File.exists?( config_file_path )
|
|
45
|
+
@@config = YAML.load( File.read( config_file_path ) )
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def resources_black_list
|
|
50
|
+
if @@config and @@config['resources_black_list']
|
|
51
|
+
@@config['resources_black_list'].gsub(' ', '').split(',').map(&:to_sym)
|
|
52
|
+
else
|
|
53
|
+
return []
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def default_errors?( action )
|
|
58
|
+
@@config and @@config['default_errors'] == true and
|
|
59
|
+
[ 'create', 'update' ].include? action
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def default_authentication
|
|
63
|
+
if @@config and [ true, false ].include? @@config['default_authentication']
|
|
64
|
+
@@config['default_authentication']
|
|
65
|
+
else
|
|
66
|
+
true
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def default_errors
|
|
71
|
+
@@config and @@config['errors'] ? @@config['errors'] : nil
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# return the directory where rapidoc generates the doc
|
|
75
|
+
def target_dir( f = nil )
|
|
76
|
+
if File.exists?( config_file_path )
|
|
77
|
+
form_file_name( target_dir_from_config, f )
|
|
78
|
+
else
|
|
79
|
+
form_file_name( File.join( ::Rails.root.to_s, 'rapidoc' ), f )
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# returns the directory where rapidoc generates actions (html files)
|
|
84
|
+
def actions_dir( f = nil )
|
|
85
|
+
f ? target_dir( "actions/#{f}" ) : target_dir( "actions" )
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# returns the directory where rapidoc searches for examples
|
|
89
|
+
def examples_dir( f = nil )
|
|
90
|
+
if File.exists?( config_file_path )
|
|
91
|
+
form_file_name( examples_dir_from_config_file, f )
|
|
92
|
+
else
|
|
93
|
+
form_file_name( config_dir( '/examples' ), f )
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def default_response_formats
|
|
98
|
+
@@config['response_formats'] if @@config
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
def target_dir_from_config
|
|
104
|
+
if @@config and @@config.has_key?( "doc_route" )
|
|
105
|
+
File.join(::Rails.root.to_s, @@config['doc_route'] )
|
|
106
|
+
else
|
|
107
|
+
File.join(::Rails.root.to_s, 'rapidoc' )
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def examples_dir_from_config_file
|
|
112
|
+
if @@config and @@config.has_key?("examples_route")
|
|
113
|
+
File.join( ::Rails.root.to_s, @@config["examples_route"] )
|
|
114
|
+
else
|
|
115
|
+
config_dir '/examples'
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def form_file_name(dir, file)
|
|
120
|
+
case file
|
|
121
|
+
when NilClass then dir
|
|
122
|
+
when String then File.join(dir, file)
|
|
123
|
+
else raise ArgumentError, "Invalid argument #{file}"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|