diff --git a/index.js b/index.js index 529437e..ad13783 100644 --- a/index.js +++ b/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)])); */ }; diff --git a/streams/filter_access.js b/streams/filter_access.js index 2e64d2d..b129023 100644 --- a/streams/filter_access.js +++ b/streams/filter_access.js @@ -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} [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; }; diff --git a/streams/infer/membership.js b/streams/infer/membership.js index 2edd7de..7874020 100644 --- a/streams/infer/membership.js +++ b/streams/infer/membership.js @@ -88,7 +88,7 @@ function inferMembership(comment) { } if (comment.lends) { - return callback(); + return comment; } var path = comment.context.ast; diff --git a/streams/nest_params.js b/streams/nest_params.js index 4f253f8..6efeeb5 100644 --- a/streams/nest_params.js +++ b/streams/nest_params.js @@ -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; }; diff --git a/streams/sort.js b/streams/sort.js index f8a9f73..490ff06 100644 --- a/streams/sort.js +++ b/streams/sort.js @@ -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} 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)); }; diff --git a/test/test.js b/test/test.js index 4184651..0509ab0 100644 --- a/test/test.js +++ b/test/test.js @@ -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) {