diff --git a/lib/parser.js b/lib/parser.js index c651080..974e416 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -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; @@ -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; + } } /** @@ -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') { @@ -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);