rapidoc 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = Rapidoc
2
2
 
3
- REST API documentation generator for rails projects ( 0.05 version ).
3
+ REST API documentation generator for rails projects ( 0.06 version ).
4
4
 
5
5
  This gem let you generate API documentation of your rails project in html format.
6
6
  It uses routes information, rapidoc comments and json examples for generate
@@ -125,6 +125,10 @@ For more details and options please visit the Wiki[https://github.com/drinor/rap
125
125
 
126
126
  * If there is an error in your documentation, rapidoc show you an error message with the file name that contains the error and block lines.
127
127
 
128
+ * Trace mode ( configuration[https://github.com/drinor/rapidoc/wiki/Configuration] ).
129
+
130
+ * Simple and intuitive navigation.
131
+
128
132
  == Contributing
129
133
 
130
134
  1. Fork it
@@ -21,10 +21,12 @@ module Rapidoc
21
21
  def initialize( routes_info, controller_info, examples_route )
22
22
  @resource = routes_info[:resource].to_s
23
23
  @action = routes_info[:action].to_s
24
- @action_method = routes_info[:method].to_s
24
+ @action_method = routes_info[:method].to_s || '-----'
25
25
  @urls = routes_info[:urls]
26
26
  @file = @resource + '_' + @action
27
27
 
28
+ puts " - Generating #{@action} action documentation..." if trace?
29
+
28
30
  add_controller_info( controller_info ) if controller_info
29
31
  load_examples( examples_route ) if examples_route
30
32
  load_params_errors if default_errors? @action and @params
@@ -37,6 +39,7 @@ module Rapidoc
37
39
  private
38
40
 
39
41
  def add_controller_info( controller_info )
42
+ puts " + Adding info from controller..." if trace?
40
43
  @description = controller_info["description"]
41
44
  @response_formats = default_response_formats || controller_info["response_formats"]
42
45
  @params = controller_info["params"]
@@ -74,12 +77,14 @@ module Rapidoc
74
77
  def load_request( examples_route )
75
78
  file = examples_route + '/' + @resource + '_' + @action + '_request.json'
76
79
  return unless File.exists?( file )
80
+ puts " + Loading request examples..." if trace?
77
81
  File.open( file ){ |f| @example_req = JSON.pretty_generate( JSON.parse(f.read) ) }
78
82
  end
79
83
 
80
84
  def load_response( examples_route )
81
85
  file = examples_route + '/' + @resource + '_' + @action + '_response.json'
82
86
  return unless File.exists?( file )
87
+ puts " + Loading response examples..." if trace?
83
88
  File.open( file ){ |f| @example_res = JSON.pretty_generate( JSON.parse(f.read) ) }
84
89
  end
85
90
  end
@@ -102,6 +102,10 @@ module Rapidoc
102
102
  @@config['response_formats'] if @@config
103
103
  end
104
104
 
105
+ def trace?
106
+ ( @@config and @@config['trace'] == true ) ? true : false
107
+ end
108
+
105
109
  private
106
110
 
107
111
  def target_dir_from_config
@@ -16,6 +16,8 @@ module Rapidoc
16
16
  # @return [RoutesDoc] class with routes info
17
17
  #
18
18
  def get_routes_doc
19
+ puts "Executing 'rake routes'..." if trace?
20
+
19
21
  routes_doc = RoutesDoc.new
20
22
  routes = Dir.chdir( ::Rails.root.to_s ) { `rake routes` }
21
23
 
@@ -35,6 +37,7 @@ module Rapidoc
35
37
  resources_names = routes_doc.get_resources_names - resources_black_list
36
38
 
37
39
  resources_names.map do |resource|
40
+ puts "Generating #{resource} documentation..." if trace?
38
41
  ResourceDoc.new( resource, routes_doc.get_actions_route_info( resource ) )
39
42
  end
40
43
  end
@@ -11,12 +11,21 @@ module Rapidoc
11
11
  end
12
12
 
13
13
  def add_route( route )
14
- if route.split.size == 4
14
+ if route.split.size > 3
15
15
  method, url, controller_action = route.split.slice(1, 3)
16
+ elsif route.split.size == 2
17
+ url, controller_action = route.split
16
18
  else
17
19
  method, url, controller_action = route.split
18
20
  end
19
21
 
22
+ # check when method is not specified
23
+ unless controller_action.include? '#'
24
+ controller_action = url
25
+ url = method
26
+ method = nil
27
+ end
28
+
20
29
  add_resource_route( method, url, controller_action )
21
30
  end
22
31
 
@@ -28,7 +28,7 @@
28
28
  <div class="nav-collapse">
29
29
  <ul class="nav">
30
30
  <li class="active"><a href="index.html">Resources</a></li>
31
- <li><a href="https://github.com/drinor/rapidoc.git">Contact</a></li>
31
+ <li><a target="_blank" href="https://github.com/drinor/rapidoc.git">Contact</a></li>
32
32
  </ul>
33
33
  </div>
34
34
  </div>
@@ -64,7 +64,7 @@
64
64
  </td>
65
65
  <td>
66
66
  {{#if ../this.has_controller_info}}
67
- <a href="actions/{{../../this.resource}}_{{../../this.action}}.html" target="_blank">{{this}}<a>
67
+ <a href="actions/{{../../this.resource}}_{{../../this.action}}.html">{{this}}<a>
68
68
  {{else}}
69
69
  {{this}}
70
70
  {{/if}}
@@ -1,3 +1,3 @@
1
1
  module Rapidoc
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -47,7 +47,7 @@ module Rapidoc
47
47
 
48
48
  begin
49
49
  info << YAML.load( lines[ b[:init] + 1, n_lines ].join.gsub(/\ *#/, '') )
50
- rescue SyntaxError => e
50
+ rescue Exception => e
51
51
  puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]"
52
52
  end
53
53
  end
@@ -1,4 +1,7 @@
1
1
  Dummy::Application.routes.draw do
2
+ match 'testing', :to => 'testing#redirect', :constraints => { :id => /[A-Z]\d{5}/ }
3
+ match '*tests', :controller => 'testing', :action => 'index'
4
+
2
5
  resources :users, :only => [ :index, :show, :create ] do
3
6
  resources :albums, :only => [ :index, :show, :create, :update, :destroy ] do
4
7
  resources :images, :only => [ :index, :show, :create, :update, :destroy ]
@@ -0,0 +1,6 @@
1
+ # =begin action
2
+ http_status:
3
+ - 201
4
+ #params:
5
+ - name: 'name'
6
+ # =end
@@ -23,6 +23,18 @@ describe Rapidoc::Config do
23
23
  gem_templates_dir('template.hbs').should =~ /(.*)\/templates\/template\.hbs/
24
24
  end
25
25
 
26
+ context "when call trace?" do
27
+ it "returns false with default options" do
28
+ trace?.should == false
29
+ end
30
+
31
+ it "returns true when config has trace=true" do
32
+ File.open( config_file_path, 'w') { |file| file.write "trace: true" }
33
+ load_config
34
+ trace?.should == true
35
+ end
36
+ end
37
+
26
38
  context "when call controller_dir" do
27
39
  context "when use default route" do
28
40
  it "controller_dir returns correct dir" do
@@ -4,36 +4,57 @@ include Rapidoc
4
4
 
5
5
  describe Rapidoc do
6
6
 
7
- before :all do
8
- create_structure
9
- load_config
10
- end
11
-
12
- after :all do
13
- remove_doc
14
- end
7
+ context "when all is ok" do
8
+ before :all do
9
+ create_structure
10
+ load_config
11
+ end
15
12
 
16
- context "when create estructure" do
17
- it "should create config files" do
18
- File.exists?( config_dir( "rapidoc.yml" ) ).should == true
13
+ after :all do
14
+ remove_doc
19
15
  end
20
16
 
21
- it "should create target dir" do
22
- File.directory?( target_dir ).should == true
17
+ context "when create estructure" do
18
+ it "should create config files" do
19
+ File.exists?( config_dir( "rapidoc.yml" ) ).should == true
20
+ end
21
+
22
+ it "should create target dir" do
23
+ File.directory?( target_dir ).should == true
24
+ end
25
+
26
+ it "should create example dir" do
27
+ File.directory?( examples_dir ).should == true
28
+ end
23
29
  end
24
30
 
25
- it "should create example dir" do
26
- File.directory?( examples_dir ).should == true
31
+ context "when executing genarate_doc function" do
32
+ before do
33
+ generate_doc
34
+ end
35
+
36
+ it "should create new index.html file" do
37
+ File.exists?( ::Rails.root.to_s + "/rapidoc/index.html" ).should == true
38
+ end
27
39
  end
28
40
  end
29
41
 
30
- context "when executing genarate_doc function" do
31
- before do
42
+ context "when there is an error" do
43
+ before :all do
44
+ create_structure
45
+
46
+ File.open( config_file_path, 'w') { |file| file.write "controllers_route: \"public\"" }
47
+ load_config
48
+
49
+ controller = controller_dir 'users_controller.yml'
50
+ File.open( controller, 'w' ) { |file|
51
+ file.write "# =begin action\nhttp_status:\n - 201\n #params:\n - name: 'name'\n# =end\n"
52
+ }
53
+
32
54
  generate_doc
33
55
  end
34
56
 
35
- it "should create new index.html file" do
36
- File.exists?( ::Rails.root.to_s + "/rapidoc/index.html" ).should == true
57
+ it "should return error" do
37
58
  end
38
59
  end
39
60
  end
@@ -4,6 +4,8 @@ include Rapidoc
4
4
 
5
5
  describe ResourceDoc do
6
6
  before :all do
7
+ reset_structure
8
+ load_config
7
9
  @extractor = ControllerExtractor.new "users_controller.rb"
8
10
  @routes_actions_info = get_routes_doc.get_actions_route_info( :users )
9
11
  end
@@ -69,7 +69,7 @@ describe Rapidoc::ResourcesExtractor do
69
69
 
70
70
  it "return correct order" do
71
71
  names = @resources.map(&:name)
72
- names.should == [ "albums", "images", "users" ]
72
+ names.should == [ "albums", "images", "testing", "users" ]
73
73
  end
74
74
 
75
75
  context "when check resource with controller" do
@@ -105,14 +105,52 @@ describe RoutesDoc do
105
105
  end
106
106
 
107
107
  context "when we call add_route function" do
108
- before do
109
- @route = 'GET /users(.:format) users#index'
108
+ context "when route has 3 normal elements" do
109
+ before do
110
+ @route = 'GET /users(.:format) users#index'
111
+ end
112
+
113
+ it "calls add_resource_route function with correct params" do
114
+ @routes_doc.should_receive( :add_resource_route ).
115
+ with( 'GET', '/users(.:format)', 'users#index' )
116
+ @routes_doc.add_route( @route )
117
+ end
110
118
  end
111
119
 
112
- it "calls add_resource_route function with correct params" do
113
- @routes_doc.should_receive( :add_resource_route ).
114
- with( 'GET', '/users(.:format)', 'users#index' )
115
- @routes_doc.add_route( @route )
120
+ context "when route has 3 elements" do
121
+ before do
122
+ @route = '/users/:id(.:format) users#index {:id=>/[A-Z]\d{5}/}'
123
+ end
124
+
125
+ it "calls add_resource_route function with correct params" do
126
+ @routes_doc.should_receive( :add_resource_route ).
127
+ with( nil, '/users/:id(.:format)', 'users#index' )
128
+ @routes_doc.add_route( @route )
129
+ end
130
+ end
131
+
132
+ context "when route has 4 elements" do
133
+ before do
134
+ @route = 'user /users/:id(.:format) users#index {:id=>/[A-Z]\d{5}/}'
135
+ end
136
+
137
+ it "calls add_resource_route function with correct params" do
138
+ @routes_doc.should_receive( :add_resource_route ).
139
+ with( nil, '/users/:id(.:format)', 'users#index' )
140
+ @routes_doc.add_route( @route )
141
+ end
142
+ end
143
+
144
+ context "when route has 2 elements" do
145
+ before do
146
+ @route = '/users/:id(.:format) users#index'
147
+ end
148
+
149
+ it "calls add_resource_route function with correct params" do
150
+ @routes_doc.should_receive( :add_resource_route ).
151
+ with( nil, '/users/:id(.:format)', 'users#index' )
152
+ @routes_doc.add_route( @route )
153
+ end
116
154
  end
117
155
  end
118
156
 
@@ -4,12 +4,13 @@ include Rapidoc
4
4
 
5
5
  describe TemplatesGenerator do
6
6
 
7
- before :all do
8
- create_structure
7
+ before do
8
+ reset_structure
9
+ load_config
9
10
  end
10
11
 
11
- after :all do
12
- remove_doc
12
+ after do
13
+ #remove_doc
13
14
  end
14
15
 
15
16
  context "when call generate_index_template" do
@@ -35,8 +36,10 @@ describe TemplatesGenerator do
35
36
  it "should create new action.html file for each action"do
36
37
  @resources.each do |resource|
37
38
  resource.actions_doc.each do |action_doc|
38
- route = actions_dir + "/#{resource.name}_#{action_doc.action}.html"
39
- File.exists?( route ).should == true
39
+ if action_doc.has_controller_info
40
+ route = actions_dir + "/#{resource.name}_#{action_doc.action}.html"
41
+ File.exists?( route ).should == true
42
+ end
40
43
  end
41
44
  end
42
45
  end
@@ -50,7 +50,7 @@ describe Rapidoc::YamlParser do
50
50
  end
51
51
  end
52
52
 
53
- context "when there is an error in the block" do
53
+ context "when there is an error in a description" do
54
54
  before :all do
55
55
  @blocks2 = [ { init: 0, end: 2 } ]
56
56
  @lines2 = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapidoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -183,6 +183,7 @@ files:
183
183
  - spec/dummy/public/favicon.ico
184
184
  - spec/dummy/public/index.html
185
185
  - spec/dummy/public/robots.txt
186
+ - spec/dummy/public/users_controller.yml
186
187
  - spec/dummy/salida/users_create_response.json
187
188
  - spec/dummy/script/rails
188
189
  - spec/dummy/test/fixtures/.gitkeep
@@ -221,12 +222,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
222
  - - ! '>='
222
223
  - !ruby/object:Gem::Version
223
224
  version: '0'
225
+ segments:
226
+ - 0
227
+ hash: -3398396139760812886
224
228
  required_rubygems_version: !ruby/object:Gem::Requirement
225
229
  none: false
226
230
  requirements:
227
231
  - - ! '>='
228
232
  - !ruby/object:Gem::Version
229
233
  version: '0'
234
+ segments:
235
+ - 0
236
+ hash: -3398396139760812886
230
237
  requirements: []
231
238
  rubyforge_project:
232
239
  rubygems_version: 1.8.25
@@ -273,6 +280,7 @@ test_files:
273
280
  - spec/dummy/public/favicon.ico
274
281
  - spec/dummy/public/index.html
275
282
  - spec/dummy/public/robots.txt
283
+ - spec/dummy/public/users_controller.yml
276
284
  - spec/dummy/salida/users_create_response.json
277
285
  - spec/dummy/script/rails
278
286
  - spec/dummy/test/fixtures/.gitkeep