droutes 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/lib/droutes/parser.rb +1 -1
- data/lib/generators/droutes/doc/doc_generator.rb +39 -0
- data/lib/generators/droutes/doc/templates/controller.html +74 -0
- data/lib/generators/droutes/doc/templates/index.html +41 -0
- metadata +5 -3
- data/lib/generators/droutes/documentation_generator.rb +0 -141
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2487bf8257158a4e4eea12767861d62924a5882d
|
4
|
+
data.tar.gz: 5a31c97b169ca682f99b896770888d49063f5b67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f5a3ea1e82705e18f1b9e23d1b20b2a9d426060bec2752844d6b3305074ad49c593d37f910dd3c0a151ba311c7ae1e1899f07c52be4c1d5dfdf04c167c1d366
|
7
|
+
data.tar.gz: 5293285db0cb4bb36002cb274ec832e87c00de363d241c5bdaf6956a26c791b00b5c3499b9c74ea118a335c6f845a9f6b4e75a65d63b37d8a6eb3ce6c2c66f8c
|
data/lib/droutes/parser.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Droutes::Generators
|
2
|
+
class DocGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
|
5
|
+
def create_docs
|
6
|
+
@root = Droutes::Parser.new(Rails.application.routes.routes).parse
|
7
|
+
template("index.html", ".droutes/index.html")
|
8
|
+
@root.children.each do |klass|
|
9
|
+
@klass = klass
|
10
|
+
template("controller.html", ".droutes/#{klass.controller}.html")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def example_json(params)
|
17
|
+
example_json = ''
|
18
|
+
params.each do |param|
|
19
|
+
eg_param = param.types.first
|
20
|
+
eg_text = if ["String", "Symbol"].include?(eg_param)
|
21
|
+
'"some string"'
|
22
|
+
elsif ["Fixnum", "Integer", "Int"].include?(eg_param)
|
23
|
+
rand(100)
|
24
|
+
elsif ["Float", "Double", "Numeric"].include?(eg_param)
|
25
|
+
(rand * 100.0).round(2)
|
26
|
+
elsif eg_param == "Hash"
|
27
|
+
'{}'
|
28
|
+
elsif eg_param == "Arrray"
|
29
|
+
'[]'
|
30
|
+
end
|
31
|
+
example_json += "\n \"#{param.name}\": #{eg_text},"
|
32
|
+
end
|
33
|
+
unless example_json.blank?
|
34
|
+
example_json = "<p>Example JSON Body</p><pre><code>{#{example_json}\n}</code></pre>"
|
35
|
+
end
|
36
|
+
example_json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
6
|
+
<title><%= Rails.application.class.parent_name %> :: <%= @klass.controller %></title>
|
7
|
+
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
8
|
+
</head>
|
9
|
+
|
10
|
+
<body>
|
11
|
+
<div class="container">
|
12
|
+
<div class="row">
|
13
|
+
<div class="col-xs-10 col-offset-xs-1">
|
14
|
+
<h1><%= @klass.controller.camelize %> API</h1>
|
15
|
+
<h4>Return to index</h4>
|
16
|
+
|
17
|
+
<div class="api">
|
18
|
+
|
19
|
+
<p class="summary">
|
20
|
+
<%= @klass.docs.gsub(/\n/, " ") %>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<div class="toc">
|
24
|
+
<h3>Routes</h3>
|
25
|
+
<% structs = @klass.paths.keys.sort.collect {|key| @klass.paths[key].values}.flatten %>
|
26
|
+
<dl>
|
27
|
+
<% structs.each do |struct| %>
|
28
|
+
<dt>
|
29
|
+
<a href="<%= struct.action %>">
|
30
|
+
<%= "#{struct.verb} #{struct.path}" %>
|
31
|
+
</a>
|
32
|
+
</dt>
|
33
|
+
<dd><%= struct.docs.summary %></dd>
|
34
|
+
<% end %>
|
35
|
+
</dl>
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<div class="routes">
|
39
|
+
<h3>Documentation</h3>
|
40
|
+
<% structs.each do |struct| %>
|
41
|
+
<div class="route panel panel-default">
|
42
|
+
<div class="panel-heading">
|
43
|
+
<h2 class="panel-title">
|
44
|
+
<code><%= "#{struct.verb} #{struct.path}" %></code> <small><%= struct.action %></small>
|
45
|
+
</h2>
|
46
|
+
</div>
|
47
|
+
<div class="panel-body">
|
48
|
+
<p class="summary"><%= struct.docs.summary %></p>
|
49
|
+
<dl class="dl-horizontal">
|
50
|
+
<% struct.docs.tags("param").each do |param| %>
|
51
|
+
<dt><%= param.name %></dt>
|
52
|
+
<dd>[<%= param.types.join("|") %>] <%= param.text %></dd>
|
53
|
+
<% end %>
|
54
|
+
<% ret = struct.docs.tags("return").first %>
|
55
|
+
<% if ret %>
|
56
|
+
<dt>[return]</dt>
|
57
|
+
<dd>[<%= ret.types.join("|") %>] <%= ret.text %></dd>
|
58
|
+
<% end %>
|
59
|
+
</dl>
|
60
|
+
<% eg_json = example_json(struct.docs.tags("param")) %>
|
61
|
+
<% unless eg_json.blank? %>
|
62
|
+
<div><%= eg_json %></div>
|
63
|
+
<% end %>
|
64
|
+
</div>
|
65
|
+
</div>
|
66
|
+
<% end %>
|
67
|
+
</div>
|
68
|
+
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
</div>
|
72
|
+
</div>
|
73
|
+
</body>
|
74
|
+
</html>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
6
|
+
<title><%= Rails.application.class.parent_name %> :: Route Index</title>
|
7
|
+
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
8
|
+
</head>
|
9
|
+
|
10
|
+
<body>
|
11
|
+
<div class="container">
|
12
|
+
<div class="row">
|
13
|
+
<h1><%= Rails.application.class.parent_name %> :: Route Index</h1>
|
14
|
+
<p>
|
15
|
+
Below is a collection of controllers and their paths. Some paths may
|
16
|
+
have multiple verbs associated with it (like a call that accepts both
|
17
|
+
GET and POST requests).
|
18
|
+
</p>
|
19
|
+
<div class="col-xs-8 col-offset-xs-2">
|
20
|
+
<% @root.children.each do |klass| %>
|
21
|
+
<h3>
|
22
|
+
<a href="<%= klass.controller %>.html">
|
23
|
+
<%= klass.controller.camelize %>
|
24
|
+
</a>
|
25
|
+
</h3>
|
26
|
+
<ul>
|
27
|
+
<% klass.paths.each do |path, actions| %>
|
28
|
+
<% struct = actions.values.first %>
|
29
|
+
<li>
|
30
|
+
<a href="<%= klass.controller %>.html#<%= struct.action %>">
|
31
|
+
<%= path %>
|
32
|
+
</a>
|
33
|
+
</li>
|
34
|
+
<% end %>
|
35
|
+
</ul>
|
36
|
+
<% end %>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
</body>
|
41
|
+
</head>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: droutes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Margison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Generating documentation for REST endpoints for client developers can
|
14
14
|
be a pain, but droutes can make it easy.
|
@@ -23,7 +23,9 @@ files:
|
|
23
23
|
- README.md
|
24
24
|
- lib/droutes.rb
|
25
25
|
- lib/droutes/parser.rb
|
26
|
-
- lib/generators/droutes/
|
26
|
+
- lib/generators/droutes/doc/doc_generator.rb
|
27
|
+
- lib/generators/droutes/doc/templates/controller.html
|
28
|
+
- lib/generators/droutes/doc/templates/index.html
|
27
29
|
homepage: https://github.com/kolorahl/droutes
|
28
30
|
licenses:
|
29
31
|
- GPLv3
|
@@ -1,141 +0,0 @@
|
|
1
|
-
module Droutes::Generators
|
2
|
-
class DocumentationGenerator < Rails::Generators::Base
|
3
|
-
source_root File.expand_path("../templates", __FILE__)
|
4
|
-
|
5
|
-
desc "Parse application routes and create REST API documentation."
|
6
|
-
def create_docs
|
7
|
-
@root = Droutes::Parser.new(Rails.application.routes.routes).parse
|
8
|
-
@root.children.each do |klass|
|
9
|
-
next if klass.paths.empty?
|
10
|
-
content = class_doc(klass)
|
11
|
-
create_file(".droutes/#{klass.controller}.html", page_wrapper(klass.controller.camelcase, content))
|
12
|
-
end
|
13
|
-
create_file(".droutes/index.html", index_page)
|
14
|
-
end
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def action_id(struct)
|
19
|
-
"#{struct.controller}_#{struct.action}"
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def index_page
|
25
|
-
<<HTML
|
26
|
-
<!doctype html>
|
27
|
-
<html lang="en">
|
28
|
-
<head>
|
29
|
-
<meta charset="utf-8">
|
30
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
31
|
-
<title>Route Index</title>
|
32
|
-
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
33
|
-
</head>
|
34
|
-
|
35
|
-
<body>
|
36
|
-
<p>All available routes (sorted by name):</p>
|
37
|
-
<ul>
|
38
|
-
#{@root.children.collect do |node|
|
39
|
-
node.paths.collect do |path, actions|
|
40
|
-
struct = actions.values.first
|
41
|
-
" <li><a href=\"#{struct.controller}.html##{action_id(struct)}\">#{path}</a></li>"
|
42
|
-
end.join("\n")
|
43
|
-
end.join("")}
|
44
|
-
</ul>
|
45
|
-
</body>
|
46
|
-
</html>
|
47
|
-
HTML
|
48
|
-
end
|
49
|
-
|
50
|
-
def page_wrapper(title, content)
|
51
|
-
<<HTML
|
52
|
-
<!doctype html>
|
53
|
-
<html lang="en">
|
54
|
-
<head>
|
55
|
-
<meta charset="utf-8">
|
56
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
57
|
-
<title>#{title}</title>
|
58
|
-
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
59
|
-
</head>
|
60
|
-
|
61
|
-
<body>
|
62
|
-
#{content}
|
63
|
-
|
64
|
-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
65
|
-
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
66
|
-
</body>
|
67
|
-
</html>
|
68
|
-
HTML
|
69
|
-
end
|
70
|
-
|
71
|
-
def class_doc(klass)
|
72
|
-
structs = []
|
73
|
-
klass.paths.keys.sort.each {|path| structs += klass.paths[path].values}
|
74
|
-
<<DOC
|
75
|
-
<div class="container-fluid">
|
76
|
-
<h1>#{klass.controller} API</h1>
|
77
|
-
<div id="#{klass.controller}" class="controller">
|
78
|
-
<p class="summary">#{klass.docs.gsub(/\n/, " ")}</p>
|
79
|
-
<div class="toc">
|
80
|
-
<h3>Routes</h3>
|
81
|
-
<dl>
|
82
|
-
#{structs.collect do |struct|
|
83
|
-
" <dt><a href=\"##{action_id(struct)}\">#{struct.verb} #{struct.path}</a></dt><dd>#{struct.docs.summary}</dd>"
|
84
|
-
end.join("\n")}
|
85
|
-
</dl>
|
86
|
-
</div>
|
87
|
-
<div class="routes">
|
88
|
-
<h3>Documentation</h3>
|
89
|
-
#{structs.collect {|struct| action_doc(struct)}.join("\n")}
|
90
|
-
</div>
|
91
|
-
</div>
|
92
|
-
</div>
|
93
|
-
DOC
|
94
|
-
end
|
95
|
-
|
96
|
-
def action_doc(struct)
|
97
|
-
<<DOC
|
98
|
-
<div id="#{action_id(struct)}" class="action panel panel-default">
|
99
|
-
<div class="panel-heading">
|
100
|
-
<h2 class="route panel-title"><code>#{struct.verb} #{struct.path}</code> <small>#{struct.action}</small></h2>
|
101
|
-
</div>
|
102
|
-
<div class="comments panel-body">
|
103
|
-
#{comments_doc(struct.docs)}
|
104
|
-
</div>
|
105
|
-
</div>
|
106
|
-
DOC
|
107
|
-
end
|
108
|
-
|
109
|
-
def comments_doc(doc)
|
110
|
-
params_dl = '<dl class="dl-horizontal params">'
|
111
|
-
example_json = ''
|
112
|
-
doc.tags("param").each do |param|
|
113
|
-
params_dl += " <dt>#{param.name}</dt><dd>[#{param.types.join('|')}] #{param.text}</dd>"
|
114
|
-
eg_param = param.types.first
|
115
|
-
eg_text = if ["String", "Symbol"].include?(eg_param)
|
116
|
-
'"some string"'
|
117
|
-
elsif ["Fixnum", "Integer", "Int"].include?(eg_param)
|
118
|
-
rand(100)
|
119
|
-
elsif ["Float", "Double", "Numeric"].include?(eg_param)
|
120
|
-
(rand * 100.0).round(2)
|
121
|
-
elsif eg_param == "Hash"
|
122
|
-
'{}'
|
123
|
-
elsif eg_param == "Arrray"
|
124
|
-
'[]'
|
125
|
-
end
|
126
|
-
example_json += "\n \"#{param.name}\": #{eg_text},"
|
127
|
-
end
|
128
|
-
unless example_json.blank?
|
129
|
-
example_json = "<p>Example JSON Body</p><pre><code>{#{example_json}\n}</code></pre>"
|
130
|
-
end
|
131
|
-
<<DOC
|
132
|
-
<p class="summary">#{doc.summary}</p>
|
133
|
-
<dl class="dl-horizontal params">
|
134
|
-
#{params_dl}
|
135
|
-
#{(ret = doc.tags("return").first) and "<dt>[return]</dt><dd>#{ret.text}</dd>"}
|
136
|
-
</dl>
|
137
|
-
#{example_json}
|
138
|
-
DOC
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|