Skip to content

Commit ac5b041

Browse files
committed
Improve internal documentation, upgrade theme-default. Refs #115
1 parent 7ee83b6 commit ac5b041

File tree

12 files changed

+381
-827
lines changed

12 files changed

+381
-827
lines changed

lib/args.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = function (args) {
7878

7979
var inputs,
8080
name = argv.name,
81-
version = argv.version,
81+
version = argv['project-version'],
8282
transform;
8383

8484
if (argv._.length > 0) {
@@ -88,7 +88,7 @@ module.exports = function (args) {
8888
var p = require(path.resolve('package.json'));
8989
inputs = [p.main || 'index.js'];
9090
name = name || p.name;
91-
version = version || p['project-version'];
91+
version = version || p.version;
9292
if (p.browserify && p.browserify.transform) {
9393
transform = p.browserify.transform;
9494
}

lib/filter_access.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ var walk = require('./walk');
77
* users to write documentation for non-public members by using the
88
* `@private` tag.
99
*
10-
* @name access
1110
* @public
1211
* @param {Array<string>} [levels=['private']] excluded access levels.
1312
* @param {Array<Object>} comments parsed comments (can be nested)
1413
* @return {Array<Object>} filtered comments
1514
*/
16-
module.exports = function (levels, comments) {
15+
function filterAccess(levels, comments) {
1716
levels = levels || ['private'];
1817

1918
function filter(comment) {
@@ -27,4 +26,6 @@ module.exports = function (levels, comments) {
2726
}
2827

2928
return walk(comments.filter(filter), recurse);
30-
};
29+
}
30+
31+
module.exports = filterAccess;

lib/filter_js.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
* with JSDoc or parsed with espree, so we filter them out before
66
* they reach documentation's machinery.
77
*
8-
* @name access
98
* @public
109
* @param {Object} data a file as an object with 'file' property
1110
* @return {boolean} whether the file is json
1211
*/
13-
module.exports = function (data) {
12+
function filterJS(data) {
1413
return !data.file.match(/\.json$/);
15-
};
14+
}
15+
16+
module.exports = filterJS;

lib/get_template.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ var path = require('path');
1212
* @param {string} name template name
1313
* @returns {Function} template function
1414
*/
15-
module.exports = function getTemplate(Handlebars, themeModule, name) {
15+
function getTemplate(Handlebars, themeModule, name) {
1616
try {
1717
return Handlebars
1818
.compile(fs.readFileSync(path.join(themeModule, name), 'utf8'));
1919
} catch (e) {
2020
throw new Error('Template file ' + name + ' missing');
2121
}
22-
};
22+
}
23+
24+
module.exports = getTemplate;

lib/html_helpers.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
'use strict';
22

3-
var slugg = require('slugg'),
4-
getGlobalExternalLink = require('globals-docs').getDoc,
3+
var getGlobalExternalLink = require('globals-docs').getDoc,
54
mdast = require('mdast'),
65
html = require('mdast-html'),
76
inlineLex = require('jsdoc-inline-lex');
87

9-
/**
10-
* Make slugg a unary so we can use it in functions
11-
*
12-
* @private
13-
* @param {string} input text
14-
* @returns {string} output
15-
*/
16-
function slug(input) {
17-
return input ? slugg(input) : '';
18-
}
19-
208
/**
219
* Format a description and target as a Markdown link.
2210
*
@@ -47,12 +35,12 @@ function formatInlineTags(text) {
4735
} else if (tokens[i].type === 'link') {
4836
var parts = tokens[i].capture[1].split(/\s|\|/);
4937
if (parts.length === 1) {
50-
output += markdownLink(tokens[i].capture[1], slug(tokens[i].capture[1]));
38+
output += markdownLink(tokens[i].capture[1], tokens[i].capture[1]);
5139
} else {
52-
output += markdownLink(parts.slice(1).join(' '), slug(parts[0]));
40+
output += markdownLink(parts.slice(1).join(' '), parts[0]);
5341
}
5442
} else if (tokens[i].type === 'prefixLink') {
55-
output += markdownLink(tokens[i].capture[1], slug(tokens[i].capture[2]));
43+
output += markdownLink(tokens[i].capture[1], tokens[i].capture[2]);
5644
}
5745
}
5846

@@ -66,8 +54,8 @@ function formatInlineTags(text) {
6654
* @returns {string} potentially linked HTML
6755
*/
6856
function autolink(paths, text) {
69-
if (paths.indexOf(slug(text)) !== -1) {
70-
return '<a href="#' + slug(text) + '">' + text + '</a>';
57+
if (paths.indexOf(text) !== -1) {
58+
return '<a href="#' + text + '">' + text + '</a>';
7159
} else if (getGlobalExternalLink(text)) {
7260
return '<a href="' + getGlobalExternalLink(text) + '">' + text + '</a>';
7361
}
@@ -147,9 +135,9 @@ function formatParameters() {
147135
* @param {Array<string>} paths list of valid namespace paths that are linkable
148136
* @returns {undefined} invokes side effects on Handlebars
149137
*/
150-
module.exports = function (Handlebars, paths) {
138+
function htmlHelpers(Handlebars, paths) {
151139
Handlebars.registerHelper('permalink', function () {
152-
return this.path.map(slug).join('/');
140+
return this.path.join('.');
153141
});
154142

155143
Handlebars.registerHelper('autolink', autolink.bind(autolink, paths));
@@ -176,4 +164,6 @@ module.exports = function (Handlebars, paths) {
176164
Handlebars.registerHelper('format_type', function (type) {
177165
return formatType(type, paths);
178166
});
179-
};
167+
}
168+
169+
module.exports = htmlHelpers;

lib/output/html.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,12 @@ var File = require('vinyl'),
55
concat = require('concat-stream'),
66
Handlebars = require('handlebars'),
77
extend = require('extend'),
8-
slugg = require('slugg'),
98
walk = require('../walk'),
109
getTemplate = require('../get_template'),
1110
resolveTheme = require('../resolve_theme'),
1211
helpers = require('../html_helpers'),
1312
hljs = require('highlight.js');
1413

15-
/**
16-
* Make slugg a unary so we can use it in functions
17-
*
18-
* @private
19-
* @param {string} input text
20-
* @returns {string} output
21-
*/
22-
function slug(input) {
23-
return input ? slugg(input) : '';
24-
}
25-
2614
/**
2715
* Given a string of JavaScript, return a string of HTML representing
2816
* that JavaScript highlighted.
@@ -70,11 +58,10 @@ module.exports = function makeHTML(comments, opts, callback) {
7058

7159
var pageTemplate = getTemplate(Handlebars, themeModule, 'index.hbs');
7260
Handlebars.registerPartial('section',
73-
74-
getTemplate(Handlebars, themeModule, 'section.hbs'));
61+
getTemplate(Handlebars, themeModule, 'section.hbs'));
7562

7663
var paths = comments.map(function (comment) {
77-
return comment.path.map(slug).join('/');
64+
return comment.path.join('.');
7865
}).filter(function (path) {
7966
return path;
8067
});

lib/parse.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var doctrine = require('doctrine'),
1515
* @return {Object} an object conforming to the
1616
* [documentation JSON API](https://github.com/documentationjs/api-json) schema
1717
*/
18-
module.exports = function (comment, loc, context) {
18+
function parseJSDoc(comment, loc, context) {
1919
var result = doctrine.parse(comment, {
2020
// have doctrine itself remove the comment asterisks from content
2121
unwrap: true,
@@ -45,4 +45,6 @@ module.exports = function (comment, loc, context) {
4545
}
4646

4747
return flatten(normalize(result));
48-
};
48+
}
49+
50+
module.exports = parseJSDoc;

lib/parsers/javascript.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,21 @@ var babel = require('babel-core'),
66
isJSDocComment = require('../../lib/is_jsdoc_comment'),
77
parse = require('../../lib/parse');
88

9-
/**
10-
* Comment-out a shebang line that may sit at the top of a file,
11-
* making it executable on linux-like systems.
12-
* @param {string} code the source code in full
13-
* @return {string} code
14-
* @example
15-
* var foo = commentShebang('#!/usr/bin/env/node');
16-
* foo === '//#!/usr/bin/env/node';
17-
*/
18-
function commentShebang(code) {
19-
return (code[0] === '#' && code[1] === '!') ? '//' + code : code;
20-
}
21-
22-
var parseOpts = {
23-
code: false,
24-
stage: 0,
25-
locations: true,
26-
ranges: true
27-
};
28-
299
/**
3010
* Receives a module-dep item,
3111
* reads the file, parses the JavaScript, and parses the JSDoc.
3212
*
33-
* @name parse
3413
* @param {Object} data a chunk of data provided by module-deps
3514
* @return {Array<Object>} an array of parsed comments
3615
*/
37-
module.exports = function (data) {
16+
function parseJavaScript(data) {
3817
var results = [];
39-
var code = commentShebang(data.source),
40-
ast = babel.parse(code, parseOpts);
18+
var ast = babel.parse(data.source, {
19+
code: false,
20+
stage: 0,
21+
locations: true,
22+
ranges: true
23+
});
4124

4225
var visited = {};
4326

@@ -69,8 +52,8 @@ module.exports = function (data) {
6952
});
7053

7154
if (path.parent && path.parent.node) {
72-
context.code = code.substring
73-
.apply(code, path.parent.node.range);
55+
context.code = data.source.substring
56+
.apply(data.source, path.parent.node.range);
7457
}
7558
} else {
7659
// Avoid the invariant of a comment with no AST by providing
@@ -98,4 +81,6 @@ module.exports = function (data) {
9881
walkComments(ast, 'trailingComments', false);
9982

10083
return results;
101-
};
84+
}
85+
86+
module.exports = parseJavaScript;

lib/parsers/polyglot.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ var getComments = require('get-comments'),
99
* Documentation stream parser: this receives a module-dep item,
1010
* reads the file, parses the JavaScript, parses the JSDoc, and
1111
* emits parsed comments.
12-
* @name parse
1312
* @param {Object} data a chunk of data provided by module-deps
1413
* @return {Array<Object>} adds to memo
1514
*/
16-
module.exports = function (data) {
15+
function parsePolyglot(data) {
1716
return getComments(data.source, true)
1817
.filter(isJSDocComment)
1918
.map(function (comment) {
@@ -23,4 +22,6 @@ module.exports = function (data) {
2322
};
2423
return parse(comment.value, comment.loc, context);
2524
});
26-
};
25+
}
26+
27+
module.exports = parsePolyglot;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"brfs": "^1.4.0",
2222
"concat-stream": "^1.5.0",
2323
"doctrine": "^0.7.0",
24-
"documentation-theme-default": "^1.0.0-alpha2",
24+
"documentation-theme-default": "^1.0.0",
2525
"extend": "^3.0.0",
2626
"get-comments": "^1.0.1",
2727
"github-url-from-git": "^1.4.0",

0 commit comments

Comments
 (0)