Skip to content

Commit

Permalink
filterByChildAnnotation
Browse files Browse the repository at this point in the history
  • Loading branch information
cancerberoSgx committed Sep 25, 2017
1 parent db554e1 commit d1fec26
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion doc/guide/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ <h1 id="text-markings">Text Markings</h1>
// @extends Backbone.Model
</pre>

<p>Also, there is a @?ref that will accept any kind of node - but less efficient by the viewer tools.</p>
<p>Also, there is a @?ref that will accept any kind of node. For classes is intelligent and you can use the class' simple name, but for referencing other types like methods, properties, events, etc you need to reference them by absolute name, this is $module.$className.$methodName. </p>

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion html/data.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/data.min.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/data.min.json.map

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions html/src/JsDocMaker_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3809,10 +3809,8 @@ JsDocMaker.filterByChildAnnotation = function(options)

};

function classHasDescendant(c, predicate){
var has;
has = has || _.find(c.children, function(node){return predicate(node)});

function classHasDescendant(c, predicate)
{
function doChildNodes(parentNode, childName, predicate)
{
var found
Expand All @@ -3830,7 +3828,12 @@ function classHasDescendant(c, predicate){
return found;
}

return doChildNodes(c, 'methods', predicate) || doChildNodes(c, 'properties', predicate) || doChildNodes(c, 'events', predicate);
var hasDirectChildren = _.find(c.children, function(node){return predicate(node)});
var hasMethods = doChildNodes(c, 'methods', predicate);
var hasProperties = doChildNodes(c, 'properties', predicate);
var hasEvents = doChildNodes(c, 'events', predicate)

return hasDirectChildren || hasMethods || hasProperties || hasEvents;
}
},{"../core/class":3,"underscore":1}],18:[function(require,module,exports){
// @module shortjsdoc.plugin @class JsDocMaker
Expand Down
13 changes: 8 additions & 5 deletions src/jsdocmaker/plugin/filter-by-child-annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ JsDocMaker.filterByChildAnnotation = function(options)

};

function classHasDescendant(c, predicate){
var has;
has = has || _.find(c.children, function(node){return predicate(node)});

function classHasDescendant(c, predicate)
{
function doChildNodes(parentNode, childName, predicate)
{
var found
Expand All @@ -53,5 +51,10 @@ function classHasDescendant(c, predicate){
return found;
}

return doChildNodes(c, 'methods', predicate) || doChildNodes(c, 'properties', predicate) || doChildNodes(c, 'events', predicate);
var hasDirectChildren = _.find(c.children, function(node){return predicate(node)});
var hasMethods = doChildNodes(c, 'methods', predicate);
var hasProperties = doChildNodes(c, 'properties', predicate);
var hasEvents = doChildNodes(c, 'events', predicate)

return hasDirectChildren || hasMethods || hasProperties || hasEvents;
}
34 changes: 23 additions & 11 deletions test/spec/JsDocMakerSpec2.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var JsDocMaker = typeof _ === 'undefined' ? require('../../src/jsdocmaker/main.js') : JsDocMaker;
var _ = typeof _ === 'undefined' ? require('underscore') : _;


describe("filter by child annotation", function()
{
it('fJsDocMaker.filterByChildAnnotation should remove classes that dont have a descendant child with given annotation', function()
// use case - I have a large project full of comments - but I want to mark somehow a public API with a custom child annotation like
// @ public or @ publicapi so we can filter a fragment of a full jsdoc for a particular api / layer / etc
{
var code =
'//@module functionAsTypesModule\n'+
'//@module big-module\n'+
'//@function F1 @param {Array<Number>} sortNumbers @return {Array<Number>}\n'+
'//@function F2 @param {Array<Number>} sortNumbers @return {Array<Number>}\n'+

Expand All @@ -32,6 +33,14 @@ describe("filter by child annotation", function()
'//@interface IComponent'+
'//@method do @publicapi'+

'//@class C3 blabla @extends Annotated2 @publicapi'+
'//@method notMarked'+


'//@class C4 blabla @extends Annotated2 @anotherannotation'+
'//@method notMarked'+


'//@module m2'+
'//@class C4'+
'';
Expand All @@ -45,16 +54,19 @@ describe("filter by child annotation", function()

var jsdoc = maker.data

// console.log(jsdoc)
expect(!!jsdoc.classes['functionAsTypesModule.C1']).toBe(false)
expect(!!jsdoc.classes['functionAsTypesModule.Annotated']).toBe(true)
expect(!!_.find(jsdoc.classes['functionAsTypesModule.Annotated'].methods, (p)=>p.name=='m1')).toBe(true)
expect(!!_.find(jsdoc.classes['functionAsTypesModule.Annotated'].methods, (p)=>p.name=='m2')).toBe(false)
expect(!!jsdoc.classes['functionAsTypesModule.Annotated2']).toBe(true)
expect(!!_.find(jsdoc.classes['functionAsTypesModule.Annotated2'].properties, (p)=>p.name=='p1')).toBe(true)
expect(!!_.find(jsdoc.classes['functionAsTypesModule.Annotated2'].properties, (p)=>p.name=='p2')).toBe(false)
expect(!!jsdoc.classes['functionAsTypesModule.IComponent']).toBe(true)
expect(!!jsdoc.classes['big-module.C3']).toBe(true)
expect(!!jsdoc.classes['big-module.C4']).toBe(false)

expect(!!jsdoc.classes['big-module.C1']).toBe(false)
expect(!!jsdoc.classes['big-module.Annotated']).toBe(true)
expect(!!_.find(jsdoc.classes['big-module.Annotated'].methods, (p)=>p.name=='m1')).toBe(true)
expect(!!_.find(jsdoc.classes['big-module.Annotated'].methods, (p)=>p.name=='m2')).toBe(false)
expect(!!jsdoc.classes['big-module.Annotated2']).toBe(true)
expect(!!_.find(jsdoc.classes['big-module.Annotated2'].properties, (p)=>p.name=='p1')).toBe(true)
expect(!!_.find(jsdoc.classes['big-module.Annotated2'].properties, (p)=>p.name=='p2')).toBe(false)
expect(!!jsdoc.classes['big-module.IComponent']).toBe(true)
expect(!!jsdoc.modules.m2).toBe(false)
expect(!!jsdoc.classes['m1.C4']).toBe(false)
});

})
})
6 changes: 5 additions & 1 deletion test/spec/pluginsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ describe("filter by child annotation", function()
'//@interface IComponent'+
'//@method do @publicapi'+

'//@class C3 blabla @extends Annotated2 @publicapi'+
'//@method notMarked'+


'//@module m2'+
'//@class C4'+
'';
Expand All @@ -415,7 +419,7 @@ describe("filter by child annotation", function()

var jsdoc = maker.data

// console.log(jsdoc)
console.log(jsdoc.classes['big-module.C3'])
expect(!!jsdoc.classes['big-module.C1']).toBe(false)
expect(!!jsdoc.classes['big-module.Annotated']).toBe(true)
expect(!!_.find(jsdoc.classes['big-module.Annotated'].methods, (p)=>p.name=='m1')).toBe(true)
Expand Down

0 comments on commit d1fec26

Please sign in to comment.