| 
									
										
										
										
											2014-12-04 14:02:03 +00:00
										 |  |  | var _ = require('lodash'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-10 12:45:02 +02:00
										 |  |  | module.exports = function captureClassMembers(log, getJSDocComment) { | 
					
						
							| 
									
										
										
										
											2014-12-04 14:02:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2015-04-10 12:45:02 +02:00
										 |  |  |     $runAfter: ['captureModuleExports'], | 
					
						
							|  |  |  |     $runBefore: ['parsing-tags'], | 
					
						
							| 
									
										
										
										
											2015-03-17 19:22:13 +00:00
										 |  |  |     ignorePrivateMembers: false, | 
					
						
							| 
									
										
										
										
											2014-12-04 14:02:03 +00:00
										 |  |  |     $process: function(docs) { | 
					
						
							|  |  |  |       var memberDocs = []; | 
					
						
							| 
									
										
										
										
											2015-03-17 19:22:13 +00:00
										 |  |  |       var ignorePrivateMembers = this.ignorePrivateMembers; | 
					
						
							| 
									
										
										
										
											2014-12-04 14:02:03 +00: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 21:51:25 +01:00
										 |  |  |             var memberName = memberDoc.name.location.toString(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (ignorePrivateMembers && memberName.charAt(0) === '_') return; | 
					
						
							| 
									
										
										
										
											2015-03-17 19:22:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-04 14:02:03 +00:00
										 |  |  |             memberDocs.push(memberDoc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             memberDoc.docType = 'member'; | 
					
						
							|  |  |  |             memberDoc.classDoc = classDoc; | 
					
						
							| 
									
										
										
										
											2015-03-31 21:51:25 +01:00
										 |  |  |             memberDoc.name = memberName; | 
					
						
							|  |  |  |             if (memberDoc.parameterList) { | 
					
						
							|  |  |  |               memberDoc.params = memberDoc.parameterList.parameters.map(function(param) { | 
					
						
							|  |  |  |                 return param.location.toString(); | 
					
						
							|  |  |  |               }); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-03-17 19:22:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-04 14:02:03 +00: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 21:51:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // Constuctor is a special case member
 | 
					
						
							|  |  |  |             if (memberName === 'constructor') { | 
					
						
							|  |  |  |               classDoc.constructorDoc = memberDoc; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               insertSorted(classDoc.members, memberDoc, 'name'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-04 14:02:03 +00:00
										 |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return docs.concat(memberDocs); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-03-31 21:51:25 +01: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); | 
					
						
							|  |  |  | } |