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

Commit 5cf12fd

Browse files
author
BELGHITI ALAOUI Omar
committed
add possibility to filter by tag
1 parent 1e30ce0 commit 5cf12fd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/parser.js

Lines changed: 23 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;
1314

1415
function Parser(_app) {
1516
var self = this;
@@ -49,6 +50,11 @@ function Parser(_app) {
4950
self.addParser(parser, require(filename));
5051
}
5152
});
53+
54+
if (app.options.filterBy) {
55+
var tag = app.options.filterBy.split('=')[0];
56+
filterTag = (tag.indexOf('api') != -1) ? tag : null;
57+
}
5258
}
5359

5460
/**
@@ -410,8 +416,11 @@ Parser.prototype._findBlocks = function() {
410416
*/
411417
Parser.prototype._findBlockWithApiGetIndex = function(blocks) {
412418
var foundIndexes = [];
419+
const valueTofilter = (filterTag) ? app.options.filterBy.split('=')[1] : null;
413420
for (var i = 0; i < blocks.length; i += 1) {
414421
var found = false;
422+
let isToFilterBy = false;
423+
let isDefine = false;
415424
for (var j = 0; j < blocks[i].length; j += 1) {
416425
// check apiIgnore
417426
if (blocks[i][j].name.substr(0, 9) === 'apiignore') {
@@ -426,10 +435,24 @@ Parser.prototype._findBlockWithApiGetIndex = function(blocks) {
426435
found = false;
427436
break;
428437
}
438+
// if (filterTag && blocks[i][j].name.substr(0, 10) === filterTag && blocks[i][j].content !== valueTofilter) {
439+
if (filterTag) {
440+
if (blocks[i][j].name.substr(0, 9) === 'apidefine') {
441+
isDefine = true;
442+
}
443+
if (blocks[i][j].name.substr(0, filterTag.length) === filterTag && blocks[i][j].content === valueTofilter) {
444+
isToFilterBy = true;
445+
}
446+
}
429447

430448
if (blocks[i][j].name.substr(0, 3) === 'api')
431449
found = true;
432450
}
451+
452+
if (filterTag) {
453+
found = found && (isToFilterBy || isDefine);
454+
}
455+
433456
if (found) {
434457
foundIndexes.push(i);
435458
app.log.debug('api found in block: ' + i);

0 commit comments

Comments
 (0)