@@ -10,6 +10,7 @@ var ParameterError = require('./errors/parameter_error');
10
10
var ParserError = require ( './errors/parser_error' ) ;
11
11
12
12
var app = { } ;
13
+ var filterTag = null ; // define the tag to filter by
13
14
14
15
function Parser ( _app ) {
15
16
var self = this ;
@@ -49,6 +50,12 @@ function Parser(_app) {
49
50
self . addParser ( parser , require ( filename ) ) ;
50
51
}
51
52
} ) ;
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
+ }
52
59
}
53
60
54
61
/**
@@ -410,8 +417,12 @@ Parser.prototype._findBlocks = function() {
410
417
*/
411
418
Parser . prototype . _findBlockWithApiGetIndex = function ( blocks ) {
412
419
var foundIndexes = [ ] ;
420
+ // get value to filter by
421
+ var valueTofilter = ( filterTag ) ? app . options . filterBy . split ( '=' ) [ 1 ] : null ;
413
422
for ( var i = 0 ; i < blocks . length ; i += 1 ) {
414
423
var found = false ;
424
+ var isToFilterBy = false ;
425
+ var isDefine = false ;
415
426
for ( var j = 0 ; j < blocks [ i ] . length ; j += 1 ) {
416
427
// check apiIgnore
417
428
if ( blocks [ i ] [ j ] . name . substr ( 0 , 9 ) === 'apiignore' ) {
@@ -427,9 +438,26 @@ Parser.prototype._findBlockWithApiGetIndex = function(blocks) {
427
438
break ;
428
439
}
429
440
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
+
430
452
if ( blocks [ i ] [ j ] . name . substr ( 0 , 3 ) === 'api' )
431
453
found = true ;
432
454
}
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
+
433
461
if ( found ) {
434
462
foundIndexes . push ( i ) ;
435
463
app . log . debug ( 'api found in block: ' + i ) ;
0 commit comments