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

Filterbytag #91

Merged
merged 6 commits into from
Nov 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var ParameterError = require('./errors/parameter_error');
var ParserError = require('./errors/parser_error');

var app = {};
var filterTag = null; // define the tag to filter by

function Parser(_app) {
var self = this;
Expand Down Expand Up @@ -49,6 +50,12 @@ function Parser(_app) {
self.addParser(parser, require(filename));
}
});

// check app.options.filterBy and define the tag to filter by
if (app.options.filterBy) {
var tag = app.options.filterBy.split('=')[0];
filterTag = (tag.indexOf('api') !== -1) ? tag : null;
}
}

/**
Expand Down Expand Up @@ -410,8 +417,12 @@ Parser.prototype._findBlocks = function() {
*/
Parser.prototype._findBlockWithApiGetIndex = function(blocks) {
var foundIndexes = [];
// get value to filter by
var valueTofilter = (filterTag) ? app.options.filterBy.split('=')[1] : null;
for (var i = 0; i < blocks.length; i += 1) {
var found = false;
var isToFilterBy = false;
var isDefine = false;
for (var j = 0; j < blocks[i].length; j += 1) {
// check apiIgnore
if (blocks[i][j].name.substr(0, 9) === 'apiignore') {
Expand All @@ -427,9 +438,26 @@ Parser.prototype._findBlockWithApiGetIndex = function(blocks) {
break;
}

// check if the user want to filter by some specific tag
if (filterTag) {
// we need to add all apidefine
if (blocks[i][j].name.substr(0, 9) === 'apidefine') {
isDefine = true;
}
if (blocks[i][j].name.substr(0, filterTag.length) === filterTag && blocks[i][j].content === valueTofilter) {
isToFilterBy = true;
}
}

if (blocks[i][j].name.substr(0, 3) === 'api')
found = true;
}

// add block if it's apidefine or the tag is equal to the value defined in options
if (filterTag) {
found = found && (isToFilterBy || isDefine);
}

if (found) {
foundIndexes.push(i);
app.log.debug('api found in block: ' + i);
Expand Down