Skip to content

Commit 2ec1622

Browse files
committed
Merge branch 'feature/structure'
2 parents af71fc6 + 433e0bd commit 2ec1622

File tree

10 files changed

+451
-466
lines changed

10 files changed

+451
-466
lines changed

bin/doxdox

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ while (args.length) {
4848

4949
break;
5050

51-
case '-p':
52-
case '--package':
51+
case '-o':
52+
case '--output':
5353

54-
pkg = args.shift();
54+
output = args.shift();
5555

5656
break;
5757

58-
case '-o':
59-
case '--output':
58+
case '-p':
59+
case '--package':
6060

61-
output = args.shift();
61+
pkg = args.shift();
6262

6363
break;
6464

@@ -98,7 +98,7 @@ while (args.length) {
9898

9999
if (!pkg) {
100100

101-
pkg = utils.findPackage(input);
101+
pkg = utils.findPackagePath(input);
102102

103103
}
104104

@@ -126,7 +126,7 @@ if (!config.title) {
126126

127127
}
128128

129-
doxdox.parseInput(input, config).then(function (content) {
129+
doxdox.parseInput(input, config, pkg).then(function (content) {
130130

131131
if (output) {
132132

lib/doxdox.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ var fs = require('fs'),
66
Promise = require('promise'),
77
utils = require('../lib/utils');
88

9-
var templates = {
9+
module.exports.templates = {
1010
bootstrap: require('../templates/bootstrap.hbs'),
1111
markdown: require('../templates/markdown.hbs'),
1212
dash: utils.buildDashDocSet
1313
};
1414

15-
exports.parseInput = function (input, config) {
15+
module.exports.parseInput = function (input, config, pkg) {
1616

1717
var files = [],
1818
stat;
@@ -26,7 +26,7 @@ exports.parseInput = function (input, config) {
2626
utils.walk(input).forEach(function (file) {
2727

2828
files.push({
29-
name: file.replace(input, '').replace(/^\//, ''),
29+
name: file.replace(input, '').replace(/^[\.\/]{1,2}/, ''),
3030
contents: fs.readFileSync(file, 'utf8')
3131
});
3232

@@ -43,30 +43,33 @@ exports.parseInput = function (input, config) {
4343

4444
} else {
4545

46-
process.stdout.write('File or directory not found.' + '\n');
46+
process.stdout.write('File or directory not found.\n');
4747
process.kill();
4848

4949
}
5050

51-
return exports.parseScripts(files, config);
51+
return exports.parseScripts(files, config, pkg);
5252

5353
};
5454

55-
exports.parseScripts = function (scripts, config) {
55+
module.exports.parseScripts = function (scripts, config, pkg) {
5656

5757
var files = [],
5858
content,
5959
template;
6060

6161
scripts.forEach(function (script) {
6262

63-
var methods = dox.parseComments(script.contents);
63+
var methods = utils.parseData(
64+
dox.parseComments(script.contents, { raw: true }),
65+
script.name
66+
);
6467

65-
if (methods) {
68+
if (methods.length) {
6669

6770
files.push({
6871
name: script.name,
69-
methods: utils.parseData(methods, script.name)
72+
methods: methods
7073
});
7174

7275
}
@@ -77,9 +80,9 @@ exports.parseScripts = function (scripts, config) {
7780

7881
template = require(path.resolve(config.layout));
7982

80-
} else if (templates[config.layout.toLowerCase()]) {
83+
} else if (exports.templates[config.layout.toLowerCase()]) {
8184

82-
template = templates[config.layout.toLowerCase()];
85+
template = exports.templates[config.layout.toLowerCase()];
8386

8487
}
8588

@@ -88,7 +91,8 @@ exports.parseScripts = function (scripts, config) {
8891
content = template({
8992
title: config.title,
9093
description: config.description,
91-
files: files
94+
files: files,
95+
pkg: pkg
9296
});
9397

9498
if (typeof content.then === 'function') {
@@ -103,7 +107,7 @@ exports.parseScripts = function (scripts, config) {
103107

104108
} else {
105109

106-
console.error('Invalid layout specified.' + '\n');
110+
console.error('Invalid layout specified.\n');
107111

108112
}
109113

lib/helpers.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,17 @@
1-
var hljs = require('highlight.js');
1+
var hljs = require('highlight.js'),
2+
marked = require('marked');
23

34
module.exports = function (hbs) {
45

5-
var context;
6-
76
hbs.registerHelper('highlightBlock', function (block) {
87

9-
return hljs.highlightAuto(block, ['javascript']).value;
10-
11-
});
12-
13-
hbs.registerHelper('ifCond', function (a, b, options) {
14-
15-
return a === b ? options.fn(this) : options.inverse(this);
16-
17-
});
18-
19-
hbs.registerHelper('ifCondMatch', function (a, b, options) {
20-
21-
return String(a).match(new RegExp(b, 'i')) ? options.fn(this) : options.inverse(this);
22-
23-
});
24-
25-
hbs.registerHelper('formatName', function (name) {
26-
27-
return String(name).replace(/\.prototype/g, '');
28-
29-
});
30-
31-
hbs.registerHelper('registerContext', function () {
32-
33-
context = this;
8+
return hljs.highlight('javascript', block).value;
349

3510
});
3611

37-
hbs.registerHelper('registerVariable', function (name, value) {
12+
hbs.registerHelper('markdown', function (block) {
3813

39-
context[name] = value;
14+
return marked(block);
4015

4116
});
4217

lib/utils.js

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,24 @@ module.exports.buildDashDocSet = function (input) {
1313

1414
var zip = new admzip(),
1515
tempdb = temp.openSync('temp.sqlite'),
16-
db = new sqlite3.Database(tempdb.path);
16+
db = new sqlite3.Database(tempdb.path),
17+
template = require('../templates/dash/method.hbs');
1718

1819
input.uid = module.exports.formatStringForUID(input.title);
1920

2021
input.files.forEach(function (file) {
2122

2223
file.methods.forEach(function (method) {
2324

24-
if (!method.ignore && method.ctx) {
25-
26-
zip.addFile(
27-
input.title + '.docset/Contents/Resources/Documents/' + method.ctx.uid + '.html',
28-
require('../templates/dash/method.hbs')(method)
29-
);
30-
31-
}
25+
zip.addFile(
26+
input.title + '.docset/Contents/Resources/Documents/' + method.uid + '.html',
27+
template(method)
28+
);
3229

3330
});
3431

3532
});
3633

37-
3834
zip.addFile(
3935
input.title + '.docset/Contents/Info.plist',
4036
require('../templates/dash/plist.hbs')(input)
@@ -61,15 +57,11 @@ module.exports.buildDashDocSet = function (input) {
6157

6258
file.methods.forEach(function (method) {
6359

64-
if (!method.ignore && method.ctx) {
65-
66-
db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', {
67-
$name: hbs.helpers.formatName(method.ctx.string),
68-
$type: method.ctx.type.replace(/^[a-z]/, function (match) { return match.toUpperCase(); }),
69-
$path: method.ctx.uid + '.html'
70-
});
71-
72-
}
60+
db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', {
61+
$name: method.name,
62+
$type: method.type.replace(/^[a-z]/, function (match) { return match.toUpperCase(); }),
63+
$path: method.uid + '.html'
64+
});
7365

7466
});
7567

@@ -92,7 +84,7 @@ module.exports.buildDashDocSet = function (input) {
9284

9385
};
9486

95-
module.exports.findPackage = function (input) {
87+
module.exports.findPackagePath = function (input) {
9688

9789
var pkg,
9890
stat;
@@ -117,6 +109,16 @@ module.exports.findPackage = function (input) {
117109

118110
};
119111

112+
module.exports.formatStringForName = function (content) {
113+
114+
content = String(content);
115+
116+
content = content.replace(/\.prototype/g, '');
117+
118+
return content;
119+
120+
};
121+
120122
module.exports.formatStringForUID = function (content) {
121123

122124
content = String(content).toLowerCase();
@@ -130,31 +132,66 @@ module.exports.formatStringForUID = function (content) {
130132

131133
module.exports.parseData = function (data, file) {
132134

133-
data.forEach(function (method) {
135+
var methods = [];
134136

135-
if (method.ctx) {
137+
data.forEach(function (item) {
136138

137-
method.ctx.uid = file + '-' + module.exports.formatStringForUID(method.ctx.string);
139+
var method = {};
138140

139-
}
141+
if (!item.ignore && item.ctx) {
142+
143+
method.uid = module.exports.formatStringForUID(file + '-' + item.ctx.string);
140144

141-
if (method.tags) {
145+
method.isPrivate = item.isPrivate;
146+
method.type = item.ctx.type;
147+
method.name = module.exports.formatStringForName(item.ctx.string);
142148

143-
method.tags.forEach(function (tag) {
149+
method.description = item.description.summary;
150+
method.body = item.description.body;
144151

145-
if (tag.name && tag.optional) {
152+
method.tags = {};
153+
method.tags.example = [];
146154

147-
tag.name = tag.name.replace(/^\[|\]$/g, '');
155+
item.tags.forEach(function (tag_data) {
156+
157+
var tag = {};
158+
159+
if (method.tags[tag_data.type] === undefined) {
160+
161+
method.tags[tag_data.type] = [];
162+
163+
}
164+
165+
if (tag_data.types && tag_data.types.length) {
166+
167+
if (tag_data.name) {
168+
169+
tag.name = tag_data.name.replace(/^\[|\]$/g, '');
170+
tag.isOptional = tag_data.optional;
171+
172+
}
173+
174+
tag.types = tag_data.types;
175+
176+
tag.description = tag_data.description;
177+
178+
method.tags[tag_data.type].push(tag);
179+
180+
} else if (tag_data.string) {
181+
182+
method.tags[tag_data.type].push(tag_data.string);
148183

149184
}
150185

151186
});
152187

188+
methods.push(method);
189+
153190
}
154191

155192
});
156193

157-
return data;
194+
return methods;
158195

159196
};
160197

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "HTML, Markdown and Dash documentation generator.",
44
"version": "0.0.18",
55
"bin": "./bin/doxdox",
6-
"preferglobal": true,
6+
"preferGlobal": true,
77
"license": "MIT",
88
"dependencies": {
99
"chalk": "0.5.1",
@@ -13,7 +13,8 @@
1313
"promise": "6.0.1",
1414
"sqlite3": "3.0.4",
1515
"adm-zip": "0.4.4",
16-
"temp": "0.8.1"
16+
"temp": "0.8.1",
17+
"marked": "0.3.2"
1718
},
1819
"keywords": [
1920
"documentation",

0 commit comments

Comments
 (0)