mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-18 14:17:30 +00:00
* feat(core): Switch to Promises everywhere. Adopt Node v4 ES6 Big changes: * Uses template strings where appropriate * Config and argument parsing is unified and there is no such thing as formatterOptions anymore. All user-passed options go through mergeConfig. * The node API surface changed (again): `buildSync` is removed, building operations return Promises. * Now using Flow for internal type annotations. More changes: * Remove buildSync command * feat(inference): Partially implement object shorthand support * Refs #649 * Use Flow annotations to enforce types * Keep flow but switch to comment syntax * Clarify types * More flow improvements * Turn server into class * LinkerStack becomes class too * Fix comment description type * Run flow on lint * Many more flow fixes * More intense flow refactoring * Simplify inference steps * Update inference tests, flow errors down to 1 * Continue refining types * Fix more flow issues * Use 'use strict' everywhere * Make 'ast' property configurable * Fix many tests * Fix more tests * Fix more tests * Fix augments * Test Markdown meta support * Improve test coverage * Switch back from for of to for for speed
95 lines
3.1 KiB
JavaScript
95 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
var fs = require('fs'),
|
|
path = require('path'),
|
|
File = require('vinyl'),
|
|
vfs = require('vinyl-fs'),
|
|
_ = require('lodash'),
|
|
concat = require('concat-stream'),
|
|
GithubSlugger = require('github-slugger'),
|
|
createFormatters = require('../').util.createFormatters,
|
|
LinkerStack = require('../').util.LinkerStack,
|
|
hljs = require('highlight.js');
|
|
|
|
module.exports = function (comments/*: Array<Comment> */, config/*: DocumentationConfig */) {
|
|
|
|
var linkerStack = new LinkerStack(config)
|
|
.namespaceResolver(comments, function (namespace) {
|
|
var slugger = new GithubSlugger();
|
|
return '#' + slugger.slug(namespace);
|
|
});
|
|
|
|
var formatters = createFormatters(linkerStack.link);
|
|
|
|
hljs.configure(config.hljs || {});
|
|
|
|
var sharedImports = {
|
|
imports: {
|
|
slug(str) {
|
|
var slugger = new GithubSlugger();
|
|
return slugger.slug(str);
|
|
},
|
|
shortSignature(section) {
|
|
var prefix = '';
|
|
if (section.kind === 'class') {
|
|
prefix = 'new ';
|
|
} else if (section.kind !== 'function') {
|
|
return section.name;
|
|
}
|
|
return prefix + section.name + formatters.parameters(section, true);
|
|
},
|
|
signature(section) {
|
|
var returns = '';
|
|
var prefix = '';
|
|
if (section.kind === 'class') {
|
|
prefix = 'new ';
|
|
} else if (section.kind !== 'function') {
|
|
return section.name;
|
|
}
|
|
if (section.returns.length) {
|
|
returns = ': ' +
|
|
formatters.type(section.returns[0].type);
|
|
}
|
|
return prefix + section.name + formatters.parameters(section) + returns;
|
|
},
|
|
md(ast, inline) {
|
|
if (inline && ast && ast.children.length && ast.children[0].type === 'paragraph') {
|
|
ast = {
|
|
type: 'root',
|
|
children: ast.children[0].children.concat(ast.children.slice(1))
|
|
};
|
|
}
|
|
return formatters.markdown(ast);
|
|
},
|
|
formatType: formatters.type,
|
|
autolink: formatters.autolink,
|
|
highlight(example) {
|
|
if (config.hljs && config.hljs.highlightAuto) {
|
|
return hljs.highlightAuto(example).value;
|
|
}
|
|
return hljs.highlight('js', example).value;
|
|
}
|
|
}
|
|
};
|
|
|
|
sharedImports.imports.renderSectionList = _.template(fs.readFileSync(path.join(__dirname, 'section_list._'), 'utf8'), sharedImports);
|
|
sharedImports.imports.renderSection = _.template(fs.readFileSync(path.join(__dirname, 'section._'), 'utf8'), sharedImports);
|
|
sharedImports.imports.renderNote = _.template(fs.readFileSync(path.join(__dirname, 'note._'), 'utf8'), sharedImports);
|
|
|
|
var pageTemplate = _.template(fs.readFileSync(path.join(__dirname, 'index._'), 'utf8'), sharedImports);
|
|
|
|
// push assets into the pipeline as well.
|
|
return new Promise(resolve => {
|
|
vfs.src([__dirname + '/assets/**'], { base: __dirname })
|
|
.pipe(concat(function (files) {
|
|
resolve(files.concat(new File({
|
|
path: 'index.html',
|
|
contents: new Buffer(pageTemplate({
|
|
docs: comments,
|
|
config: config
|
|
}), 'utf8')
|
|
})));
|
|
}));
|
|
});
|
|
};
|