mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-18 14:17:30 +00:00
Port nestParams, sort, filterAccess
This commit is contained in:
parent
56bdd39066
commit
b3e71f0cee
8
index.js
8
index.js
@ -2,7 +2,6 @@
|
||||
|
||||
var splicer = require('stream-splicer'),
|
||||
sort = require('./streams/sort'),
|
||||
concat = require('concat-stream'),
|
||||
unstream = require('unstream'),
|
||||
nestParams = require('./streams/nest_params'),
|
||||
filterAccess = require('./streams/filter_access'),
|
||||
@ -55,14 +54,15 @@ module.exports = function (indexes, options) {
|
||||
.reduce(parse, [])
|
||||
.map(inferName)
|
||||
.map(inferKind)
|
||||
.map(inferMembership));
|
||||
.map(inferMembership)
|
||||
.map(nestParams)
|
||||
.sort(sort.bind(undefined, options.order))
|
||||
.filter(filterAccess.bind(undefined, options.private ? [] : undefined)));
|
||||
}));
|
||||
/*
|
||||
|
||||
return splicer.obj(
|
||||
inputStream.concat([
|
||||
sort(options.order),
|
||||
nestParams(),
|
||||
filterAccess(options.private ? [] : undefined)]));
|
||||
*/
|
||||
};
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var filter = require('through2-filter');
|
||||
|
||||
/**
|
||||
* Exclude given access levels from the generated documentation: this allows
|
||||
* users to write documentation for non-public members by using the
|
||||
@ -12,9 +10,7 @@ var filter = require('through2-filter');
|
||||
* @param {Array<String>} [levels=[private]] excluded access levels.
|
||||
* @return {stream.Transform}
|
||||
*/
|
||||
module.exports = function (levels) {
|
||||
module.exports = function (levels, comment) {
|
||||
levels = levels || ['private'];
|
||||
return filter.obj(function (comment) {
|
||||
return levels.indexOf(comment.access) === -1;
|
||||
});
|
||||
return levels.indexOf(comment.access) === -1;
|
||||
};
|
||||
|
||||
@ -88,7 +88,7 @@ function inferMembership(comment) {
|
||||
}
|
||||
|
||||
if (comment.lends) {
|
||||
return callback();
|
||||
return comment;
|
||||
}
|
||||
|
||||
var path = comment.context.ast;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var through2 = require('through2'),
|
||||
extend = require('extend');
|
||||
var extend = require('extend');
|
||||
|
||||
/**
|
||||
* Create a transform stream that nests
|
||||
@ -15,36 +14,34 @@ var through2 = require('through2'),
|
||||
* @name nestParams
|
||||
* @return {stream.Transform}
|
||||
*/
|
||||
module.exports = function () {
|
||||
return through2.obj(function (comment, enc, callback) {
|
||||
if (!comment.params) {
|
||||
return callback(null, comment);
|
||||
}
|
||||
module.exports = function (comment) {
|
||||
if (!comment.params) {
|
||||
return comment;
|
||||
}
|
||||
|
||||
var result = extend({}, comment),
|
||||
index = {};
|
||||
var result = extend({}, comment),
|
||||
index = {};
|
||||
|
||||
result.params = [];
|
||||
comment.params.forEach(function (param) {
|
||||
index[param.name] = param;
|
||||
var parts = param.name.split(/(\[\])?\./);
|
||||
if (parts.length > 1) {
|
||||
var parent = index[parts[0]];
|
||||
if (parent === undefined) {
|
||||
console.error(
|
||||
'@param %s\'s parent %s not found',
|
||||
param.name,
|
||||
parts[0]);
|
||||
result.params.push(param);
|
||||
return;
|
||||
}
|
||||
parent.properties = parent.properties || [];
|
||||
parent.properties.push(param);
|
||||
} else {
|
||||
result.params = [];
|
||||
comment.params.forEach(function (param) {
|
||||
index[param.name] = param;
|
||||
var parts = param.name.split(/(\[\])?\./);
|
||||
if (parts.length > 1) {
|
||||
var parent = index[parts[0]];
|
||||
if (parent === undefined) {
|
||||
console.error(
|
||||
'@param %s\'s parent %s not found',
|
||||
param.name,
|
||||
parts[0]);
|
||||
result.params.push(param);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
callback(null, result);
|
||||
parent.properties = parent.properties || [];
|
||||
parent.properties.push(param);
|
||||
} else {
|
||||
result.params.push(param);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var sort = require('sort-stream');
|
||||
|
||||
/**
|
||||
* Given a comment, get its sorting key: this is either the comment's
|
||||
* name tag, or a hardcoded sorting index given by a user-provided
|
||||
@ -32,7 +30,7 @@ function getSortKey(comment, order) {
|
||||
* @return {number} sorting value
|
||||
* @private
|
||||
*/
|
||||
function sortDocs(order, a, b) {
|
||||
module.exports = function sortDocs(order, a, b) {
|
||||
a = getSortKey(a, order);
|
||||
b = getSortKey(b, order);
|
||||
|
||||
@ -47,17 +45,4 @@ function sortDocs(order, a, b) {
|
||||
}
|
||||
|
||||
return a.localeCompare(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a stream.Transform that sorts its input of comments
|
||||
* by the name tag, if any, and otherwise by filename.
|
||||
*
|
||||
* @name sort
|
||||
* @param {Array<string>} order an array of namepaths that will be sorted
|
||||
* in the order given.
|
||||
* @return {stream.Transform} a transform stream
|
||||
*/
|
||||
module.exports = function (order) {
|
||||
return sort(sortDocs.bind(undefined, order));
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tap').test,
|
||||
var test = require('tape'),
|
||||
documentation = require('../'),
|
||||
markdown = require('../streams/output/markdown.js'),
|
||||
outputHtml = require('../streams/output/html.js'),
|
||||
@ -36,7 +36,6 @@ test('external modules option', function (t) {
|
||||
}));
|
||||
});
|
||||
|
||||
/*
|
||||
test('parse', function (tt) {
|
||||
glob.sync(path.join(__dirname, 'fixture', '*.input.js')).forEach(function (file) {
|
||||
tt.test(path.basename(file), function (t) {
|
||||
@ -55,6 +54,7 @@ test('parse', function (tt) {
|
||||
tt.end();
|
||||
});
|
||||
|
||||
/*
|
||||
test('formats', function (tt) {
|
||||
glob.sync(path.join(__dirname, 'fixture', '*.input.js')).forEach(function (file) {
|
||||
tt.test('json', function (ttt) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user