chore(doc-gen): add method signatures to members and functions

Closes https://github.com/angular/dgeni/issues/124
This commit is contained in:
Peter Bacon Darwin 2015-03-31 21:51:25 +01:00
parent 54a4e4a67c
commit 609201e109
5 changed files with 55 additions and 9 deletions

View File

@ -17,15 +17,20 @@ module.exports = function processClassDocs(log, getJSDocComment) {
// Create a new doc for each member of the class // Create a new doc for each member of the class
_.forEach(classDoc.elements, function(memberDoc) { _.forEach(classDoc.elements, function(memberDoc) {
if (ignorePrivateMembers && memberDoc.name.literalToken.value.charAt(0) === '_') return; var memberName = memberDoc.name.location.toString();
if (ignorePrivateMembers && memberName.charAt(0) === '_') return;
classDoc.members.push(memberDoc);
memberDocs.push(memberDoc); memberDocs.push(memberDoc);
memberDoc.docType = 'member'; memberDoc.docType = 'member';
memberDoc.classDoc = classDoc; memberDoc.classDoc = classDoc;
memberDoc.name = memberDoc.name.literalToken.value; memberDoc.name = memberName;
if (memberDoc.parameterList) {
memberDoc.params = memberDoc.parameterList.parameters.map(function(param) {
return param.location.toString();
});
}
if (memberDoc.commentBefore ) { if (memberDoc.commentBefore ) {
// If this export has a comment, remove it from the list of // If this export has a comment, remove it from the list of
@ -37,6 +42,14 @@ module.exports = function processClassDocs(log, getJSDocComment) {
_.assign(memberDoc, getJSDocComment(memberDoc.commentBefore)); _.assign(memberDoc, getJSDocComment(memberDoc.commentBefore));
} }
// Constuctor is a special case member
if (memberName === 'constructor') {
classDoc.constructorDoc = memberDoc;
} else {
insertSorted(classDoc.members, memberDoc, 'name');
}
}); });
} }
}); });
@ -45,3 +58,13 @@ module.exports = function processClassDocs(log, getJSDocComment) {
} }
}; };
}; };
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);
}

View File

@ -38,7 +38,9 @@ module.exports = function ExportTreeVisitor(ParseTreeVisitor, log) {
this.updateExport(tree); this.updateExport(tree);
this.currentExport.name = tree.name.identifierToken.value; this.currentExport.name = tree.name.identifierToken.value;
this.currentExport.functionKind = tree.functionKind; this.currentExport.functionKind = tree.functionKind;
this.currentExport.parameters = tree.parameterList.parameters; this.currentExport.parameters = tree.parameterList.parameters.map(function(param) {
return param.location.toString();
});
this.currentExport.typeAnnotation = tree.typeAnnotation; this.currentExport.typeAnnotation = tree.typeAnnotation;
this.currentExport.annotations = tree.annotations; this.currentExport.annotations = tree.annotations;
this.currentExport.docType = 'function'; this.currentExport.docType = 'function';

View File

@ -1,13 +1,18 @@
{% extends 'layout/base.template.html' %} {% include "lib/paramList.html" -%}
{% extends 'layout/base.template.html' -%}
{% block body %} {% block body %}
<h1>{$ doc.name $} <span class="type">class</span></h1> <h1 class="class export">{$ doc.name $} <span class="type">class</span></h1>
<p class="module">exported from <a href="/{$ doc.moduleDoc.path $}">{$ doc.moduleDoc.id $}</a></p> <p class="module">exported from <a href="/{$ doc.moduleDoc.path $}">{$ doc.moduleDoc.id $}</a></p>
<p>{$ doc.description | marked $}</p> <p>{$ doc.description | marked $}</p>
<h2>Members</h2> <h2>Members</h2>
{% for member in doc.members %} {%- if doc.constructorDoc %}
<h3>{$ member.name $}</h3> <h3>{$ doc.constructorDoc.name $}{$ paramList(doc.constructorDoc.params) $}</h3>
<p>{$ doc.constructorDoc.description | marked $}</p>
{% endif -%}
{%- for member in doc.members %}
<h3>{$ member.name $}{$ paramList(member.params) $}</h3>
<p>{$ member.description | marked $}</p> <p>{$ member.description | marked $}</p>
{% endfor %} {% endfor %}

View File

@ -0,0 +1,9 @@
{% include "lib/paramList.html" -%}
{% extends 'layout/base.template.html' -%}
{% block body %}
<h1 class="function export">{$ doc.name $}{$ paramList(doc.parameters) $}</h1>
<p class="module">exported from <a href="/{$ doc.moduleDoc.path $}">{$ doc.moduleDoc.id $}</a></p>
<p>{$ doc.description | marked $}</p>
{% endblock %}

View File

@ -0,0 +1,7 @@
{% macro paramList(params) -%}
{%- if params -%}<span class="params">(
{%- for param in params -%}
<span class="param">{$ param $}{% if not loop.last %}, {% endif %}</span>
{%- endfor %})</span>
{%- endif %}
{%- endmacro -%}