mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
Added "property to member" plugin for JSDoc
This automatically fixes usage of the form /** desc * @property {T} name - desc To /** desc * @member {T} name Being careful to only make the transformation when it is logical to do and preserving both descriptions as appropriate.
This commit is contained in:
parent
be8499fa49
commit
e6da96e908
2 changed files with 71 additions and 2 deletions
7
docs/build/conf.json
vendored
7
docs/build/conf.json
vendored
|
@ -28,7 +28,10 @@
|
|||
"includePattern": ".+\\.js(doc)?$",
|
||||
"excludePattern": "(^|\\/|\\\\)_"
|
||||
},
|
||||
"plugins" : ["plugins/markdown"],
|
||||
"plugins" : [
|
||||
"local-plugins/proptomember",
|
||||
"plugins/markdown"
|
||||
],
|
||||
"templates": {
|
||||
"cleverLinks" : false,
|
||||
"monospaceLinks" : false,
|
||||
|
@ -56,4 +59,4 @@
|
|||
"private": false,
|
||||
"lenient": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
66
docs/build/local-plugins/proptomember.js
vendored
Normal file
66
docs/build/local-plugins/proptomember.js
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Transform @property tags to @member tags if it looks like @property was incorrectly used.
|
||||
* - That is, there is only one property and it has the same name as the member.
|
||||
* The result is less-redundancy and better type exposure in the JSDoc output.
|
||||
*
|
||||
* If the member type is not assigned then the property type is used.
|
||||
*
|
||||
* A meld of the description are used; appending the property description if appropriate.
|
||||
*
|
||||
* This approach works for most cases in Phaser because JSDoc automatically determines the name if not specified in @name, @method, @member or @field.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
|
||||
function looksLikeItMightContain (haystack, needle) {
|
||||
|
||||
haystack = haystack || '';
|
||||
needle = needle || '';
|
||||
|
||||
if (!needle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
haystack = haystack.replace(/[^a-z]/gi, '').toLowerCase();
|
||||
needle = needle.replace(/[^a-z]/gi, '').toLowerCase();
|
||||
|
||||
return haystack.indexOf(needle) > -1;
|
||||
|
||||
}
|
||||
|
||||
exports.handlers = {};
|
||||
exports.handlers.newDoclet = function (e) {
|
||||
|
||||
var doclet = e.doclet;
|
||||
var props = e.doclet.properties;
|
||||
|
||||
if (doclet.kind === 'member' &&
|
||||
props && props.length === 1 &&
|
||||
props[0].name === doclet.name)
|
||||
{
|
||||
// "Duplicate"
|
||||
var prop = props[0];
|
||||
|
||||
if (!doclet.type)
|
||||
{
|
||||
doclet.type = prop.type;
|
||||
}
|
||||
|
||||
if (!doclet.description)
|
||||
{
|
||||
doclet.description = prop.description;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!looksLikeItMightContain(doclet.description, prop.description))
|
||||
{
|
||||
// Tack it on..
|
||||
doclet.description += " " + prop.description;
|
||||
}
|
||||
}
|
||||
|
||||
// And no more prop
|
||||
e.doclet.properties = undefined;
|
||||
}
|
||||
|
||||
};
|
Loading…
Reference in a new issue