Skip to content

Commit 989881c

Browse files
committed
Added dox comment parsing.
Added data parsing utilities.
1 parent 3cb7732 commit 989881c

File tree

2 files changed

+53
-42
lines changed

2 files changed

+53
-42
lines changed

bin/doxdox

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
var pkg = require('../package'),
44
fs = require('fs'),
5+
dox = require('dox'),
56
hbs = require('handlebars'),
6-
helpers = require('../lib/helpers')(hbs);
7+
helpers = require('../lib/helpers')(hbs),
8+
utils = require('../lib/utils');
79

810
var templates = {
911
bootstrap: require('../templates/bootstrap.hbs'),
1012
markdown: require('../templates/markdown.hbs')
1113
};
1214

1315
var title = 'Untitled Project',
14-
description = '';
16+
description = '',
17+
layout = 'bootstrap';
1518

1619
var args = process.argv.slice(2),
1720
value;
@@ -34,6 +37,11 @@ while (args.length) {
3437
description = args.shift();
3538
break;
3639

40+
case '-l':
41+
case '--layout':
42+
layout = args.shift();
43+
break;
44+
3745
case '-v':
3846
case '--version':
3947
process.stdout.write(pkg.version + '\n');
@@ -47,49 +55,20 @@ while (args.length) {
4755

4856
}
4957

50-
if (filename) {
51-
52-
fs.readFile(filename, 'utf8', function (error, data) {
53-
54-
if (!error) {
55-
56-
data = JSON.parse(data);
57-
58-
data.forEach(function (methods) {
59-
60-
if (methods.tags) {
61-
62-
methods.tags.forEach(function (tag) {
63-
64-
if (tag.types) {
58+
fs.exists(filename, function (exists) {
6559

66-
tag.types.forEach(function (type, index) {
60+
var data;
6761

68-
if (type.match(/\?/g)) {
62+
if (exists) {
6963

70-
tag.optional = true;
71-
tag.types[index] = type.replace(/\?/g, '');
64+
data = dox.parseComments(fs.readFileSync(filename, 'utf8'));
7265

73-
}
66+
process.stdout.write(templates[layout]({
67+
title: title,
68+
description: description,
69+
methods: utils.parseData(data)
70+
}));
7471

75-
});
76-
77-
}
78-
79-
});
80-
81-
}
82-
83-
});
84-
85-
process.stdout.write(templates.bootstrap({
86-
title: title,
87-
description: description,
88-
methods: data
89-
}));
90-
91-
}
92-
93-
});
72+
}
9473

95-
}
74+
});

lib/utils.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
exports.parseData = function (data) {
2+
3+
data.forEach(function (methods) {
4+
5+
if (methods.tags) {
6+
7+
methods.tags.forEach(function (tag) {
8+
9+
if (tag.types) {
10+
11+
tag.types.forEach(function (type, index) {
12+
13+
if (type.match(/\?/g)) {
14+
15+
tag.optional = true;
16+
tag.types[index] = type.replace(/\?/g, '');
17+
18+
}
19+
20+
});
21+
22+
}
23+
24+
});
25+
26+
}
27+
28+
});
29+
30+
return data;
31+
32+
};

0 commit comments

Comments
 (0)