Skip to content

Commit ea86166

Browse files
committed
Documentation - YUIdoc to jsdoc, global nav
- Added support to deal with some of the YUIDoc "formats" used to represent arrays. It covers the case of the old PIXI documentation. - Cleaned up log reporting and issue identification - "Fixed" the global navigation, now that globals are displayed .. now just need to fix the documentation the members aren't incorrectly listed as globals ..
1 parent d8d2ebd commit ea86166

2 files changed

Lines changed: 98 additions & 14 deletions

File tree

docs/build/docstrap-master/template/publish.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ function buildNav( members ) {
347347
members.globals.forEach( function ( g ) {
348348
if ( g.kind !== 'typedef' && !hasOwnProp.call( seen, g.longname ) ) {
349349

350-
nav.global.members.push( linkto( g.longname, g.name ) );
350+
nav.global.members.push( {
351+
link: linkto( g.longname, g.name ),
352+
depth: g.longname.split('.').length - 1
353+
} );
354+
351355
}
352356
seen[g.longname] = true;
353357
} );

tasks/yuidoc-to-jsdoc/converter.js

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,61 @@ function group_typeitems(typeitems) {
102102

103103
}
104104

105+
/**
106+
* Convert ident to the "closest" valid non-quoted identifier.
107+
*/
108+
function as_valid_identifier (ident) {
109+
ident = ident.replace(/\s/g, '_');
110+
ident = ident.replace(/[^\w_$]/g, '');
111+
ident = ident.replace(/^(\d)/, '_$1');
112+
113+
return ident;
114+
}
115+
116+
/**
117+
* YUIDoc has no concept of generic types and various projects use inconsistent mashups.
118+
* This is a simple hack to provide some normalization; only spome formats
119+
* (in particular, that seen in the pixi project) and a few types of input are
120+
* correctly accepted and nested arrays are not supported.
121+
*
122+
* Returns the corrected type if successful
123+
*/
124+
function fixup_yuidoc_array (rawtype) {
125+
// Accept examples, where the angle braces represent all braces.
126+
// 1. X < >
127+
// 2. Array < X >
128+
// 3. Array..of < X >
129+
var r = rawtype;
130+
var m;
131+
132+
// Trim spaces
133+
r = r.replace(/^\s+|\s+$/g, '');
134+
// make all brackets angles
135+
r = r.replace(/[({[]/g, '<').replace(/[)}\]]/g, '>');
136+
// remove whitespace and periods next to brackets
137+
r = r.replace(/[\s.]*([<>])[\s.]*/g, '$1');
138+
139+
// match T<..>, where T != 'array'
140+
m = r.match(/^(\S+)(?:<.*>)$/i);
141+
if (m && m[1].toLowerCase() !== 'array') {
142+
return 'Array<' + as_valid_identifier(m[1] || 'unknown') + '>';
143+
}
144+
145+
// match Array <T>
146+
m = r.match(/^Array<(.*)>$/i);
147+
if (m) {
148+
return 'Array<' + as_valid_identifier(m[1] || 'unknown') + '>';
149+
}
150+
151+
// match Array..of T
152+
m = r.match(/^Array.*?of\b\s*(.*)$/i);
153+
if (m) {
154+
return 'Array<' + as_valid_identifier(m[1] || 'unknown') + '>';
155+
}
156+
157+
return '';
158+
}
159+
105160
/**
106161
* Process a complex (possibly multiple) type.
107162
* (This has limited ability now: will not recurse, handle special arrays, etc.)
@@ -118,20 +173,43 @@ function resolve_typename(typename, typedescs) {
118173
}
119174

120175
typenames = typenames.map(function (part) {
121-
122-
// YUIDoc is type... and JSDoc is ...type
176+
177+
var orig = part;
178+
var prev;
179+
var loss = false;
123180
var repeating = false;
124-
if (part.match(/[.]{2,}/)) {
125-
repeating = true;
126-
part = part.replace(/[.]{2,}/g, '');
181+
var array = false;
182+
183+
// Don't accept quotes in names from upstream
184+
prev = part;
185+
part = part.replace(/"/g, '');
186+
loss = loss || prev !== part;
187+
188+
// YUIDoc is type... and JSDoc is ...type
189+
prev = part;
190+
part = part.replace(/^\.{3,}|\.{3,}$/g, '');
191+
repeating = prev !== part;
192+
193+
prev = part;
194+
part = fixup_yuidoc_array(part);
195+
if (part) {
196+
array = true;
197+
} else {
198+
part = prev;
199+
}
200+
201+
if (array) {
202+
loss = loss || orig.replace(/^\W/, '') !== part.replace(/^\W/, '');
203+
} else {
204+
prev = part;
205+
var m = part.match(/[\w$.]+/); // Take possible '.' to start
206+
part = (m && m[0]) || '';
207+
part = as_valid_identifier(part);
208+
loss = loss || prev !== part;
127209
}
128210

129-
// This may happen for some terribly invalid input; ideally this would not be
130-
// "handled" here, but trying to work with some not-correct input..
131-
var origpart = part;
132-
part = part.replace(/[^a-zA-Z0-9_$<>.]/g, '');
133-
if (origpart !== part) {
134-
console.log("Mutilating type: {" + origpart + "}");
211+
if (loss) {
212+
console.log("Mutilating type: (" + orig + "=>" + part + ")");
135213
}
136214

137215
var resolved = resolve_single_typename(part, typedescs);
@@ -293,9 +371,11 @@ function itemdesc_to_attrs(itemdesc, typedesc, typedescs) {
293371
{
294372
return propertydesc_to_attrs(itemdesc, typedesc, typedescs);
295373
}
296-
else
374+
else if (!typedesc._loggedLooseComment)
297375
{
298-
console.log("Skipping loose comment: " + itemdesc.file + ":" + itemdesc.line);
376+
typedesc._loggedLooseComment = true;
377+
var name = itemdesc.file.match(/([^\/\\]*)$/)[1];
378+
console.log("Skipping loose comment: " + name + ":" + itemdesc.line + " (first)");
299379
}
300380

301381
}

0 commit comments

Comments
 (0)