2014-12-04 09:02:03 -05:00
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
module.exports = function processClassDocs(log, getJSDocComment) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
$runAfter: ['processModuleDocs'],
|
|
|
|
$runBefore: ['parsing-tags', 'generateDocsFromComments'],
|
2015-03-17 15:22:13 -04:00
|
|
|
ignorePrivateMembers: false,
|
2014-12-04 09:02:03 -05:00
|
|
|
$process: function(docs) {
|
|
|
|
var memberDocs = [];
|
2015-03-17 15:22:13 -04:00
|
|
|
var ignorePrivateMembers = this.ignorePrivateMembers;
|
2014-12-04 09:02:03 -05:00
|
|
|
_.forEach(docs, function(classDoc) {
|
|
|
|
if ( classDoc.docType === 'class' ) {
|
|
|
|
|
|
|
|
classDoc.members = [];
|
|
|
|
|
|
|
|
// Create a new doc for each member of the class
|
|
|
|
_.forEach(classDoc.elements, function(memberDoc) {
|
|
|
|
|
2015-03-31 16:51:25 -04:00
|
|
|
var memberName = memberDoc.name.location.toString();
|
|
|
|
|
|
|
|
if (ignorePrivateMembers && memberName.charAt(0) === '_') return;
|
2015-03-17 15:22:13 -04:00
|
|
|
|
2014-12-04 09:02:03 -05:00
|
|
|
memberDocs.push(memberDoc);
|
|
|
|
|
|
|
|
memberDoc.docType = 'member';
|
|
|
|
memberDoc.classDoc = classDoc;
|
2015-03-31 16:51:25 -04:00
|
|
|
memberDoc.name = memberName;
|
|
|
|
if (memberDoc.parameterList) {
|
|
|
|
memberDoc.params = memberDoc.parameterList.parameters.map(function(param) {
|
|
|
|
return param.location.toString();
|
|
|
|
});
|
|
|
|
}
|
2015-03-17 15:22:13 -04:00
|
|
|
|
2014-12-04 09:02:03 -05:00
|
|
|
if (memberDoc.commentBefore ) {
|
|
|
|
// If this export has a comment, remove it from the list of
|
|
|
|
// comments collected in the module
|
|
|
|
var index = classDoc.moduleDoc.comments.indexOf(memberDoc.commentBefore);
|
|
|
|
if ( index !== -1 ) {
|
|
|
|
classDoc.moduleDoc.comments.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_.assign(memberDoc, getJSDocComment(memberDoc.commentBefore));
|
|
|
|
}
|
2015-03-31 16:51:25 -04:00
|
|
|
|
|
|
|
// Constuctor is a special case member
|
|
|
|
if (memberName === 'constructor') {
|
|
|
|
classDoc.constructorDoc = memberDoc;
|
|
|
|
} else {
|
|
|
|
insertSorted(classDoc.members, memberDoc, 'name');
|
|
|
|
}
|
|
|
|
|
2014-12-04 09:02:03 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return docs.concat(memberDocs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2015-03-31 16:51:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
function insertSorted(collection, item, property) {
|
|
|
|
var index = collection.length;
|
|
|
|
while(index>0) {
|
|
|
|
if(collection[index-1][property] < item[property]) break;
|
|
|
|
index -= 1;
|
|
|
|
}
|
|
|
|
collection.splice(index, 0, item);
|
|
|
|
}
|