Skip to content

Commit 61bea12

Browse files
committed
Added doxdox with bootstrap template.
1 parent 38250ad commit 61bea12

File tree

4 files changed

+325
-1
lines changed

4 files changed

+325
-1
lines changed

bin/doxdox

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env node
2+
3+
var pkg = require('../package'),
4+
fs = require('fs'),
5+
hbs = require('handlebars'),
6+
helpers = require('../lib/helpers')(hbs);
7+
8+
var templates = {
9+
bootstrap: require('../templates/bootstrap.hbs')
10+
};
11+
12+
var title = 'Untitled Project',
13+
description = '';
14+
15+
var args = process.argv.slice(2),
16+
value;
17+
18+
var filename;
19+
20+
while (args.length) {
21+
22+
value = args.shift();
23+
24+
switch (value) {
25+
26+
case '-t':
27+
case '--title':
28+
title = args.shift();
29+
break;
30+
31+
case '-d':
32+
case '--description':
33+
description = args.shift();
34+
break;
35+
36+
case '-v':
37+
case '--version':
38+
process.stdout.write(pkg.version + '\n');
39+
break;
40+
41+
default:
42+
filename = value;
43+
break;
44+
45+
}
46+
47+
}
48+
49+
if (filename) {
50+
51+
fs.readFile(filename, 'utf8', function (error, data) {
52+
53+
if (!error) {
54+
55+
data = JSON.parse(data);
56+
57+
data.forEach(function (methods) {
58+
59+
if (methods.tags) {
60+
61+
methods.tags.forEach(function (tag) {
62+
63+
if (tag.types) {
64+
65+
tag.types.forEach(function (type, index) {
66+
67+
if (type.match(/\?/g)) {
68+
69+
tag.optional = true;
70+
tag.types[index] = type.replace(/\?/g, '');
71+
72+
}
73+
74+
});
75+
76+
}
77+
78+
});
79+
80+
}
81+
82+
});
83+
84+
process.stdout.write(templates.bootstrap({
85+
title: title,
86+
description: description,
87+
methods: data
88+
}));
89+
90+
}
91+
92+
});
93+
94+
}

lib/helpers.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function (hbs) {
2+
3+
hbs.registerHelper('ifCond', function (a, b, options) {
4+
return a === b ? options.fn(this) : options.inverse(this);
5+
});
6+
7+
hbs.registerHelper('formatId', function (name) {
8+
return String(name).toLowerCase().replace(/[^\w\.]+/g, '');
9+
});
10+
11+
hbs.registerHelper('formatName', function (name) {
12+
return String(name).replace(/\.prototype/g, '');
13+
});
14+
15+
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"name": "doxdox",
33
"description": "HTML and Markdown documentation generator.",
44
"version": "0.0.1",
5+
"bin": "./bin/doxdox",
56
"license": "MIT",
67
"dependencies": {
7-
"dox": "0.4.6"
8+
"dox": "0.4.6",
9+
"handlebars": "1.3.0"
810
},
911
"keywords": [
1012
"documentation",

templates/bootstrap.hbs

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="initial-scale=1">
6+
<title>{{title}}{{#if description}} - {{description}}{{/if}}</title>
7+
<style>
8+
9+
.method h2 {
10+
text-overflow: ellipsis;
11+
overflow: hidden;
12+
}
13+
14+
.permalink {
15+
position: absolute;
16+
margin-left: -25px;
17+
font-weight: normal;
18+
color: #eee;
19+
}
20+
21+
.permalink:hover {
22+
color: #666;
23+
text-decoration: none;
24+
}
25+
26+
.bs-footer {
27+
margin: 50px auto;
28+
color: #777;
29+
text-align: center;
30+
}
31+
32+
</style>
33+
<script>
34+
35+
(function () {
36+
37+
'use strict';
38+
39+
var css = document.createElement('link'),
40+
protocol = window.location.protocol;
41+
42+
if (protocol === 'file:') {
43+
protocol = 'http:';
44+
}
45+
46+
css.setAttribute('rel', 'stylesheet');
47+
css.setAttribute('href', protocol + '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css');
48+
49+
document.head.appendChild(css);
50+
51+
}());
52+
53+
</script>
54+
</head>
55+
56+
<body>
57+
58+
<div class="wrap">
59+
60+
<div class="container">
61+
62+
<div class="page-header">
63+
64+
<h1>{{title}}{{#if description}} <small>{{description}}</small>{{/if}}</h1>
65+
66+
</div>
67+
68+
<div class="row">
69+
70+
<div class="col-md-3 hidden-sm hidden-xs">
71+
72+
<ul class="nav">
73+
74+
{{#each methods}}
75+
76+
{{#unless ignore}}
77+
78+
{{#if ctx}}
79+
80+
<li><a href="#{{formatId ctx.string}}">{{formatName ctx.string}}</a></li>
81+
82+
{{/if}}
83+
84+
{{/unless}}
85+
86+
{{/each}}
87+
88+
</ul>
89+
90+
</div>
91+
92+
<div class="col-md-9">
93+
94+
{{#each methods}}
95+
96+
<div class="method">
97+
98+
{{#unless ignore}}
99+
100+
{{#if ctx}}
101+
102+
<h2 id="{{formatId ctx.string}}">
103+
<a href="#{{formatId ctx.string}}" class="permalink">#</a> {{formatName ctx.string}}
104+
</h2>
105+
106+
{{{description.summary}}}
107+
108+
<section class="parameters">
109+
110+
<h3>Parameters</h3>
111+
112+
{{#each tags}}
113+
114+
{{#ifCond type "param"}}
115+
116+
<p>
117+
<b>{{name}}</b>
118+
{{#each types}}
119+
<code>{{.}}</code>
120+
{{/each}}
121+
{{#if optional}}
122+
<span class="label label-default">Optional</span>
123+
{{/if}}
124+
</p>
125+
<p>{{{description}}}</p>
126+
127+
{{/ifCond}}
128+
129+
{{/each}}
130+
131+
</section>
132+
133+
<section class="properties">
134+
135+
<h3>Properties</h3>
136+
137+
{{#each tags}}
138+
139+
{{#ifCond type "property"}}
140+
141+
<p>
142+
<b>{{name}}</b>
143+
{{#each types}}
144+
<code>{{.}}</code>
145+
{{/each}}
146+
{{#if optional}}
147+
<span class="label label-default">Optional</span>
148+
{{/if}}
149+
</p>
150+
<p>{{{description}}}</p>
151+
152+
{{/ifCond}}
153+
154+
{{/each}}
155+
156+
</section>
157+
158+
<section class="examples">
159+
160+
<h3>Examples</h3>
161+
162+
{{{description.body}}}
163+
164+
</section>
165+
166+
<section class="code">
167+
168+
<h3>Code</h3>
169+
170+
<pre>{{code}}</pre>
171+
172+
</section>
173+
174+
<h3>Returns</h3>
175+
176+
{{#each tags}}
177+
178+
{{#ifCond type "return"}}
179+
180+
<p>{{#each types}}<code>{{.}}</code> {{/each}} {{{description}}}</p>
181+
182+
{{/ifCond}}
183+
184+
{{/each}}
185+
186+
{{/if}}
187+
188+
{{/unless}}
189+
190+
</div>
191+
192+
{{/each}}
193+
194+
</div>
195+
196+
</div>
197+
198+
</div>
199+
200+
</div>
201+
202+
<footer class="bs-footer">
203+
204+
<div class="container">
205+
206+
<p>Documentation generated with <a href="https://github.com/neogeek/doxdox">doxdox</a>.</p>
207+
208+
</div>
209+
210+
</footer>
211+
212+
</body>
213+
</html>

0 commit comments

Comments
 (0)