Skip to content

Commit 83f4eb4

Browse files
committed
Merge pull request phaserjs#1385 from pnstickne/wip-jsdoc-core2
jsdoc core/plugins
2 parents d19a2ab + bf16b97 commit 83f4eb4

5 files changed

Lines changed: 133 additions & 10 deletions

File tree

tasks/jsdoc-conf.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@
2020
"./src/system/",
2121
"./src/tilemap/",
2222
"./src/time/",
23-
"./src/tween/",
24-
"./src/utils/"
23+
"./src/tween/",
24+
"./src/utils/"
2525
],
2626
"exclude": [
2727
"./src/physics/p2/p2.js"
2828
],
2929
"includePattern": ".+\\.js(doc)?$",
3030
"excludePattern": "(^|\\/|\\\\)_"
3131
},
32-
"plugins" : [
32+
"plugins": [
33+
"./tasks/jsdoc-plugins/namealias",
34+
"./tasks/jsdoc-plugins/filterpixi",
3335
"./tasks/jsdoc-plugins/proptomember",
3436
"./tasks/jsdoc-plugins/sourceproxy",
37+
"./tasks/jsdoc-plugins/shortlinks",
3538
"plugins/markdown"
3639
],
3740
"templates": {

tasks/jsdoc-plugins/filterpixi.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Mark various PIXI properties/methods as private if they are not relevant to Phaser.
3+
*/
4+
5+
var path = require('path');
6+
7+
function docletParamsAcceptInteractionData (doclet) {
8+
9+
if (Array.isArray(doclet.params)) {
10+
return doclet.params.some(function (p) {
11+
return p.type && p.type.names.some(function (n) {
12+
return n === 'PIXI.InteractionData';
13+
});
14+
});
15+
}
16+
17+
}
18+
19+
var unwantedNames = {
20+
'PIXI.DisplayObject#defaultCursor': 1,
21+
'PIXI.DisplayObject#interactive' : 1
22+
};
23+
24+
function hasUnwantedName (doclet) {
25+
26+
var longname = doclet.longname;
27+
return unwantedNames[longname];
28+
29+
}
30+
31+
exports.handlers = {};
32+
exports.handlers.newDoclet = function (e) {
33+
34+
var doclet = e.doclet;
35+
36+
if (docletParamsAcceptInteractionData(doclet) ||
37+
hasUnwantedName(doclet))
38+
{
39+
doclet.access = 'private';
40+
}
41+
42+
};

tasks/jsdoc-plugins/namealias.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* When JSdoc encounters names it disables the automatic code inspection ability;
3+
* this is especially problematic for cases like
4+
*
5+
* > @class MyClass
6+
* > @constructor
7+
*
8+
* because the properties without an explicit @memberof or fullname are not being included in
9+
* in the newer JSDoc output.
10+
*
11+
* This is a simple plugin, as discussed https://github.com/jsdoc3/jsdoc/issues/804#event-195287680
12+
* to rewrite the @class [@constructor] to @alias @class which enables JSDoc to collect better data.
13+
*/
14+
15+
exports.handlers = {};
16+
exports.handlers.jsdocCommentFound = function (e) {
17+
18+
var raw = e.comment;
19+
20+
var m = /^(\s*[*])\s*@class\b/m.exec(raw);
21+
if (m)
22+
{
23+
// @class X -> @alias X / @class
24+
raw = raw.replace(/^(\s*[*])\s*@class[ \t]+(\S+).*?((?=[\r\n]+))/mg, "$1 @alias $2$3$1 @class");
25+
// @constructor -> {removed}
26+
raw = raw.replace(/^(\s*[*])\s*@constructor\b.*?(?=[\r\n]+)/mg, "$1");
27+
28+
e.comment = raw;
29+
}
30+
31+
};

tasks/jsdoc-plugins/shortlinks.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Transform '{@link #x}' to '{@link longname#x x}' which saves lots of cumersome typing.
3+
*
4+
* This looks in @description, @classdesc and @see tags only.
5+
*
6+
* See https://github.com/jsdoc3/jsdoc/issues/483
7+
*/
8+
9+
var path = require('path');
10+
11+
function expandLinks (text, parent) {
12+
13+
return text.replace(/\{\s*@link\s+([#.])([\w$.]+)\s*\}/g, function (m, mod, name) {
14+
var expanded = "{@link " + parent + mod + name + " " + name + "}";
15+
return expanded;
16+
});
17+
18+
}
19+
20+
exports.handlers = {};
21+
exports.handlers.newDoclet = function (e) {
22+
23+
var doclet = e.doclet;
24+
var parent;
25+
if (doclet.kind === 'class' || doclet.kind === 'interface')
26+
{
27+
parent = doclet.longname;
28+
}
29+
else
30+
{
31+
// member, method, property, etc.
32+
parent = doclet.memberof;
33+
}
34+
35+
['description', 'classdesc'].forEach(function (p) {
36+
if (doclet[p])
37+
{
38+
doclet[p] = expandLinks(doclet[p], parent);
39+
}
40+
});
41+
42+
if (doclet.see && doclet.see.length)
43+
{
44+
for (var i = 0; i < doclet.see.length; i++)
45+
{
46+
doclet.see[i] = expandLinks(doclet.see[i], parent);
47+
}
48+
}
49+
50+
};

tasks/jsdoc-plugins/sourceproxy.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
2-
* For use with custom `@sourcepath`, `@sourceline`, `@nosource` properties
3-
* (which are used in YUIDoc-to-JSDoc to supply source documentation)
2+
* Moves information from custom `@sourcepath`, `@sourceline`, `@nosource` doclets
3+
* into the doclet meta-information.
4+
*
5+
* This is useful to maintain source file/lineno links with the YUIDoc-to-JSDoc output.
46
*/
57

68
var path = require('path');
@@ -31,8 +33,3 @@ exports.defineTags = function(dictionary) {
3133
});
3234

3335
};
34-
35-
exports.handlers = {};
36-
exports.handlers.newDoclet = function (e) {
37-
38-
};

0 commit comments

Comments
 (0)