rapi_doc 0.1.1 → 0.1.2

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 ADDED
@@ -0,0 +1,55 @@
1
+ Rails API Doc Generator
2
+ =======================
3
+
4
+ RESTTful API generator...
5
+
6
+ It generates a set of HTML views in the public directory. Parses the desired controllers and generates appropriate views.
7
+
8
+ Currently does not read routes.rb and requires manual entry of routes
9
+
10
+ Installation
11
+ ============
12
+
13
+ `gem install rapi_doc`
14
+
15
+ Usage
16
+ =====
17
+
18
+ Run `rake rapi_doc` to generate config and layout files. (TODO: Add a separate rake task to generate config files)
19
+
20
+ Modify config file by adding your controllers, e.g.:
21
+
22
+ `
23
+ users:
24
+ location: "/users"
25
+ controller_name: "users_controller.rb"
26
+ `
27
+
28
+ Then invoke the generation by calling:
29
+
30
+ `rake rapi_doc`
31
+
32
+ Documentation Example
33
+ ---------------------
34
+
35
+ =begin apidoc
36
+ url:: /users
37
+ method:: GET
38
+ access:: FREE
39
+ return:: [JSON|XML] - list of user objects
40
+ param:: page:int - the page, default is 1
41
+ param:: per_page:int - max items per page, default is 10
42
+
43
+ Get a list of all users in the system with pagination. Defaults to 10 per page
44
+ =end
45
+
46
+ Layout
47
+ ------
48
+
49
+ Documentation layout is located at `config/rapi_doc/layout.html.erb`.
50
+
51
+ Credit
52
+ ======
53
+
54
+ * Based on RAPI Doc by Jaap van der Meer found here: http://code.google.com/p/rapidoc/
55
+ * https://github.com/sabman/rapi_doc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/rapi_config.rb CHANGED
@@ -12,12 +12,8 @@ module RapiDoc
12
12
  File.join(find_location(location), 'config.yml')
13
13
  end
14
14
 
15
- def index_layout_file(location)
16
- File.join(find_location(location), 'index.html.erb')
17
- end
18
-
19
- def resource_layout_file(location)
20
- File.join(find_location(location), 'resource.html.erb')
15
+ def layout_file(location)
16
+ File.join(find_location(location), 'layout.html.erb')
21
17
  end
22
18
 
23
19
  def find_location(location)
@@ -6,7 +6,7 @@ task :rapi_doc do
6
6
  yml = YAML::load(File.open(config_file(:target)))
7
7
  rescue
8
8
  FileUtils.mkdir(config_dir) if (!File.directory?(config_dir))
9
- [config_file(:template), index_layout_file(:template), resource_layout_file(:template)].each do |_file|
9
+ [config_file(:template), layout_file(:template)].each do |_file|
10
10
  FileUtils.cp _file, config_dir
11
11
  puts "Generated config/rapi_doc/#{File.basename(_file)}" # TODO Add instructions for users to update the config file
12
12
  end
@@ -16,11 +16,11 @@ task :rapi_doc do
16
16
  if yml
17
17
  resources = []
18
18
  yml.keys.each do |key|
19
- resources << ResourceDoc.new(key, yml[key]["location"], yml[key]["controller_name"])
19
+ resources << RapiDoc::ResourceDoc.new(key, yml[key]["location"], yml[key]["controller_name"])
20
20
  end
21
21
 
22
22
  # generate the apidoc
23
- RAPIDoc.new(resources)
23
+ RapiDoc::RAPIDoc.new(resources)
24
24
  end
25
25
  end
26
26
 
data/lib/rapi_doc.rb CHANGED
@@ -34,7 +34,8 @@ module RapiDoc
34
34
  # generate the index file for the api views
35
35
  def generate_index!
36
36
  template = ""
37
- File.open(index_layout_file(:target)).each { |line| template << line }
37
+ @page_type = 'index'
38
+ File.open(layout_file(:target)).each { |line| template << line }
38
39
  parsed = ERB.new(template).result(binding)
39
40
  File.open(File.join(temp_dir, "index.html"), 'w') { |file| file.write parsed }
40
41
  end
@@ -68,4 +69,4 @@ module RapiDoc
68
69
  @temp_dir ||= "#{Dir.mktmpdir("apidoc")}/"
69
70
  end
70
71
  end
71
- end
72
+ end
data/lib/resource_doc.rb CHANGED
@@ -97,30 +97,21 @@ module RapiDoc
97
97
  end
98
98
  # write it to a file
99
99
  template = ""
100
- File.open(resource_layout_file(:target)).each { |line| template << line }
100
+ File.open(layout_file(:target)).each { |line| template << line }
101
101
  parsed = ERB.new(template).result(binding)
102
102
  File.open(File.join(temp_dir, name + ".html"), 'w') { |file| file.write parsed }
103
103
  end
104
104
 
105
-
106
105
  def get_parsed_header
107
106
  template = ""
108
107
  File.open(File.join(File.dirname(__FILE__), '..', 'templates', '_resource_header.html.erb')).each { |line| template << line }
109
-
110
- puts "-"*30
111
- puts ">>> inside: get_parsed_header"
112
- puts ERB.new(template).result(@class_block.get_binding)
113
- puts "-"*30; puts ""
114
-
115
- return ERB.new(template).result(@class_block.get_binding)
108
+ ERB.new(template).result(@class_block.get_binding)
116
109
  end
117
110
 
118
-
119
111
  def get_parsed_method(method_block)
120
112
  template = ""
121
113
  File.open(File.join(File.dirname(__FILE__), '..', 'templates', '_resource_method.html.erb')).each { |line| template << line }
122
114
  return ERB.new(template).result(method_block.get_binding)
123
115
  end
124
-
125
116
  end
126
- end
117
+ end
@@ -26,6 +26,14 @@
26
26
  </ul>
27
27
  <% end %>
28
28
 
29
+ <% if @output %>
30
+ <strong>Output:</strong>
31
+ <div class="code">
32
+ <%= @output %>
33
+ </div>
34
+ <br />
35
+ <% end %>
36
+
29
37
  <% unless @request.blank? %>
30
38
  <strong>Request:</strong>
31
39
  <pre class="code"><code><%= @request %></code></pre>
@@ -43,24 +43,43 @@
43
43
  font-size: 1.4em;
44
44
  color:#262626;
45
45
  }
46
+ .code {
47
+ font-family: monospace;
48
+ }
46
49
  </style>
47
50
 
48
51
  </head>
49
52
  <body>
50
53
  <div class="content">
51
54
 
52
- <div id="introduction">
53
- <!-- documentation intro -->
54
- </div>
55
+ <% if @page_type == 'index' %>
56
+ <div id="introduction">
57
+ <!-- documentation intro -->
58
+ </div>
59
+
60
+ <h2>Resources</h2>
61
+ <div id="resources">
62
+ <ul>
63
+ <% @resources.each do |r| %>
64
+ <li>Resource: <a href="/apidoc/<%=r.name %>.html"><%=r.resource_location %></a></li>
65
+ <% end %>
66
+ </ul>
67
+ </div>
68
+ <% else %>
69
+ <div id="navigation">
70
+ <ul class="main">
71
+ <li><a href="/apidoc/index.html">&laquo; Back to index</a></li>
72
+ </ul>
73
+ </div>
74
+
75
+ <hr />
76
+
77
+ <%=@header_code %>
55
78
 
56
- <h2>Resources</h2>
57
- <div id="resources">
58
- <ul>
59
- <% @resources.each do |r| %>
60
- <li>Resource: <a href="/apidoc/<%=r.name %>.html"><%=r.resource_location %></a></li>
79
+ <% @method_codes.each do |mc| %>
80
+ <%=mc %>
61
81
  <% end %>
62
- </ul>
63
- </div>
82
+ <% end %>
64
83
 
65
84
  </div>
66
85
  </body>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rapi_doc
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Husein Choroomi
@@ -64,13 +64,13 @@ extensions: []
64
64
 
65
65
  extra_rdoc_files:
66
66
  - LICENSE.txt
67
- - README
67
+ - README.md
68
68
  files:
69
69
  - .rvmrc
70
70
  - Gemfile
71
71
  - Gemfile.lock
72
72
  - LICENSE.txt
73
- - README
73
+ - README.md
74
74
  - Rakefile
75
75
  - VERSION
76
76
  - init.rb
@@ -85,8 +85,7 @@ files:
85
85
  - templates/_resource_header.html.erb
86
86
  - templates/_resource_method.html.erb
87
87
  - templates/config.yml
88
- - templates/index.html.erb
89
- - templates/resource.html.erb
88
+ - templates/layout.html.erb
90
89
  - test/rapi_doc_test.rb
91
90
  - test/test_helper.rb
92
91
  - uninstall.rb
@@ -103,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
102
  requirements:
104
103
  - - ">="
105
104
  - !ruby/object:Gem::Version
106
- hash: 4485947497076302486
105
+ hash: -1142143920796928786
107
106
  segments:
108
107
  - 0
109
108
  version: "0"
data/README DELETED
@@ -1,44 +0,0 @@
1
- @WIP
2
- Based on RAPI Doc by Jaap van der Meer found here: http://code.google.com/p/rapidoc/
3
-
4
- Rails API Doc Generator
5
- Original Author: JPM van der Meer
6
- Modified By: Chelsea Robb
7
- =======================
8
- With API DOC one can generate code for a Restful Rails API.
9
- It generates a set of HTML views in the public directory. Parses the desired controllers and generates appropriate views.
10
- Currently does not read routes.rb and requires manual entry of routes
11
-
12
- =INSTALL
13
- gem install rapi_doc
14
-
15
- ==Layout files
16
- You can find documentation layouts in config/rapi_doc
17
-
18
- index.html.erb is used for index page.
19
- resource.html.erb is used for individual controllers.
20
-
21
- ==Usage
22
- Run 'rake rapi_doc' to generate config and layout files. (TODO: Add a separte rake task to generate config files)
23
- Modify config file by adding your controllers, e.g.:
24
-
25
- users:
26
- location: "/users"
27
- controller_name: "users_controller.rb"
28
-
29
- Then invoke the generation by calling:
30
- rake rapi_doc
31
-
32
- ==Documentation Example
33
-
34
- =begin apidoc
35
- url:: /users
36
- method:: GET
37
- access:: FREE
38
- return:: [JSON|XML] - list of user objects
39
- param:: page:int - the page, default is 1
40
- param:: per_page:int - max items per page, default is 10
41
-
42
- Get a list of all users in the system with pagination. Defaults to 10 per page
43
- =end
44
-
@@ -1,67 +0,0 @@
1
- <!-- TODO Use same layout for index and resources -->
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title><%= @name || 'Home' %></title>
7
-
8
- <style>
9
- body {
10
- line-height: 1.5em;
11
- color:#484848;
12
- }
13
-
14
- ul, ol {
15
- margin-bottom: 0.8em;
16
- }
17
-
18
- li {
19
- padding-left: 10px;
20
- margin-right: 10px;
21
- }
22
-
23
- #resources {
24
-
25
- }
26
-
27
- h1, h2, h3 {
28
- padding-top: 8px;
29
- padding-bottom: 2px;
30
- }
31
-
32
- #method {
33
- padding: 15px 30px;
34
- border-top:1px solid #ddd;
35
- }
36
-
37
- #http_verb {
38
- color:#ff6600;
39
- width:200px;
40
- margin-right:20px;'
41
- }
42
-
43
- .description{
44
- font-size: 1.4em;
45
- color:#262626;
46
- }
47
- </style>
48
-
49
- </head>
50
- <body>
51
- <div class="content">
52
- <div id="navigation">
53
- <ul class="main">
54
- <li><a href="/apidoc/index.html">&laquo; Back to index</a></li>
55
- </ul>
56
- </div>
57
-
58
- <hr />
59
-
60
- <%=@header_code %>
61
-
62
- <% @method_codes.each do |mc| %>
63
- <%=mc %>
64
- <% end %>
65
- </div>
66
- </body>
67
- </html>