jsdoc: implement constructors plugin that scans for symbols named Class#initialize or Class.Class and places them in the Constructors list in the documentation.

This commit is contained in:
Jonathan Puckey 2011-05-28 02:13:52 +02:00
parent f78259f8de
commit 69732bcbad
4 changed files with 85 additions and 43 deletions

View file

@ -0,0 +1,14 @@
JSDOC.PluginManager.registerPlugin(
"JSDOC.constructors",
{
beanSymbols: {},
onSymbol: function(symbol) {
// If the method name is 'initialize', or it is a static method
// with a capitalized first character, it is a constructor
if (/(#initialize|\.[A-Z][a-z][^#.]+$)/.test(symbol.alias)) {
symbol.isConstructor = true;
symbol.isa = 'FUNCTION';
}
}
}
);

View file

@ -1,10 +1,11 @@
{! data.classId = data.alias.toLowerCase() !}
{!
var ownProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic});
var staticProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && $.isStatic});
var ownMethods = data.methods.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic && !$.isOperator});
var staticMethods = data.methods.filter(function($){return $.memberOf == data.alias && !$.isNamespace && $.isStatic && !$.isOperator});
var operatorMethods = data.methods.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic && $.isOperator});
var constructors = data.methods.filter(function($){return $.memberOf == data.alias && $.isConstructor});
var ownProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic && !$.isConstructor});
var staticProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && $.isStatic && !$.isConstructor});
var ownMethods = data.methods.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic && !$.isOperator && !$.isConstructor});
var staticMethods = data.methods.filter(function($){return $.memberOf == data.alias && !$.isNamespace && $.isStatic && !$.isOperator && !$.isConstructor});
var operatorMethods = data.methods.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic && !$.isConstructor && $.isOperator});
if (operatorMethods.length) {
var operators = {};
for (var i = 0, l = operatorMethods.length; i < l; i++) {
@ -62,41 +63,12 @@
{+processInlineTags(data.classDesc)+}
</div>
<!-- ============================== constructors ========================= -->
<if test="!/(Event|Style)/.test(data.alias) && !data.isNamespace">
<if test="!/(Event|Style)/.test(data.alias) && !data.isNamespace && !data.ignore">
<div class="reference-members"><h2>Constructors</h2>
<div id="{+data.classId+}" class="member">
<div id="{+data.classId+}-link" class="member-link">
<a name="{+data.classId+}" href="#" onClick="return toggleMember('{+data.classId+}', false);"><tt><b>{+ data.alias +}</b>{+ makeSignature(data.params) +}</tt></a>
</div>
<div id="{+data.classId+}-description" class="member-description hidden">
<div class="member-header">
<div class="member-title">
<div class="member-link">
<a href="#" onClick="return toggleMember('{+data.classId+}', false);"><tt><b>{+ data.alias +}</b>{+ makeSignature(data.params) +}</tt></a>
</div>
</div>
<div class="member-close"><input type="button" value="Close" onClick="toggleMember('{+data.classId+}', false);"></div>
<div class="clear"></div>
</div>
<div class="member-text">{+processInlineTags(data.desc)+}
<if test="data.example.length">
<for each="example" in="data.example">
<pre>{+example+}</pre>
</for>
</if>
{+ templates.parameters.process(data) +}
<if test="data.returns.length">
<ul><b>Returns:</b>
<li>
<for each="item" in="data.returns">
<dd>{+((item.type)?"<span class=\"light fixedFont\">{"+(new Link().toSymbol(item.type))+"}</span> " : "")+}{+processInlineTags(item.desc, { stripParagraphs: true })+}</dd>
</for>
</li>
</ul>
</if>
</div>
</div>
</div>
{+ templates.constructor.process(data) +}
<for each="constructor" in="constructors">
{+ templates.constructor.process(constructor) +}
</for>
</div>
</if>

View file

@ -0,0 +1,45 @@
{!
var constructorId = Helpers.getConstructorId(data);
var name = data.alias.replace(/(#|\^).+$/, '');
data.desc = processGroupTitle(data.desc, data);
if (data.returns.length == 0)
data.returns = [{type: data.memberOf ? data.memberOf : data.alias, desc: ''}];
!}
<if test="defined(data.groupTitle)">
<h3>{+data.groupTitle+}</h3>
</if>
<div id="{+constructorId+}" class="member">
<div id="{+constructorId+}-link" class="member-link">
<a name="{+constructorId+}" href="#" onClick="return toggleMember('{+constructorId+}', false);"><tt><b>{+ name +}</b>{+ makeSignature(data.params) +}</tt></a>
</div>
<div id="{+constructorId+}-description" class="member-description hidden">
<div class="member-header">
<div class="member-title">
<div class="member-link">
<a href="#" onClick="return toggleMember('{+constructorId+}', false);"><tt><b>{+ name +}</b>{+ makeSignature(data.params) +}</tt></a>
</div>
</div>
<div class="member-close"><input type="button" value="Close" onClick="toggleMember('{+constructorId+}', false);"></div>
<div class="clear"></div>
</div>
<div class="member-text">{+processInlineTags(data.desc)+}
<if test="data.example.length">
<for each="example" in="data.example">
<pre>{+example+}</pre>
</for>
</if>
{+ templates.parameters.process(data) +}
<if test="data.returns.length">
<ul><b>Returns:</b>
<li>
<for each="item" in="data.returns">
<li>
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}<if test="item.desc">&nbsp;&mdash;&nbsp;</if></if>{+processInlineTags(item.desc, { stripParagraphs: true })+}</tt>
</li>
</for>
</li>
</ul>
</if>
</div>
</div>
</div>

View file

@ -44,6 +44,19 @@ var Helpers = {
}
}
return id.join('-');
},
getConstructorId: function(symbol) {
var id = [symbol.alias.replace(/([#].+$|[\^][0-9])/g, '').toLowerCase()
.replace(/[.]/, '-')];
if (symbol.params) {
for (var i = 0, l = symbol.params.length; i < l; i++) {
var param = symbol.params[i];
if (!param.isOptional)
id.push(param.name);
}
}
return id.join('-');
}
};
@ -64,7 +77,8 @@ function publish(symbolSet) {
property: new JSDOC.JsPlate(publish.conf.templatesDir + "property.tmpl"),
parameters: new JSDOC.JsPlate(publish.conf.templatesDir + "parameters.tmpl"),
operators: new JSDOC.JsPlate(publish.conf.templatesDir + "operators.tmpl"),
examples: new JSDOC.JsPlate(publish.conf.templatesDir + "examples.tmpl")
examples: new JSDOC.JsPlate(publish.conf.templatesDir + "examples.tmpl"),
constructor: new JSDOC.JsPlate(publish.conf.templatesDir + "constructor.tmpl")
};
// is source output is suppressed, just display the links to the source file
@ -262,9 +276,6 @@ function makeSignature(params) {
}
function processGroupTitle(str, symbol) {
// if (/grouptitle/.test(str))
// print('yeah');
// print(str);
var groupTitle = str.match(/\{@grouptitle ([^}]+)\}/);
if (groupTitle) {
symbol.groupTitle = groupTitle[1];