rapidoc 0.0.4 → 0.0.5

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.
@@ -1,23 +1,21 @@
1
1
  = Rapidoc
2
2
 
3
- REST API documentation generator for rails projects ( 0.04 version ).
3
+ REST API documentation generator for rails projects ( 0.05 version ).
4
4
 
5
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.
6
+ It uses routes information, rapidoc comments and json examples for generate
7
+ static html files. Documentation templates are generated using _handlebars_ and
8
+ _bootstrap_.
8
9
 
9
- This is how the web interface look like:
10
+ This is how the web interface look like: example[http://drinor.github.io/rapidoc/index.html]
10
11
 
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
12
+ Rapidoc is based in restapi_doc[https://github.com/Alayho/restapi_doc] gem.
15
13
 
16
14
  == Installation
17
15
 
18
16
  Add this line to your application's Gemfile:
19
17
 
20
- gem 'rapidoc', :git => 'https://github.com/drinor/rapidoc.git'
18
+ gem 'rapidoc'
21
19
 
22
20
  And then execute:
23
21
 
@@ -33,30 +31,6 @@ For clean all generate files run:
33
31
 
34
32
  rake rapidoc:clean
35
33
 
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
34
  == Introducction
61
35
 
62
36
  If you generate documentation without do anithing, you can get all resources list in a _index.html_ file.
@@ -73,37 +47,7 @@ For get action documentation you need add an action block to resource controller
73
47
 
74
48
  Documentation blocks use *yaml* format.
75
49
 
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
50
+ == Documentation example
107
51
 
108
52
  Resource documentation:
109
53
 
@@ -143,6 +87,44 @@ Action documentation:
143
87
  ...
144
88
  end
145
89
 
90
+ == Configuration
91
+
92
+ You can configure rapidoc in ``/config/rapidoc/rapidoc.yml`` file:
93
+
94
+ project_name: "Project Name"
95
+ company: "My company"
96
+ year: 2013
97
+ doc_route: "doc"
98
+ examples_route: "examples"
99
+
100
+ The first three parameters are used for show information about project in the documentation.
101
+
102
+ The *doc_route* parameter let you specify where _rapidoc_ will generate the
103
+ documentation:
104
+
105
+ path_project/doc
106
+
107
+ The *examples_route* parameter let you specify where _rapidoc_ will search for
108
+ requests/responeses examples files:
109
+
110
+ path_project/examples
111
+
112
+ For more details and options please visit the Wiki[https://github.com/drinor/rapidoc/wiki].
113
+
114
+ == Other Options
115
+
116
+ * You can use .yml files for write documentation blocks ( configuration[https://github.com/drinor/rapidoc/wiki/Configuration] ).
117
+
118
+ * Rapidoc let you define *json* files with requests/responses examples ( examples[https://github.com/drinor/rapidoc/wiki/Request---Response-Examples] )
119
+
120
+ * Rapidoc let you use default errors ( errors[https://github.com/drinor/rapidoc/wiki/Params-Errors] )
121
+
122
+ * Rapidoc has a lot of parameters for document actions of resource ( actions[https://github.com/drinor/rapidoc/wiki/Action-Documentation] )
123
+
124
+ * When you are in an action page, you can click the resource name and go back to the resources page with resource selected.
125
+
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
+
146
128
  == Contributing
147
129
 
148
130
  1. Fork it
@@ -32,6 +32,10 @@ module Rapidoc
32
32
  form_file_name controller_dir, f
33
33
  end
34
34
 
35
+ def controllers_extension
36
+ ( @@config and @@config['controllers_route'] ) ? '.yml' : '.rb'
37
+ end
38
+
35
39
  def config_file_path
36
40
  config_dir 'rapidoc.yml'
37
41
  end
@@ -17,8 +17,8 @@ module Rapidoc
17
17
  lines = IO.readlines( controller_dir( controller_file ) )
18
18
  blocks = extract_blocks( lines )
19
19
 
20
- @resource_info = YamlParser.extract_resource_info( lines, blocks )
21
- @actions_info = YamlParser.extract_actions_info( lines, blocks )
20
+ @resource_info = YamlParser.extract_resource_info( lines, blocks, controller_file )
21
+ @actions_info = YamlParser.extract_actions_info( lines, blocks, controller_file )
22
22
  end
23
23
 
24
24
  def get_actions_info
@@ -16,7 +16,7 @@ module Rapidoc
16
16
  #
17
17
  def initialize( resource_name, routes_actions_info )
18
18
  @name = resource_name.to_s
19
- @controller_file = name.to_s.pluralize + '_controller.rb'
19
+ @controller_file = name.to_s.pluralize + '_controller' + controllers_extension
20
20
 
21
21
  generate_info routes_actions_info
22
22
  end
@@ -38,6 +38,9 @@ module Rapidoc
38
38
  extractor = get_controller_extractor
39
39
  @description = extractor.get_resource_info['description'] if extractor
40
40
  @actions_doc = get_actions_doc( routes_info, extractor )
41
+
42
+ # template need that description will be an array
43
+ @description = [ @description ] unless @description.class == Array
41
44
  end
42
45
  end
43
46
 
@@ -39,7 +39,7 @@
39
39
 
40
40
  <div class="container">
41
41
  <div class="page-header">
42
- <h1>{{action.resource}}</h1>
42
+ <h1><a href="../index.html?collapse=collapse{{action.resource}}">{{action.resource}}</a></h1>
43
43
  </div>
44
44
 
45
45
  <ul class="nav nav-tabs" id="myTab">
@@ -27,8 +27,8 @@
27
27
  <a class="brand" href="#">{{info.project_name}}</a>
28
28
  <div class="nav-collapse">
29
29
  <ul class="nav">
30
- <li class="active"><a href="#">Resources</a></li>
31
- <li><a target="_blank" href="https://github.com/drinor/rapidoc.git">Contact</a></li>
30
+ <li class="active"><a href="index.html">Resources</a></li>
31
+ <li><a href="https://github.com/drinor/rapidoc.git">Contact</a></li>
32
32
  </ul>
33
33
  </div>
34
34
  </div>
@@ -51,7 +51,9 @@
51
51
  <div id="collapse{{this.simple_name}}" class="accordion-body collapse">
52
52
  <div class="accordion-inner">
53
53
  <div class="pad-description">
54
- {{this.description}}
54
+ {{#each this.description}}
55
+ <p>{{this}}</p>
56
+ {{/each}}
55
57
  </div>
56
58
  <table class="table table-hover">
57
59
  {{#each this.actions_doc}}
@@ -80,6 +82,14 @@
80
82
  <footer>
81
83
  <p>{{info.company}} {{info.year}}</p>
82
84
  </footer>
85
+
86
+ <script>
87
+ window.onload = function () {
88
+ var collapse = '#' + decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] );
89
+ console.log(collapse)
90
+ $(collapse).collapse('show')
91
+ }
92
+ </script>
83
93
  </div>
84
94
  </body>
85
95
  </html>
@@ -1,3 +1,3 @@
1
1
  module Rapidoc
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -12,13 +12,18 @@ module Rapidoc
12
12
  # @param blocks [Hash] lines of blocks, example: { init: 1, end: 4 }
13
13
  # @return [Hash] resource info
14
14
  #
15
- def extract_resource_info( lines, blocks )
15
+ def extract_resource_info( lines, blocks, file_name )
16
16
  blocks ? info = [] : blocks = []
17
17
 
18
18
  blocks.each.map do |b|
19
19
  if lines[ b[:init] ].include? "=begin resource"
20
20
  n_lines = b[:end] - b[:init] - 1
21
- info.push YAML.load( lines[ b[:init] +1, n_lines ].join.gsub(/\ *#/, '') )
21
+
22
+ begin
23
+ info.push YAML.load( lines[ b[:init] +1, n_lines ].join.gsub(/\ *#/, '') )
24
+ rescue SyntaxError => e
25
+ puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]"
26
+ end
22
27
  end
23
28
  end
24
29
 
@@ -32,14 +37,19 @@ module Rapidoc
32
37
  # @param blocks [Hash] lines of blocks, example: { init: 1, end: 4 }
33
38
  # @return [Array] all actions info
34
39
  #
35
- def extract_actions_info( lines, blocks )
40
+ def extract_actions_info( lines, blocks, file_name )
36
41
  info = []
37
42
  blocks = [] unless blocks
38
43
 
39
- blocks.each do |block|
40
- if lines[ block[:init] ].include? "=begin action"
41
- n_lines = block[:end] - block[:init] - 1
42
- info << YAML.load( lines[ block[:init] + 1, n_lines ].join.gsub(/\ *#/, '') )
44
+ blocks.each do |b|
45
+ if lines[ b[:init] ].include? "=begin action"
46
+ n_lines = b[:end] - b[:init] - 1
47
+
48
+ begin
49
+ info << YAML.load( lines[ b[:init] + 1, n_lines ].join.gsub(/\ *#/, '') )
50
+ rescue SyntaxError => e
51
+ puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]"
52
+ end
43
53
  end
44
54
  end
45
55
 
@@ -57,7 +57,9 @@ describe "Index page" do
57
57
 
58
58
  it "contains the correct description" do
59
59
  @resources.each do |resource|
60
- page.should have_text(resource.description)
60
+ resource.description.each do |paragraph|
61
+ page.should have_text( paragraph )
62
+ end
61
63
  end
62
64
  end
63
65
  end
@@ -73,5 +73,26 @@ describe ControllerExtractor do
73
73
  lambda{ ControllerExtractor.new( "no_file" ) }.should raise_error
74
74
  end
75
75
  end
76
+
77
+ context "when check controllers_name" do
78
+ context "when use default controllers route" do
79
+ it "use .rb extension for controllers files" do
80
+ ResourceDoc.any_instance.stub( :generate_info ).and_return( true )
81
+ resource_doc = ResourceDoc.new( 'user', nil )
82
+ resource_doc.controller_file.should == "users_controller.rb"
83
+ end
84
+ end
85
+
86
+ context "when use custom controllers route" do
87
+ it "use .yml extension for controllers files" do
88
+ File.open( config_file_path, 'w') { |file| file.write "controllers_route: \"vim\"" }
89
+ load_config
90
+
91
+ ResourceDoc.any_instance.stub( :generate_info ).and_return( true )
92
+ resource_doc = ResourceDoc.new( 'user', nil )
93
+ resource_doc.controller_file.should == "users_controller.yml"
94
+ end
95
+ end
96
+ end
76
97
  end
77
98
 
@@ -1,6 +1,17 @@
1
1
  require 'spec_helper'
2
2
  require 'rake'
3
3
 
4
+ def capture_stdout(&block)
5
+ original_stdout = $stdout
6
+ $stdout = fake = StringIO.new
7
+ begin
8
+ yield
9
+ ensure
10
+ $stdout = original_stdout
11
+ end
12
+ fake.string
13
+ end
14
+
4
15
  describe Rake do
5
16
  context 'rapidoc:generate' do
6
17
  before do
@@ -18,7 +29,10 @@ describe Rake do
18
29
  end
19
30
 
20
31
  it "should create documentation" do
21
- run_rake_task
32
+ output = capture_stdout { run_rake_task }
33
+ output.should be_include( 'Generating API documentation...' )
34
+ output.should be_include( 'Completed API documentation generation' )
35
+
22
36
  File.exists?( ::Rails.root.to_s + "/rapidoc/index.html" ).should == true
23
37
  end
24
38
  end
@@ -109,23 +109,42 @@ describe ResourceDoc do
109
109
  end
110
110
 
111
111
  context "when create new valid instance" do
112
- before :all do
113
- @resource_name = "users"
114
- @rdoc = ResourceDoc.new @resource_name, @routes_actions_info
115
- end
112
+ context "when use normal sintax" do
113
+ before :all do
114
+ @resource_name = "users"
115
+ @rdoc = ResourceDoc.new @resource_name, @routes_actions_info
116
+ end
116
117
 
117
- it "saves it correctly" do
118
- @rdoc.name.should == @resource_name
119
- @rdoc.controller_file.should == @resource_name + '_controller.rb'
120
- end
118
+ it "saves it correctly" do
119
+ @rdoc.name.should == @resource_name
120
+ @rdoc.controller_file.should == @resource_name + '_controller.rb'
121
+ end
121
122
 
122
- it "set correct description" do
123
- @rdoc.description.should == @extractor.get_resource_info['description']
123
+ it "set correct description" do
124
+ @rdoc.description.should == [ @extractor.get_resource_info['description'] ]
125
+ end
126
+
127
+ it "set correct actions_doc" do
128
+ @rdoc.actions_doc.class.should == Array
129
+ @rdoc.actions_doc.each{ |ad| ad.class.should == ActionDoc }
130
+ end
124
131
  end
125
132
 
126
- it "set correct actions_doc" do
127
- @rdoc.actions_doc.class.should == Array
128
- @rdoc.actions_doc.each{ |ad| ad.class.should == ActionDoc }
133
+ context "when description is an array" do
134
+ before :all do
135
+ @file_name = controller_dir 'resources_controller.rb'
136
+ content = "# =begin resource\n# description:\n# - Info1\n# - Info2\n# =end\n"
137
+ File.open( @file_name, 'w') { |file| file.write content }
138
+ @rdoc = ResourceDoc.new "resource", []
139
+ end
140
+
141
+ after :all do
142
+ File.delete( @file_name )
143
+ end
144
+
145
+ it "set correct description" do
146
+ @rdoc.description.should == [ 'Info1', 'Info2' ]
147
+ end
129
148
  end
130
149
  end
131
150
  end
@@ -0,0 +1,102 @@
1
+ require "spec_helper"
2
+
3
+ include Rapidoc
4
+
5
+ def capture_stdout(&block)
6
+ original_stdout = $stdout
7
+ $stdout = fake = StringIO.new
8
+ begin
9
+ yield
10
+ ensure
11
+ $stdout = original_stdout
12
+ end
13
+ fake.string
14
+ end
15
+
16
+ describe Rapidoc::YamlParser do
17
+
18
+ before :all do
19
+ @description = "resource description"
20
+ @action1 = "index"
21
+ @action2 = "create"
22
+ @blocks = [ { init: 0, end: 2 }, { init: 4, end: 6 }, { init: 8, end: 10 } ]
23
+ @lines = [
24
+ " # =begin resource\n",
25
+ " # description: #{@description}\n",
26
+ " # =end\n",
27
+ " ...\n",
28
+ " # =begin action\n",
29
+ " # action: #{@action1}\n",
30
+ " # =end\n",
31
+ " ...\n",
32
+ " # =begin action\n",
33
+ " # action: #{@action2}\n",
34
+ " # =end\n"
35
+ ]
36
+ end
37
+
38
+ context "when call extract_resource_info" do
39
+ context "when block is correct" do
40
+ before :all do
41
+ @resource_info = extract_resource_info( @lines, @blocks, 'file' )
42
+ end
43
+
44
+ it "returns resource info" do
45
+ @resource_info.keys.should be_include( "description" )
46
+ end
47
+
48
+ it "return correct description" do
49
+ @resource_info['description'].should == @description
50
+ end
51
+ end
52
+
53
+ context "when there is an error in the block" do
54
+ before :all do
55
+ @blocks2 = [ { init: 0, end: 2 } ]
56
+ @lines2 = [
57
+ " # =begin resource\n",
58
+ " # description: hello : goodbye\n",
59
+ " # =end\n"
60
+ ]
61
+ end
62
+
63
+ it "prints error message" do
64
+ output = capture_stdout { extract_resource_info( @lines2, @blocks2, 'file' ) }
65
+ output.should == "Error parsing block in file file [0 - 2]\n"
66
+ end
67
+ end
68
+ end
69
+
70
+ context "when call extract_actions_info" do
71
+ context "when block is correct" do
72
+ before :all do
73
+ @actions_info = extract_actions_info( @lines, @blocks, 'file' )
74
+ end
75
+
76
+ it "returns all actions info" do
77
+ @actions_info.size.should == 2
78
+ end
79
+
80
+ it "returns correct info of each action" do
81
+ @actions_info.first['action'].should == @action1
82
+ @actions_info.last['action'].should == @action2
83
+ end
84
+ end
85
+
86
+ context "when there is an error in the block" do
87
+ before :all do
88
+ @blocks2 = [ { init: 0, end: 2 } ]
89
+ @lines2 = [
90
+ " # =begin action\n",
91
+ " # action: hello : goodbye\n",
92
+ " # =end\n"
93
+ ]
94
+ end
95
+
96
+ it "prints error message" do
97
+ output = capture_stdout { extract_actions_info( @lines2, @blocks2, 'file' ) }
98
+ output.should == "Error parsing block in file file [0 - 2]\n"
99
+ end
100
+ end
101
+ end
102
+ end
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.4
4
+ version: 0.0.5
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-03-31 00:00:00.000000000 Z
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -207,7 +207,7 @@ files:
207
207
  - spec/lib/resources_extractor_spec.rb
208
208
  - spec/lib/routes_doc_spec.rb
209
209
  - spec/lib/templates_generator_spec.rb
210
- - spec/lib/yard_parser_spec.rb
210
+ - spec/lib/yaml_parser_spec.rb
211
211
  - spec/spec_helper.rb
212
212
  homepage: https://github.com/drinor/rapidoc.git
213
213
  licenses: []
@@ -221,18 +221,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
221
  - - ! '>='
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
- segments:
225
- - 0
226
- hash: 2741643923882514570
227
224
  required_rubygems_version: !ruby/object:Gem::Requirement
228
225
  none: false
229
226
  requirements:
230
227
  - - ! '>='
231
228
  - !ruby/object:Gem::Version
232
229
  version: '0'
233
- segments:
234
- - 0
235
- hash: 2741643923882514570
236
230
  requirements: []
237
231
  rubyforge_project:
238
232
  rubygems_version: 1.8.25
@@ -303,5 +297,5 @@ test_files:
303
297
  - spec/lib/resources_extractor_spec.rb
304
298
  - spec/lib/routes_doc_spec.rb
305
299
  - spec/lib/templates_generator_spec.rb
306
- - spec/lib/yard_parser_spec.rb
300
+ - spec/lib/yaml_parser_spec.rb
307
301
  - spec/spec_helper.rb
@@ -1,55 +0,0 @@
1
- require "spec_helper"
2
-
3
- include Rapidoc
4
-
5
- describe Rapidoc::YamlParser do
6
-
7
- before :all do
8
- @description = "resource description"
9
- @action1 = "index"
10
- @action2 = "create"
11
- @blocks = [ { init: 0, end: 2 }, { init: 4, end: 6 }, { init: 8, end: 10 } ]
12
- @lines = [
13
- " # =begin resource\n",
14
- " # description: #{@description}\n",
15
- " # =end\n",
16
- " ...\n",
17
- " # =begin action\n",
18
- " # action: #{@action1}\n",
19
- " # =end\n",
20
- " ...\n",
21
- " # =begin action\n",
22
- " # action: #{@action2}\n",
23
- " # =end\n"
24
- ]
25
- end
26
-
27
- context "when call extract_resource_info" do
28
- before :all do
29
- @resource_info = extract_resource_info( @lines, @blocks )
30
- end
31
-
32
- it "returns resource info" do
33
- @resource_info.keys.should be_include( "description" )
34
- end
35
-
36
- it "return correct description" do
37
- @resource_info['description'].should == @description
38
- end
39
- end
40
-
41
- context "when call extract_actions_info" do
42
- before :all do
43
- @actions_info = extract_actions_info( @lines, @blocks )
44
- end
45
-
46
- it "returns all actions info" do
47
- @actions_info.size.should == 2
48
- end
49
-
50
- it "returns correct info of each action" do
51
- @actions_info.first['action'].should == @action1
52
- @actions_info.last['action'].should == @action2
53
- end
54
- end
55
- end