-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdgenerationx.js
2910 lines (2222 loc) · 82.1 KB
/
dgenerationx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// DGeneration-X - A Javascript documentation generator.
//
// Copyright (c) 2023 Cliff Earl.
//
// MIT License:
//
/* clip_start */
const
// Create a new HTML element with the given type.
createElement = (type) => document.createElement(type),
// Append the given child HTML element to the given parent HTML element.
appendChild = (parent, child) => parent.appendChild(child),
// Output the given text to the developer console.
log = (t) => {
console.log(t);
worklog.push(`${t}\n`);
},
// Output the given text to the developer console as a warning.
warn = (t) => {
console.warn(t);
worklog.push(`${t}\n`);
}
// Initialize performance timing.
resetPerf = () => perfStart = performance.now(),
// Dump performance timing to console prepended by the given text.
showPerf = (t) => log(`${t} in ${(performance.now() - perfStart).toFixed(4)}ms.`),
// #region - File operations.
// Load the text file from the given url.
loadTextFile = async (uri) => {
try {
const response = await fetch(uri);
const data = await response.text();
return data;
} catch (e) {
console.warn(`loadTextFile() ${e.message}`);
}
},
// Allow the user to browse for and select a local, then load the selected file as text.
// loadFile = async () => {
// const fileHandle = await window.showOpenFilePicker();
// const file = await fileHandle.getFile();
// const contents = await file.text();
// return contents;
// },
// Allow the user to browse for and select a local, then save the given data as a text file.
saveFile = async (content) => {
const options = {
types: [
{
description: "HTML file",
accept: { "text/html": [".html"] },
},
],
};
try {
const fileHandle = await window.showSaveFilePicker(options);
const writable = await fileHandle.createWritable();
await writable.write(content);
await writable.close();
} catch (e) {
console.warn(`saveFile() ${e.message}`);
}
};
//#endregion
//
// JAVASCRIPT CODE PARSING AND HTML CONTENT GENERATION.
//
//#region - Javascript code parsing.
let
worklog = [], // Debugging only.
project,
targetStyleSheet,
targetRule,
adt,
docID,
mObject,
mNamespace,
mClass,
inClass,
inNamespace,
mComments = [],
jsDoc,
lines,
perfStart;
const
mNamespaces = [],
mClasses = [],
mOrphanedDocs = [],
mOrphanedMembers = [],
mOrphanedMethods = [],
// Create a new object that will be used to represent a namespace, class, member, or method. The resulting object will be merged with the given source object.
newObject = (source = {}) => Object.assign({
id: docID, // Common.
kind: '',
name: '',
description: '',
isNamespace: false, // Namespace.
isComment: false, // Namespace.
isMember: false, // Namespace.
isClass: false, // Class.
isMethod: false, // Method.
isParameter: false, // Method.
isConstructor: false, // Method.
isReturn: false, // Method.
isOptional: false, // Parameter.
extends: '',
memberOf: '', // Member / Method.
default: '', // Member.
syntax: '', // Method.
example: '', // Method.
comments: [], // Namespace.
members: [], // Member.
methods: [], // Method.
parameters: [],
returns: [],
}, source),
// Generate debug information about the given object, and display it in the `content` pane.
displayObject = (object) => {
const
content = createElement('div'), // Container that will be appended to the `content pane.
container = createElement('div'), // Clickable container that toggles visibility of its self.
title = createElement('label'), // Clickable label that toggles visibility of 'container.
// Append a new key/value pair to 'container' with the given key, value, and CSS class.
append = (key, value, _class = '') => {
// Create HTML elements.
const
objectContainer = createElement('div'),
keyElement = createElement('span'),
valueElement = createElement('span'),
commaElement = createElement('span');
// Set CSS styles.
keyElement.classList.add('jsdoc-key'),
commaElement.classList.add('jsdoc-comma');
valueElement.classList.add('jsdoc-value');
if (_class != '') valueElement.classList.add(_class);
// Set innerHTML.
commaElement.innerHTML = ',';
keyElement.innerHTML = `${key}: `;
valueElement.innerHTML = value;
// Append in order and display in the `content` pane.
appendChild(objectContainer, keyElement);
appendChild(objectContainer, valueElement);
appendChild(valueElement, commaElement);
appendChild(container, objectContainer);
};
container.classList.add('hidden', 'jsdoc-container');
content.classList.add('jsdoc-display');
title.innerHTML = `${object.id}. (${object.kind})`;
const objectKindClass = (object.isNamespace) ? 'jsdoc-namespace' : (object.isClass) ? 'jsdoc-class' : (object.isMethod) ? 'jsdoc-method' : 'jsdoc-member';
title.classList.add('jsdoc-title', objectKindClass);
title.onclick = () => container.classList.toggle('hidden');
container.onclick = () => container.classList.toggle('hidden');
appendChild(content, title);
appendChild(content, container);
appendChild(contentPane, content);
for (const key in object) {
let value = object[key];
switch (typeof value) {
case 'string':
if (value != '') {
if (object.isComment) {
append(key, `/*<br>${value}<br>*/`, 'jsdoc-comment');// appendString(`${key}: ${object[key]}`);
} else {
append(key, `${'`'}${value}${'`'}`, 'jsdoc-string');// appendString(`${key}: ${object[key]}`);
}
}
break;
case 'number':
append(key, value, 'jsdoc-number');// appendString(`${key}: ${object[key]}`);
break;
case 'boolean':
if (value) append(key, value, 'jsdoc-boolean');// appendString(`${key}: ${object[key]}`);
break;
case 'object':
if (object.isMethod && value.length > 0) append(key, `[${value.length}]`, 'jsdoc-array');// appendString(`${key}: ${object[key]}`);
break;
default:
warn(`displayObject() unknown type (${typeof value})`);
break;
} // Typeof switch.
} // Process objects loop.
},
// Determine if the given array of lines contains comment information.
isComment = (lines) => (lines[lines.length - 1] === '@@'),
// Determine if the given array of lines contains namespace information.
isNamespace = (lines) => {
for (const line of lines) {
if (line.indexOf('@namespace') === 0) return true;
}
return false;
},
// Determine if the given array of lines contains class information.
isClass = (lines) => {
for (const line of lines) {
if (line.indexOf('class ') === 0) return true;
}
return false;
},
// Determine if the given array of lines contains member information.
isMember = (lines) => {
for (const line of lines) {
if (line.indexOf('@memberof') === 0) return true;
}
return false;
},
// Determine if the given array of lines contains method information.
isMethod = (lines) => {
for (const line of lines) {
if (line.indexOf('function ') === 0) return true;
if (line.indexOf('@param') === 0) return true;
if (line.indexOf('@return') === 0) return true;
if (line.indexOf('=>') >= 0) return true;
if (line.indexOf('()') >= 0 && line.indexOf('() ') === -1 && line.indexOf('@default') === -1 ) return true; // This is a bit sketchy (checking for ""() " in the doc to differentiate between functions and readme's").
}
return false;
},
// Close the current class by adding it to the `mClasses` array.
closeOpenClass = () => {
mClasses.push(mClass);
inClass = false;
},
// We assume that each source code file contains a single @namespace declaration.
createNewNamespace = (lines) => {
if (inNamespace) { // Check for nested namespaces.
//
// Nested namespaces are a nasty occurrence (IMHO) but we need to manage them as best as we are able to.
// Our "best effort" is to hastily create a new namespace for the nested one and add it to the `mNamespaces` array.
//
// warn(`>>>>> encountered a nested namespace. creating extra namespace." <<<<<`);
const temp = newObject({isNamespace: true, kind: 'namespace'});
let skipRemaining;
for (const line of lines) {
if (line.indexOf('@namespace') === 0) {
//log(`namespace tag..`);
temp.name = line.slice(line.indexOf('@namespace ') + '@namespace '.length);
} else if (line.indexOf('@example') === 0) {
//log(`example tag..`);
skipRemaining = true;
} else if (!skipRemaining) {
if (line.indexOf('@') === 0) {
//log(`unknown tag "${line}"..`);
} else {
//log(`description fragment..`);
temp.description += `${line}<br>`;
}
}
} // Line loop.
mNamespaces.push(temp);
//log('mNamespace{}');
//log(mNamespace);
return;
} // Nested namespace check.
//log(`initializeNamespace()`);
mNamespace = newObject({isNamespace: true, kind: 'namespace'});
let skipRemaining;
for (const line of lines) {
if (line.indexOf('@namespace') === 0) {
//log(`namespace tag..`);
mNamespace.name = line.slice(line.indexOf('@namespace ') + '@namespace '.length);
} else if (line.indexOf('@example') === 0) {
//log(`example tag..`);
// break;
skipRemaining = true;
} else if (!skipRemaining) {
if (line.indexOf('@') === 0) {
//log(`unknown tag "${line}"..`);
} else {
//log(`description fragment..`);
mNamespace.description += `${line}<br>`;
}
}
} // Line loop.
inNamespace = true;
//log('mNamespace{}');
//log(mNamespace);
},
// Close open class and add it to the `mClasses` array, then create and initialize a new class.
createNewClass = (lines) => {
//log(`createNewClass()`);
mObject.kind = 'class';
if (inClass) mClasses.push(mClass); // Close and add to `mClasses` array if already open.
mClass = newObject({isClass: true, kind: 'class'});
inClass = true;
const name = lines.pop().replace('class ', '');
if (name.indexOf(' extends ') != -1) {
mClass.extends = name.slice(name.indexOf(' extends ') + ' extends '.length);
mClass.name = name.slice(0, name.indexOf(' '));
} else {
mClass.name = name;
}
for (let line of lines) {
if (line.indexOf('@example') != -1) {
//log(`found example.. skipping remaining lines..`);
break;
} else if (line.indexOf('@') === 0) {
//log(`unknown tag "${line}"..`);
} else {
if (line.indexOf('$') === 0) line = ` - ${line.slice(1)}`;
if (line.indexOf('$') != -1) line = line.replace(/\$/g, '- ')
//log(`description fragment..`);
mClass.description += `${line}<br>`;
}
} // Line loop.
//log('mClass{}');
//log(mClass);
},
// Create and initialize a new method.
createNewMethod = (lines) => {
//log(`createNewMethod()`);
mObject.kind = 'method';
let declaration = lines.pop();
// log(`declaration: ${declaration}`);
if (declaration.indexOf('this.') === 0) return; // Fix for edge case where properties might be interpretted as methods, when inside a class.
if (declaration.indexOf('constructor') === 0) {
//log(`class constructor..`);
mObject.name = 'constructor';
} else if (declaration.indexOf('()') + 2 === declaration.length) {
//log(`class method declaration..`);
mObject.name = declaration.slice(0, declaration.indexOf('()'));
} else if (declaration.indexOf('function ') === 0) {
//log(`function declaration..`);
mObject.name = declaration.substring(declaration.indexOf(' ') + 1, declaration.indexOf('('));
} else if (declaration.indexOf('const ') === 0 || declaration.indexOf('let ') === 0) {
//log(`const function declaration..`);
mObject.name = declaration.substring(declaration.indexOf(' ') + 1, declaration.indexOf('=') - 1);
} else if (inClass) {
//log(`class function declaration..`);
mObject.name = declaration.slice(0, declaration.indexOf('('));
}
let skippingExample;
for (let line of lines) {
if (line.indexOf('@param') === 0) {
//log(`parameter..`);
//log(`${line}`);
const mParameter = newObject({isParameter: true});
// Check for and get description.
if (line.indexOf('$') != -1) {
mParameter.description = line.slice(line.indexOf('$') + 1);
line = line.slice(0, line.indexOf('$')); // Truncate line so it no longer contains the description.
}
mParameter.kind = line.substring(line.indexOf('{') + 1, line.indexOf('}'));
line = line.replace(/ /g, ''); // Strip whitespace to ease procssing.
const defaultValueIndex = line.indexOf('=');
if (line.indexOf('[') != -1) {
mParameter.isOptional = true;
if (defaultValueIndex != -1) {
//log(' parameter IS optional AND has default.');
mParameter.name = line.substring(line.indexOf('[') + 1, defaultValueIndex);
mParameter.default = line.substring(line.indexOf('=') + 1, line.indexOf(']'));
} else {
//log(' parameter IS optional.');
mParameter.name = line.substring(line.indexOf('[') + 1, line.indexOf(']'));
}
} else {
//log(`parameter is NOT optional.`)
mParameter.name = line.slice(line.indexOf('}') + 1);
}
mObject.parameters.push(mParameter);
} else if (line.indexOf('@return') === 0) {
//log(`return..`);
const mReturn = newObject({isReturn: true});
mReturn.kind = line.substring(line.indexOf('{') + 1, line.indexOf('}'))
mObject.returns.push(mReturn);
} else if (line.indexOf('@memberof ') === 0) {
//log(`memberof..`);
mObject.memberOf = line.slice(line.indexOf(' ') + 1);
} else if (line.indexOf('@example') === 0) {
//log(`example..`);
skippingExample = true;
} else {
if (line.indexOf('@') === 0) {
//log(`unknown tag "${line}"..`);
} else {
if (skippingExample) {
//log(`skipping example..`)
} else {
if (line.indexOf('$') === 0) line = ` - ${line.slice(1)}`;
//log(`description fragment..`);
mObject.description += `${line}<br>`;
}
}
}
} // Line loop.
if (inClass) {
mClass.methods.push(mObject);
} else {
if (mNamespace) {
if (mObject.memberOf != '' && mNamespace.name != mObject.memberOf) { // Is the method a method of `mNamespace`?
mOrphanedMethods.push(mObject); // If no then it belings to a nested napespace that might not exist yet. In this case, orphan it and it will be relocated to the correct namespace later.
} else { // Method is a method of `mNamespace`.
mNamespace.methods.push(mObject);
}
} else {
mOrphanedMethods.push(mObject);
}
}
if (inClass && mObject.isMember) closeOpenClass(); // If currently in a class but a member method is encountered, then we left the class, so close it.
//log(`mObject{}`);
//log(mObject);
},
// Create and initialize a new member.
createNewMember = (lines) => {
//log(`createNewMember()`);
mObject.kind = 'member';
const declaration = lines.pop();
mObject.name = declaration.substring(declaration.indexOf(' ') + 1, (declaration.indexOf('=') === -1) ? declaration.indexOf(';') : declaration.indexOf('=') - 1);
for (let line of lines) {
if (line.indexOf('@default ') === 0) {
//log(`default tag..`);
let value = line.slice(line.indexOf('@default ') + '@default '.length);
mObject.default = (isNaN(value)) ? value : value * 1;
} else if (line.indexOf('@memberof ') === 0) {
//log(`memberof..`);
mObject.memberOf = line.slice(line.indexOf(' ') + 1);
} else {
if (line.indexOf('@') === 0) {
//log(`unknown tag "${line}"..`);
} else {
if (line.indexOf('$') === 0) line = ` - ${line.slice(1)}`;
//log(`description fragment..`);
mObject.description += `${line}<br>`;
}
}
} // Line loop.
if (mNamespace) {
mNamespace.members.push(mObject);
} else {
mOrphanedMembers.push(mObject);
}
},
// Create and initialize a new comment.
createNewComment = (lines) => {
//log(`createNewComment()`);
mObject.kind = 'comment';
for (const line of lines) {
//log('comment line..')
mObject.comment += `${line}<br>`;
} // Line loop.
mComments.push(mObject);
},
// Parse all .js files in the `filenames` array.
parseAllFiles = async () => {
const // Strings to replace before parsing.
replacements = [
'\r',
'<br>',
'<b>',
'</b>',
"'use strict';"
];
resetPerf();
// #region - Process all javascript files.
for (let i = 0; i < project.fileNames.length; i++) {
//
// Read and parse a javascript source code file into objects that can be used to create HTML documentation.
//
//log(`reading ${project.fileNames[i]}.js`);
let input = await loadTextFile(`${project.filePath}/${project.fileNames[i]}.js`); // load next file.
for (let j = 0; j < replacements.length; j++) input = input.replace(new RegExp(replacements[j], 'g'), ''); // Replace problematic strings.
let jsDocs = input.split('/**'); // Split into jsDocs.
//log(`found ${jsDocs.length} jsDocs:`);
mComments = [];
inNamespace = false;
// Process all jsdocs that were identified in the js file.
for (let i = 0; i < jsDocs.length; i++) {
jsDoc = jsDocs[i];
if (jsDoc.length === 0) continue; // Skip empty sections
docID = i;
jsDoc = jsDoc
.replace(/ *\*\//g, '@@') // Replace all jsdoc terminators (*/) which are preceeded by any number of space characters, with "@@" for later identification.
.replace(/ *\* */g, '') // Remove all asterix characters and all whitespace before and after them.
.replace(/\//, '') // Remove extraneous division character.
.trim(); // Remove leading and trailing whitespace.
if (jsDoc.indexOf('@namespace') === -1) {
jsDoc = jsDoc.replace(/ *- */g, ' $'); // Replace with string character for later identification.
// Now we need to fix shit that got broken.
jsDoc = jsDoc.replace(/= \$/g, '=-').replace(/\( \$/g, '(-');
}
let
pruningLines,
tempLines = jsDoc.split(/\r|\n/); // Split into lines.
lines = [];
// #region - Preprocess lines.
for (let j = 0; j < tempLines.length; j++) {
let line = tempLines[j];
if (line === '@example') pruningLines = true; // Begin pruning lines when this tag is encountered.
if (!pruningLines) {
if (line.indexOf('@@') > 0) { // Check where the terminator is not the entire content of the line.
lines.push(line.slice(0, line.indexOf('@@')).trim()); //Isolate and add the part of the line that isn't the terminator, and add it to the lines array.
line = '@@'; // Set line is a terminator.
lines.push(line); // Add the new terminator to the lines array.
} else {
lines.push(line.trim());
}
} else {
if (line.indexOf('@') === 0) pruningLines = false; // Stop pruning if we encounter another tag.
lines.push(line);
} // Pruning check.
// Once we reach the terminator, add the very next line to the array as it will contain a function, variable, or class declaration.
if (line === '@@') {
if (j < tempLines.length - 1) {
if (pruningLines) lines.push(tempLines[j]);
lines.push(tempLines[j + 1].trim()); // Include the line directly after the terminator to the lines array.
}
break;
}
} // Preprocess lines loop.
// #endregion
//
// The lines array has been preprocessed. All code examples and extraneous javascript code have been removed.
//
// Create a new object that will enableus to determine which type of processing will be needed for the current jsdoc.
mObject = newObject({
isComment: isComment(lines),
isNamespace: isNamespace(lines),
isClass: isClass(lines),
isMember: isMember(lines),
isMethod: isMethod(lines),
});
//log(`\n${''.padStart(200, '*')}\njsDoc ${i}(${jsDoc.length} bytes) (${lines.length} lines)`);
//log(jsDoc.slice(0, 250));
//log(lines);
if (mObject.isNamespace) {
createNewNamespace(lines);
if (project.displayDebugInfo) displayObject(mNamespace);
} else if (mObject.isComment) {
createNewComment(lines);
if (project.displayDebugInfo) displayObject(mObject);
} else if (mObject.isClass) {
createNewClass(lines);
if (project.displayDebugInfo) displayObject(mClass);
} else if (mObject.isMethod) {
createNewMethod(lines);
if (project.displayDebugInfo) displayObject(mObject);
} else if (mObject.isMember) {
createNewMember(lines);
if (project.displayDebugInfo) displayObject(mObject);
} else {
//log(`docID:${docID} unable to categorize lines array`);
mOrphanedDocs.push(lines);
}
} // jsDocs loop.
if (mNamespace) {
for (let k = 0; k < mComments.length; k++) mNamespace.comments.push(mComments[k]); // Copy all comments. Only first one will be used when generating documentation.
}
if (mNamespace) mNamespaces.push(mNamespace);
mNamespace = null;
inNamespace = false;
} // Process files loop.
// #endregion
if (inClass) closeOpenClass(); // Close any open class.
//
// All javascript files have now been read, and parsed into various arrays of objects.
//
//log(`parsed ${mNamespaces.length} namespaces`);
//log(mNamespaces);
//log(`parsed ${mClasses.length} classes`);
//log(mClasses);
warn(`found ${mOrphanedDocs.length} orphaned documents`);
//log(mOrphanedDocs);
//
// Whilst parsing, some members and methods may be have been tagged as being a memberof another namespace that hasn't been parsed yet (doesn't exist).
// During parsing, these members and methods will have been added to the 'mOrphanedMembers` and `mOrphanedMethods` arrays respectively.
// Now that all namespaces have been identified, try to relocate the orphaned entities to the namespace they belong to.
//
// #region - Relocate orphaned members and methods.
//log(`found ${mOrphanedMethods.length} orphaned methods`);
//log(mOrphanedMethods);
//log(`found ${mOrphanedMembers.length} orphaned members`);
//log(mOrphanedMembers);
//log(`relocating orphaned members(${mOrphanedMembers.length}) and methods(${mOrphanedMethods.length})`);
for (let j = 0; j < mNamespaces.length; j++) {
const
mNamespace = mNamespaces[j],
namespaceName = mNamespace.name;
//log(`checking namespace ${mNamespace.name}`);
// Relocate orphaned members.
for (let k = mOrphanedMembers.length - 1; k >= 0; k--) {
const mMember = mOrphanedMembers[k];
if (mMember.memberOf === namespaceName) {
//log(`relocated orphaned member "${mMember.name}" to namespace "${namespaceName}"..`);
mNamespace.members.push(mMember);
mOrphanedMembers.splice(k, 1);
} // Member is member of namespace check.
} // Orphaned members loop.
// Relocate orphaned methods.
for (let k = mOrphanedMethods.length - 1; k >= 0; k--) {
const mMethod = mOrphanedMethods[k];
if (mMethod.memberOf === namespaceName) {
//log(`relocated orphaned method "${mMethod.name}" to namespace "${namespaceName}"..`);
mNamespace.methods.push(mMethod);
mOrphanedMethods.splice(k, 1);
} // Method is member of namespace check.
} // Orphaned methods loop.
} // Namespace loop.
if (mOrphanedMembers.length === 0 && mOrphanedMethods.length === 0) {
log('\nall orphaned members and methods relocated');
} else {
//
// You really don't want to ever see the following warning :D
//
warn(`\n${mOrphanedMembers.length} orphaned members and ${mOrphanedMethods.length} methods were unable to be relocated`);
//log(mOrphanedMethods);
}
// #endregion
//
// Before generating the final HTML, sort all arrays into a-z order.
//
mNamespaces.sort((a, b) => (a.name > b.name) ? 1 : -1);
for (let j = 0; j < mNamespaces.length; j++) mNamespaces[j].members.sort((a, b) => (a.name > b.name) ? 1 : -1);
for (let j = 0; j < mNamespaces.length; j++) mNamespaces[j].methods.sort((a, b) => (a.name > b.name) ? 1 : -1);
mClasses.sort((a, b) => (a.name > b.name) ? 1 : -1);
for (let j = 0; j < mClasses.length; j++) mClasses[j].members.sort((a, b) => (a.name > b.name) ? 1 : -1);
for (let j = 0; j < mClasses.length; j++) mClasses[j].methods.sort((a, b) => (a.name > b.name) ? 1 : -1);
//
// This object encapsulates all of the data generated during parsing.
//
adt = {
description: 'This is the abstract data tree (adt)',
namespaces : mNamespaces,
classes: mClasses,
orphanedDocs: mOrphanedDocs,
ophanedMembers: mOrphanedMembers,
orphanedMethods: mOrphanedMethods,
};
// Dump the adt to the console.
//log('\nadt');
//log(adt);
if (project.displayWorklog) {
let pre = createElement('pre');
pre.innerHTML = worklog.join('');
appendChild(contentPane, pre);
}
//
// Begin by generating the namespace containers which will be displayed in the navigation pane.
//
//
// Generate HTML content for each namespace and it's associated members and methods.
//
// #region - Generate namespace navigation containers.
const
// Create elements.
namespacesTitle = createElement('label'),
allNamespaces = createElement('div');
// Add CSS styles.
namespacesTitle.classList.add('clickable-navigation-title');
allNamespaces.classList.add('collapsable-navigation-container');
// Set properties.
namespacesTitle.innerHTML = 'Namespaces';
namespacesTitle.onclick = () => namespacesTitle.nextElementSibling.classList.toggle('hidden');
// Append to navigation pane.
appendChild(navigationPane, namespacesTitle);
appendChild(navigationPane, allNamespaces);
// #endregion
// #region - Create HTML content for each namespace.
for (let i = 0; i < mNamespaces.length; i++) {
const
_namespace = mNamespaces[i],
// #region - Create title which when clicked, displays the appropriate content.
// Create clickable title.
namespaceTitle = createElement('label');
namespaceTitle.classList.add('clickable-navigation-link');
namespaceTitle.innerHTML = _namespace.name;
namespaceTitle.id = `${_namespace.name}_title`;
appendChild(allNamespaces, namespaceTitle);
// Install click handler to display relevant content in content pane when title is clicked.
namespaceTitle.onclick = () => {
hideElementsWithClass('nonapi');
// If there is already a selected namespace title, unselect it.
if (selectedObject) {
pagePositions[selectedObject.id] = contentPane.scrollTop;
selectedObject.classList.toggle('hidden');
selectedObjectTitle.classList.remove('selected');
}
// Display relevant content in content pane.
const selectedObjectID = `${_namespace.name}_content`;
selectedObject = getByID(selectedObjectID);
selectedObject.classList.toggle('hidden');
contentPane.scrollTop = (pagePositions[selectedObjectID]) ? pagePositions[selectedObjectID] : 0;
// Set currently selected namespace title.
selectedObjectTitle = getByID(`${_namespace.name}_title`);
selectedObjectTitle.classList.add('selected');
} // Namespace title click handler.
// #endregion
// #region - Generate content container, title, and description.
const
// Create elements
_namespaceDocument = createElement('div'),
_namespaceHeader = createElement('div'),
_namespaceTitle = createElement('h3'),
_namespaceDescription = createElement('p');
// Add CSS styles.
_namespaceDocument.classList.add('document', 'hidden', 'api');
_namespaceHeader.classList.add('document-header');
_namespaceTitle.classList.add('document-title');
_namespaceDescription.classList.add('document-description');
// Set properties.
_namespaceDocument.id = `${_namespace.name}_content`;
_namespaceTitle.innerHTML = _namespace.name;
_namespaceDescription.innerHTML = _namespace.description;
appendChild(_namespaceHeader, _namespaceTitle);
appendChild(_namespaceHeader, _namespaceDescription);
appendChild(_namespaceDocument, _namespaceHeader);
// #endregion
// #region - Generate HTML content for namespace members.
if (_namespace.members.length > 0) {
const
// Create elements.
section = createElement('div'),
sectionTitle = createElement('h4');
// Add CSS styles.
section.classList.add('document-section');
sectionTitle.classList.add('section-title');
// Set properties.
sectionTitle.innerHTML = 'Members';
// Append to container.
appendChild(section, sectionTitle);
appendChild(_namespaceDocument, section);