Skip to content

Commit 4bb7384

Browse files
committed
Merge branch 'edge'
2 parents 6a1a8c7 + b3a6105 commit 4bb7384

File tree

13 files changed

+324
-75
lines changed

13 files changed

+324
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
templates/bootstrap.min.js

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#Changelog
22

3+
##0.0.5 (August 17, 2014)
4+
5+
- Added support for crawling directories.
6+
- Added support for pulling title and description from package.json files.
7+
- Added "Back to Top" link.
8+
- Minor visual changes.
9+
310
##0.0.4 (August 10, 2014)
411

512
- Improved Node.js support with the addition of a new method: parseFile.

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ $ npm install doxdox -g
1515
##Usage
1616

1717
```bash
18-
Usage: doxdox <file> [options]
18+
Usage: doxdox <path> [options]
1919

2020
Options:
2121

22-
-h, --help Display this help message.
23-
-v, --version Display the current installed version.
24-
-t, --title Sets title.
25-
-d, --description Sets description.
26-
-l, --layout Template to render the documentation with.
27-
-o, --output File to save documentation to. Default to stdout.
22+
-h, --help Display this help message.
23+
-v, --version Display the current installed version.
24+
-t, --title Sets title.
25+
-d, --description Sets description.
26+
-l, --layout Template to render the documentation with.
27+
-p, --package Sets location of package.json file.
28+
-o, --output File to save documentation to. Defaults to stdout.
2829

2930
Available Layouts:
3031

31-
- Bootstrap (default) (http://getbootstrap.com/)
32-
- Markdown (http://daringfireball.net/projects/markdown/)
32+
- Bootstrap (default) (http://getbootstrap.com/)
33+
- Markdown (http://daringfireball.net/projects/markdown/)
3334
```
3435

3536
##Examples:
3637

37-
- [Facade.js Documentation](http://docs.facadejs.com/)
38+
- [Facade.js](http://facadejs.com/) - [Documentation](http://docs.facadejs.com/)
39+
- [plastick.js](https://github.com/syntaxtsb/plastick.js) - [Documentation](http://doxdox.org/syntaxtsb/plastick.js)
40+
- [CanvasToVideo](https://github.com/neogeek/CanvasToVideo) - [Documentation](http://doxdox.org/neogeek/CanvasToVideo)

bin/doxdox

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
#!/usr/bin/env node
22

3-
var pkg = require('../package'),
3+
var fs = require('fs'),
4+
path = require('path'),
45
chalk = require('chalk'),
56
doxdox = require('..');
67

78
var config = {
8-
title: 'Untitled Project',
9+
title: '',
910
description: '',
1011
layout: 'bootstrap'
1112
};
1213

13-
var file = '',
14-
output = '';
14+
var input = process.cwd(),
15+
output,
16+
pkg;
1517

16-
var args = process.argv.slice(2),
17-
value;
18+
var args = process.argv.slice(2);
1819

1920
if (args.length && !args[0].match(/^\-/)) {
2021

21-
file = args.shift();
22+
input = args.shift();
2223

2324
}
2425

2526
while (args.length) {
2627

27-
value = args.shift();
28-
29-
switch (value) {
28+
switch (args.shift()) {
3029

3130
case '-t':
3231
case '--title':
@@ -43,27 +42,33 @@ while (args.length) {
4342
config.layout = args.shift();
4443
break;
4544

45+
case '-p':
46+
case '--package':
47+
pkg = args.shift();
48+
break;
49+
4650
case '-o':
4751
case '--output':
4852
output = args.shift();
4953
break;
5054

5155
case '-v':
5256
case '--version':
53-
process.stdout.write(pkg.version + '\n');
57+
process.stdout.write(require('../package').version + '\n');
5458
process.kill();
5559
break;
5660

5761
default:
5862
process.stdout.write('\n');
59-
process.stdout.write(chalk.blue(' Usage:') + ' doxdox <file> [options]' + '\n\n');
63+
process.stdout.write(chalk.blue(' Usage:') + ' doxdox <path> [options]' + '\n\n');
6064
process.stdout.write(' Options:' + '\n\n');
6165
process.stdout.write(chalk.yellow(' -h, --help') + '\t\tDisplay this help message.' + '\n');
6266
process.stdout.write(chalk.yellow(' -v, --version') + '\t\tDisplay the current installed version.' + '\n');
6367
process.stdout.write(chalk.yellow(' -t, --title') + '\t\tSets title.' + '\n');
6468
process.stdout.write(chalk.yellow(' -d, --description') + '\tSets description.' + '\n');
6569
process.stdout.write(chalk.yellow(' -l, --layout') + '\t\tTemplate to render the documentation with.' + '\n');
66-
process.stdout.write(chalk.yellow(' -o, --output') + '\t\tFile to save documentation to. Default to stdout.' + '\n');
70+
process.stdout.write(chalk.yellow(' -p, --package') + '\tSets location of package.json file.' + '\n');
71+
process.stdout.write(chalk.yellow(' -o, --output') + '\t\tFile to save documentation to. Defaults to stdout.' + '\n');
6772
process.stdout.write('\n');
6873
process.stdout.write(' Available Layouts:' + '\n\n');
6974
process.stdout.write(' - Bootstrap (default)\t (http://getbootstrap.com/)' + '\n');
@@ -76,4 +81,46 @@ while (args.length) {
7681

7782
}
7883

79-
doxdox.parseFile(file, output, config);
84+
var stat;
85+
86+
if (!pkg && fs.existsSync(input)) {
87+
88+
stat = fs.statSync(input);
89+
90+
if (stat.isDirectory()) {
91+
92+
pkg = path.normalize(input + '/package.json');
93+
94+
} else if (stat.isFile()) {
95+
96+
pkg = path.normalize(path.dirname(input) + '/package.json');
97+
98+
}
99+
100+
}
101+
102+
if (fs.existsSync(pkg)) {
103+
104+
pkg = require(pkg);
105+
106+
if (pkg.name && !config.title) {
107+
108+
config.title = pkg.name;
109+
110+
}
111+
112+
if (pkg.description && !config.description) {
113+
114+
config.description = pkg.description;
115+
116+
}
117+
118+
}
119+
120+
if (!config.title) {
121+
122+
config.title = 'Untitled Project';
123+
124+
}
125+
126+
doxdox.parseInput(input, output, config);

lib/doxdox.js

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var fs = require('fs'),
2+
path = require('path'),
23
dox = require('dox'),
34
hbs = require('handlebars'),
45
helpers = require('../lib/helpers')(hbs),
@@ -9,31 +10,72 @@ var templates = {
910
markdown: require('../templates/markdown.hbs')
1011
};
1112

12-
exports.parseFile = function (file, output, config) {
13+
exports.parseInput = function (input, output, config) {
1314

14-
if (fs.existsSync(file)) {
15+
var files = [],
16+
stat;
1517

16-
return exports.parseScript(fs.readFileSync(file, 'utf8'), output, config);
18+
if (fs.existsSync(input)) {
19+
20+
stat = fs.statSync(input);
21+
22+
if (stat.isDirectory()) {
23+
24+
utils.walk(input).forEach(function (file) {
25+
26+
files.push({
27+
name: file.replace(input, '').replace(/^\//, ''),
28+
contents: fs.readFileSync(file, 'utf8')
29+
});
30+
31+
});
32+
33+
} else if (stat.isFile()) {
34+
35+
files.push({
36+
name: path.basename(input),
37+
contents: fs.readFileSync(input, 'utf8')
38+
});
39+
40+
}
1741

1842
} else {
1943

20-
process.stdout.write('File not found.' + '\n');
44+
process.stdout.write('File or directory not found.' + '\n');
45+
process.kill();
2146

2247
}
2348

24-
}
49+
return exports.parseScripts(files, output, config);
2550

26-
exports.parseScript = function (script, output, config) {
51+
};
2752

28-
var content,
29-
data = dox.parseComments(script);
53+
exports.parseScripts = function (scripts, output, config) {
54+
55+
var files = [],
56+
content;
57+
58+
scripts.forEach(function (script) {
59+
60+
var methods = dox.parseComments(script.contents);
61+
62+
if (methods) {
63+
64+
files.push({
65+
name: script.name,
66+
methods: utils.parseData(methods, script.name)
67+
});
68+
69+
}
70+
71+
});
3072

3173
if (templates[config.layout]) {
3274

3375
content = templates[config.layout]({
3476
title: config.title,
3577
description: config.description,
36-
methods: utils.parseData(data)
78+
files: files
3779
});
3880

3981
if (output) {
@@ -44,10 +86,10 @@ exports.parseScript = function (script, output, config) {
4486

4587
process.stdout.write(content);
4688

47-
return content;
48-
4989
}
5090

91+
return content;
92+
5193
} else {
5294

5395
process.stdout.write('Invalid layout specified.' + '\n');

lib/helpers.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ module.exports = function (hbs) {
66
return a === b ? options.fn(this) : options.inverse(this);
77
});
88

9-
hbs.registerHelper('formatId', function (name) {
10-
return String(name).toLowerCase().replace(/[^\w\.]+/g, '');
11-
});
12-
139
hbs.registerHelper('formatName', function (name) {
1410
return String(name).replace(/\.prototype/g, '');
1511
});

lib/utils.js

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
module.exports.parseData = function (data) {
1+
var fs = require('fs'),
2+
path = require('path');
3+
4+
module.exports.formatStringForUID = function (content) {
5+
6+
content = String(content).toLowerCase();
7+
8+
content = content.replace(/[^\w\.]+/g, '-');
9+
content = content.replace(/^-|-$/g, '');
10+
11+
return content;
12+
13+
};
14+
15+
module.exports.parseData = function (data, file) {
216

317
data.forEach(function (methods) {
418

19+
if (methods.ctx) {
20+
21+
methods.ctx.uid = file + '-' + module.exports.formatStringForUID(methods.ctx.string);
22+
23+
}
24+
525
if (methods.tags) {
626

727
methods.tags.forEach(function (tag) {
@@ -30,3 +50,47 @@ module.exports.parseData = function (data) {
3050
return data;
3151

3252
};
53+
54+
module.exports.walk = function (dir, opts) {
55+
56+
var files = [];
57+
58+
if (!opts) {
59+
opts = {};
60+
}
61+
62+
if (!opts.match) {
63+
opts.match = /\.js$/;
64+
}
65+
66+
if (!opts.exception) {
67+
opts.exception = /\.git|\.min|node_modules|test|gruntfile/i;
68+
}
69+
70+
if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
71+
72+
fs.readdirSync(dir).forEach(function (file) {
73+
74+
var stat;
75+
76+
file = path.normalize(dir + '/' + file);
77+
78+
stat = fs.statSync(file);
79+
80+
if (stat.isDirectory() && !file.match(opts.exception)) {
81+
82+
files = files.concat(module.exports.walk(file, opts));
83+
84+
} else if (stat.isFile() && file.match(opts.match) && !file.match(opts.exception)) {
85+
86+
files.push(file);
87+
88+
}
89+
90+
});
91+
92+
}
93+
94+
return files;
95+
96+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "doxdox",
33
"description": "HTML and Markdown documentation generator.",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"bin": "./bin/doxdox",
66
"license": "MIT",
77
"dependencies": {

0 commit comments

Comments
 (0)