cdoc 0.1.5 → 0.1.6
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/Gemfile +0 -1
- data/README.md +17 -4
- data/cdoc.gemspec +0 -1
- data/lib/cdoc.rb +53 -51
- data/lib/cdoc/version.rb +1 -1
- data/lib/layouts/bootstrap.html +10 -13
- data/lib/layouts/default.html +2 -2
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 330e5acf5e69b1f523fa79269626598381210081
|
4
|
+
data.tar.gz: ba839a48e9775992def0dd457e30748145b003a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55f81bbabe959fd40ffa73eb2352178fddef674c4899d49a13b7d3c3df23c1a468d261bb4354e5ac559f48c6059e8de66432c0f17c4c57d39545fdf595006c83
|
7
|
+
data.tar.gz: 5ff8aa840889db2cc74fba3998cde069f45d9a314216fb91b7d0897976889821c446f96dd1d12f49e62f71a1d21e598c74deab344e00a3e713776ca3880fc104
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ For example
|
|
7
7
|
|
8
8
|
```
|
9
9
|
#doc
|
10
|
-
# @
|
10
|
+
# @api /api/v1/accounts/list
|
11
11
|
# @params
|
12
12
|
# {
|
13
13
|
# user_id: '123456'
|
@@ -29,7 +29,17 @@ For example
|
|
29
29
|
# }
|
30
30
|
```
|
31
31
|
|
32
|
-
The code sections will be highligted if a 2 space indentation is used.
|
32
|
+
The code sections will be highligted if a 2 space indentation is used. Also if the code section is a valid json then the section will be highlighted.
|
33
|
+
|
34
|
+
## Tags
|
35
|
+
|
36
|
+
If a line starts with `@word` then the line is considered as a tagged line. The text after the tagged line is simply highlighted.
|
37
|
+
|
38
|
+
eg : @api /api/v1/accounts/list will be rendered as
|
39
|
+
|
40
|
+
Api **/api/v1/accounts/list**
|
41
|
+
|
42
|
+
To make it simple none of the tags is considered special at the moment.
|
33
43
|
|
34
44
|
## Installation
|
35
45
|
|
@@ -51,8 +61,11 @@ Or install it yourself as:
|
|
51
61
|
|
52
62
|
cd to your rails application and run
|
53
63
|
|
54
|
-
$ cdoc
|
55
|
-
$
|
64
|
+
$ cdoc TITLE="Fizbuz API Documentation"
|
65
|
+
$ cd doc
|
66
|
+
$ ruby -run -e httpd -- -p 5000 . # start a web server to serve the generated files
|
67
|
+
|
68
|
+
Now open the browser and go to [http://localhost:5000](http://localhost:5000) to view the documentation.
|
56
69
|
|
57
70
|
## Development
|
58
71
|
|
data/cdoc.gemspec
CHANGED
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.bindir = "bin"
|
30
30
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
|
-
spec.add_runtime_dependency "redcarpet", "~>3.4.0"
|
33
32
|
spec.add_runtime_dependency "pygments.rb", "~>1.1.1"
|
34
33
|
spec.add_development_dependency "bundler", "~> 1.13"
|
35
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/cdoc.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'cdoc/version'
|
2
2
|
require 'rake'
|
3
|
-
require 'redcarpet'
|
4
3
|
require 'pygments'
|
5
4
|
require 'json'
|
6
5
|
|
@@ -10,11 +9,8 @@ module Cdoc
|
|
10
9
|
def to_id(str)
|
11
10
|
str.gsub(/\W/, '').downcase
|
12
11
|
end
|
13
|
-
end
|
14
12
|
|
15
|
-
|
16
|
-
def block_code(code, lang='text')
|
17
|
-
lang = lang && lang.split.first || "text"
|
13
|
+
def highlight(code, lang)
|
18
14
|
Pygments.highlight(code, lexer: lang)
|
19
15
|
end
|
20
16
|
end
|
@@ -24,7 +20,6 @@ module Cdoc
|
|
24
20
|
include Helpers
|
25
21
|
|
26
22
|
def initialize
|
27
|
-
@docstring = ''
|
28
23
|
@content = []
|
29
24
|
end
|
30
25
|
|
@@ -32,15 +27,23 @@ module Cdoc
|
|
32
27
|
@title = title
|
33
28
|
end
|
34
29
|
|
30
|
+
def sidebar(keys)
|
31
|
+
return if keys.empty?
|
32
|
+
|
33
|
+
tmpl_item = '<a href="#%{id}" class="list-group-item">%{item}</a>'
|
34
|
+
|
35
|
+
items = keys.map do |key|
|
36
|
+
tmpl_item % { id: to_id(key), item: key.capitalize }
|
37
|
+
end
|
38
|
+
|
39
|
+
@sidebar = ['<div class="list-group">', items, '</div>'].flatten.join("\n")
|
40
|
+
end
|
41
|
+
|
35
42
|
def section(str)
|
36
43
|
template = "<p id='%{id}'><h3>%{str}</h3></p>"
|
37
44
|
@content << template % { id: to_id(str), str: str }
|
38
45
|
end
|
39
46
|
|
40
|
-
def sidebar(sidebar)
|
41
|
-
@sidebar = sidebar
|
42
|
-
end
|
43
|
-
|
44
47
|
def subsection(str)
|
45
48
|
|
46
49
|
template = %q(
|
@@ -53,7 +56,7 @@ module Cdoc
|
|
53
56
|
</div>
|
54
57
|
</div>)
|
55
58
|
|
56
|
-
|
59
|
+
lines = str.split("\n")
|
57
60
|
index = 0
|
58
61
|
section_header = ''
|
59
62
|
sub_section = []
|
@@ -78,7 +81,7 @@ module Cdoc
|
|
78
81
|
begin
|
79
82
|
json = JSON.parse(code_str)
|
80
83
|
code_str = JSON.pretty_generate(json)
|
81
|
-
block =
|
84
|
+
block = highlight(code_str, 'json')
|
82
85
|
rescue JSON::ParserError => e
|
83
86
|
# puts e.message
|
84
87
|
block = ['<pre><code>', code_str, '</code></pre>'].join("\n")
|
@@ -90,6 +93,24 @@ module Cdoc
|
|
90
93
|
index = index + 1
|
91
94
|
end
|
92
95
|
end
|
96
|
+
elsif unordered_list?(line)
|
97
|
+
list_block = []
|
98
|
+
list_block << line.sub(/\-|\*/, '').strip
|
99
|
+
|
100
|
+
loop do
|
101
|
+
line = lines[index + 1]
|
102
|
+
|
103
|
+
if line.nil? || !unordered_list?(line)
|
104
|
+
list_block.join('\n')
|
105
|
+
break
|
106
|
+
else
|
107
|
+
list_block << line.sub(/\-|\*/, '').strip
|
108
|
+
index = index + 1
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
list_block = list_block.map { |i| ['<footer>', i, '</footer>'].join('') }
|
113
|
+
block = ['<blockquote>', list_block, '</blockquote>'].flatten.join("\n")
|
93
114
|
else
|
94
115
|
block = [line, '<br/>'].join('')
|
95
116
|
end
|
@@ -106,6 +127,11 @@ module Cdoc
|
|
106
127
|
@content << template % { section_header: section_header, section_body: sub_section.join("\n")}
|
107
128
|
end
|
108
129
|
|
130
|
+
def unordered_list?(line)
|
131
|
+
l = line.strip
|
132
|
+
l.start_with?('- ') || l.start_with?('* ')
|
133
|
+
end
|
134
|
+
|
109
135
|
def tagged_line(line, tag)
|
110
136
|
if ['url', 'endpoint', 'api'].include?(tag.downcase)
|
111
137
|
# set the title of the section
|
@@ -123,16 +149,9 @@ module Cdoc
|
|
123
149
|
|
124
150
|
def finish
|
125
151
|
FileUtils.mkdir_p('doc') unless Dir.exists?('doc')
|
126
|
-
render_as_markdown
|
127
152
|
render_as_html
|
128
153
|
end
|
129
154
|
|
130
|
-
def render_as_markdown
|
131
|
-
f = File.open('doc/index.md', 'w+')
|
132
|
-
f.write(@docstring)
|
133
|
-
f.close
|
134
|
-
end
|
135
|
-
|
136
155
|
def content
|
137
156
|
@content.flatten.join('')
|
138
157
|
end
|
@@ -141,16 +160,11 @@ module Cdoc
|
|
141
160
|
layout_file = File.join(File.dirname(__FILE__), 'layouts/bootstrap.html')
|
142
161
|
layout = File.read(layout_file)
|
143
162
|
f = File.open('doc/index.html', 'w+')
|
144
|
-
renderer = DocRenderer.new
|
145
|
-
markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)
|
146
163
|
html = layout % { title: @title, sidebar: @sidebar, content: content }
|
147
164
|
f.write(html)
|
148
165
|
f.close
|
149
166
|
|
150
|
-
|
151
|
-
puts File.join(File.dirname(__FILE__), 'styles')
|
152
|
-
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'styles'), 'doc/css')
|
153
|
-
end
|
167
|
+
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'styles'), 'doc/')
|
154
168
|
end
|
155
169
|
end
|
156
170
|
|
@@ -166,26 +180,16 @@ module Cdoc
|
|
166
180
|
@doc = DocString.new
|
167
181
|
end
|
168
182
|
|
169
|
-
def generate_sidebar(keys)
|
170
|
-
tmpl_item = '<a href="#%{id}" class="list-group-item">%{item}</a>'
|
171
|
-
|
172
|
-
items = keys.map do |key|
|
173
|
-
tmpl_item % { id: to_id(key), item: key.capitalize }
|
174
|
-
end
|
175
|
-
|
176
|
-
['<div class="list-group">', items, '</div>'].flatten.join("\n")
|
177
|
-
end
|
178
|
-
|
179
183
|
def generate
|
180
|
-
@doc.title('Chillr API Documentaion')
|
181
|
-
|
182
|
-
@file_groups = files.group_by { |f| File.basename(f, '_controller.rb') }
|
184
|
+
@doc.title(ENV['TITLE'] || 'Chillr API Documentaion')
|
183
185
|
|
184
|
-
|
186
|
+
file_groups = files.group_by { |f| File.basename(f, '_controller.rb') }
|
185
187
|
|
186
|
-
|
188
|
+
# Generates sidebar
|
189
|
+
@doc.sidebar(file_groups.keys)
|
187
190
|
|
188
|
-
|
191
|
+
# Generates body
|
192
|
+
file_groups.each do |group, files|
|
189
193
|
@doc.section(group.capitalize)
|
190
194
|
files.each do |file|
|
191
195
|
docs = extract_documentation(file)
|
@@ -206,8 +210,8 @@ module Cdoc
|
|
206
210
|
return
|
207
211
|
end
|
208
212
|
|
209
|
-
|
210
|
-
|
213
|
+
sections = []
|
214
|
+
section_doc_lines = []
|
211
215
|
recording = false
|
212
216
|
|
213
217
|
lines.each do |line|
|
@@ -222,22 +226,20 @@ module Cdoc
|
|
222
226
|
if line.empty?
|
223
227
|
next
|
224
228
|
elsif line.start_with?('#')
|
225
|
-
|
229
|
+
section_doc_lines << line.strip.sub('#', '')
|
226
230
|
else
|
227
231
|
recording = false
|
228
|
-
|
229
|
-
|
232
|
+
sections << section_doc_lines.join("\n")
|
233
|
+
section_doc_lines = []
|
230
234
|
end
|
231
235
|
end
|
232
236
|
end
|
233
237
|
|
234
|
-
if recording && (
|
235
|
-
|
236
|
-
docs << doclines.join("\n")
|
237
|
-
doclines = []
|
238
|
+
if recording && (section_doc_lines.length != 0)
|
239
|
+
sections << section_doc_lines.join("\n")
|
238
240
|
end
|
239
241
|
|
240
|
-
|
242
|
+
sections
|
241
243
|
end
|
242
244
|
end
|
243
245
|
end
|
data/lib/cdoc/version.rb
CHANGED
data/lib/layouts/bootstrap.html
CHANGED
@@ -10,6 +10,15 @@
|
|
10
10
|
<!-- Bootstrap -->
|
11
11
|
<!--<link href="/css/bootstrap.min.css" rel="stylesheet">-->
|
12
12
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
13
|
+
<link href="/styles/fruity.css" rel="stylesheet">
|
14
|
+
|
15
|
+
<style>
|
16
|
+
pre {
|
17
|
+
color: #ffffff;
|
18
|
+
background-color: black;
|
19
|
+
border-color: #0f140f;
|
20
|
+
}
|
21
|
+
</style>
|
13
22
|
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
14
23
|
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
15
24
|
<!--[if lt IE 9]>
|
@@ -28,20 +37,8 @@
|
|
28
37
|
<span class="icon-bar"></span>
|
29
38
|
<span class="icon-bar"></span>
|
30
39
|
</button>
|
31
|
-
<a class="navbar-brand" href="
|
40
|
+
<a class="navbar-brand" href="/">Chillr</a>
|
32
41
|
</div>
|
33
|
-
|
34
|
-
<!-- Collect the nav links, forms, and other content for toggling -->
|
35
|
-
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
36
|
-
<ul class="nav navbar-nav navbar-right">
|
37
|
-
<li class="dropdown">
|
38
|
-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">More<span class="caret"></span></a>
|
39
|
-
<ul class="dropdown-menu">
|
40
|
-
<li><a href="#">Action</a></li>
|
41
|
-
</ul>
|
42
|
-
</li>
|
43
|
-
</ul>
|
44
|
-
</div><!-- /.navbar-collapse -->
|
45
42
|
</div><!-- /.container-fluid -->
|
46
43
|
</nav>
|
47
44
|
<div class="container">
|
data/lib/layouts/default.html
CHANGED
@@ -7,8 +7,8 @@
|
|
7
7
|
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
8
8
|
<title>%{title}</title>
|
9
9
|
|
10
|
-
<link href="
|
11
|
-
<link href="
|
10
|
+
<link href="styles/markdown4.css" rel="stylesheet">
|
11
|
+
<link href="styles/pygments_github.css" rel="stylesheet">
|
12
12
|
</head>
|
13
13
|
<body>
|
14
14
|
%{content}
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak Kumar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: redcarpet
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 3.4.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 3.4.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: pygments.rb
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|