Skip to content
This repository has been 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 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 filer by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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 specifique tag
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"wants" and "specific" (are you french? :p)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hh yes :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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 equale to the value defined in options.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"equal" and no dot at the end please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (filterTag) {
found = found && (isToFilterBy || isDefine);
}

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