Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 6fd0191

Browse files
authored
Allow filtering by tag (pull request #91 from omaretna)
If you don't want to generate the doc for all the things you can filter by tag: apidoc --filter-by apigroup=User
2 parents e8d55c8 + a6e49dd commit 6fd0191

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/parser.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var ParameterError = require('./errors/parameter_error');
1010
var ParserError = require('./errors/parser_error');
1111

1212
var app = {};
13+
var filterTag = null; // define the tag to filter by
1314

1415
function Parser(_app) {
1516
var self = this;
@@ -49,6 +50,12 @@ function Parser(_app) {
4950
self.addParser(parser, require(filename));
5051
}
5152
});
53+
54+
// check app.options.filterBy and define the tag to filter by
55+
if (app.options.filterBy) {
56+
var tag = app.options.filterBy.split('=')[0];
57+
filterTag = (tag.indexOf('api') !== -1) ? tag : null;
58+
}
5259
}
5360

5461
/**
@@ -410,8 +417,12 @@ Parser.prototype._findBlocks = function() {
410417
*/
411418
Parser.prototype._findBlockWithApiGetIndex = function(blocks) {
412419
var foundIndexes = [];
420+
// get value to filter by
421+
var valueTofilter = (filterTag) ? app.options.filterBy.split('=')[1] : null;
413422
for (var i = 0; i < blocks.length; i += 1) {
414423
var found = false;
424+
var isToFilterBy = false;
425+
var isDefine = false;
415426
for (var j = 0; j < blocks[i].length; j += 1) {
416427
// check apiIgnore
417428
if (blocks[i][j].name.substr(0, 9) === 'apiignore') {
@@ -427,9 +438,26 @@ Parser.prototype._findBlockWithApiGetIndex = function(blocks) {
427438
break;
428439
}
429440

441+
// check if the user want to filter by some specific tag
442+
if (filterTag) {
443+
// we need to add all apidefine
444+
if (blocks[i][j].name.substr(0, 9) === 'apidefine') {
445+
isDefine = true;
446+
}
447+
if (blocks[i][j].name.substr(0, filterTag.length) === filterTag && blocks[i][j].content === valueTofilter) {
448+
isToFilterBy = true;
449+
}
450+
}
451+
430452
if (blocks[i][j].name.substr(0, 3) === 'api')
431453
found = true;
432454
}
455+
456+
// add block if it's apidefine or the tag is equal to the value defined in options
457+
if (filterTag) {
458+
found = found && (isToFilterBy || isDefine);
459+
}
460+
433461
if (found) {
434462
foundIndexes.push(i);
435463
app.log.debug('api found in block: ' + i);

0 commit comments

Comments
 (0)