This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Gruntfile.js
997 lines (982 loc) · 46.1 KB
/
Gruntfile.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
'use strict';
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
shell: {
generateJSON: {
command: 'jsdoc --configure ./conf.json ./video.js/src/js > cumulative.json'
},
cloneVideoJS: {
// Once 5.0 is in stable the line below should be use instead
// command: 'rm -rf ./video.js && git clone -b stable --single-branch https://github.com/videojs/video.js.git'
command: 'rm -rf ./video.js && git clone -b stable --single-branch https://github.com/videojs/video.js.git'
},
},
copy: {
guides: {
expand: true,
src: ['video.js/docs/guides/*'],
dest: 'docs/guides/',
filter: 'isFile',
flatten: true
},
examples: {
expand: true,
cwd: 'video.js/docs/examples/',
src: '**',
dest: 'docs/examples/',
filter: 'isFile',
flatten: false
},
fontawesome: {
files: [
{
expand: true,
src: ['node_modules/font-awesome/fonts/*'],
dest: 'docs/fonts',
filter: 'isFile',
flatten: true
}
]
}
},
markdown: {
all: {
files: [
{
expand: true,
src: 'docs/guides/*.md',
dest: './',
ext: '.html'
}
],
options: {
preCompile: function(src, context) {
return src.replace(/\.\/(.*)\.md/g, "./$1.html");
},
template: 'templates/guide-template.html',
markdownOptions: {
gfm: true
}
}
}
},
clean: [
'docs/guides/*.md'
],
concat: {
dist: {
src: ['var-name.txt',
'cumulative.json',
'semicolon.txt'
],
dest: 'doc-data-full.js'
}
},
uglify: {
dist: {
src: 'doc-data-full.js',
dest: './docs/api/js/doc-data.js'
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-markdown');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.task.registerTask('createFiles', 'Create files into which docs will be injected', function () {
var classData = [],
docData = '',
contentStr = '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><script src="//use.edgefonts.net/source-code-pro.js">\n // font for code blocks \n</script><link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700" rel="stylesheet" type="text/css"> <!-- there are many other style for highlighted code here: https://cdnjs.com/libraries/highlight.js --><link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/atelier-forest.light.min.css"><link rel="stylesheet" type="text/css" href="css/api-docs.css"></head><body></body></html>',
DOMParser = require('xmldom').DOMParser,
XMLSerializer = require('xmldom').XMLSerializer,
doc,
doc_data = {},
docsPathStem = 'https://github.com/videojs/video.js/blob/master/src',
docsFolder,
title,
// data structures
classes = {
thisClass: [],
parentClass: []
},
// paths
classFilePath,
parentClassFilePath,
// elements
mainContent,
main,
doc_body,
docContentStr;
//read the JSDoc JSON into a variable
docData = grunt.file.readJSON('cumulative.json');
// extract the class items from the doc data
classData = getSubArray(docData, 'kind', 'class');
// now create the array of filenames
createFilenameArray(classData);
/**
* get a subset of objects in array of objects
* based on some property value
*
* @param {array} targetArray - array to search
* @param {string} objProperty - object property to search
* @param {string|number} value - value of the property to search for
* @return {array} array of objects with matching property value
*/
function getSubArray(targetArray, objProperty, value) {
var i, totalItems = targetArray.length,
idxArr = [];
for (i = 0; i < totalItems; i++) {
if (targetArray[i][objProperty] === value) {
idxArr.push(targetArray[i]);
}
}
return idxArr;
}
/**
* does a regex replace on a str
* @param {String} str the string to make replacements on
* @param {Object} regex the regex
* @param {String} newStr the string to substitute for the regex finds
* @param {Function} callback callback function
* @return {String} str the string with replacements made
*/
function regexReplace(str, regex, newStr, callback) {
str = str.replace(regex, newStr);
return str;
}
/**
* create the HTML files for the classes
* @param {array} filenameArray - array of the filenames
*/
function createFiles(filenameArray) {
var i,
iMax = filenameArray.length,
filename,
fullpath,
reLT1 = new RegExp('&lt;', 'g'),
reLT2 = new RegExp('<', 'g'),
reGT = new RegExp('>', 'g'),
reQuot1 = new RegExp('&quot;', 'g'),
reQuot2 = new RegExp('"', 'g');
/**
* does a regex replace on a str
* @param {String} str the string to make replacements on
* @param {Object} regex the regex
* @param {String} newStr the string to substitute for the regex finds
* @param {Function} callback callback function
* @return {String} str the string with replacements made
*/
function regexReplace(str, regex, newStr, callback) {
str = str.replace(regex, newStr);
return str;
}
function writeFile() {
// create file with name=filename and contents=contentStr
docContentStr = new XMLSerializer().serializeToString(doc);
// convert html character codes to brackets
docContentStr = docContentStr.replace(reLT1, '<');
docContentStr = docContentStr.replace(reLT2, '<');
docContentStr = docContentStr.replace(reGT, '>');
docContentStr = docContentStr.replace(reQuot1, '"');
docContentStr = docContentStr.replace(reQuot2, '"');
fullpath = './docs/api/' + filename;
grunt.file.write(fullpath, docContentStr);
}
for (i = 0; i < iMax; i++) {
filename = filenameArray[i];
doc = new DOMParser().parseFromString(contentStr);
// generate the main contents
contentInit(filename, writeFile);
}
}
function createFilenameArray(classData) {
var filenameArray = [],
i,
iMax = classData.length,
item,
str;
// extract the filenames from the class items
for (i = 0; i < iMax; i++) {
item = classData[i];
str = item.meta.filename;
str = str.substr(str.lastIndexOf('/') + 1);
str = str.replace('.js', '.html');
filenameArray.push(str);
}
// videojs is special case
filenameArray.push('video.html');
filenameArray = filenameArray.sort();
// now create the files
createFiles(filenameArray);
}
/**
* tests for all the ways a variable might be undefined or not have a value
*
* @param {*} x - the variable to test
* @return {Boolean} true if variable is defined and has a value
*/
function isDefined(x) {
if (x === '' || x === null || x === undefined || x === NaN) {
return false;
}
return true;
}
/**
* determines whether specified item is in an array
*
* @param {array} arr - array to check
* @param {string} item - to check for
* @return {boolean} true if item is in the array, else false
*/
function isItemInArray(arr, item) {
var i,
iMax = arr.length;
for (i = 0; i < iMax; i++) {
if (arr[i] === item) {
return true;
}
}
return false;
}
/**
* get a copy of (rather than reference to) an object
*
* @param {object} obj - the object you want a copy
* @return {object} the copy
*/
function copyObj(obj) {
if (isDefined(obj)) {
return JSON.parse(JSON.stringify(obj));
}
return null;
}
/**
* find index of an object in array of objects
* based on some property value
* generally useful for finding a unique object
*
* @param {array} targetArray - array to search
* @param {string} objProperty - object property to search
* @param {string|number} value - value of the property to search for
* @return {integer} index of first instance if found, otherwise returns -1
*/
function findObjectInArray(targetArray, objProperty, value) {
var i, totalItems = targetArray.length,
objFound = false;
for (i = 0; i < totalItems; i++) {
if (targetArray[i][objProperty] === value) {
objFound = true;
return i;
}
}
if (objFound === false) {
return -1;
}
}
/**
* find indexes of a set of object in array of objects
* based on some property value
* generally useful for finding several objects
*
* @param {array} targetArray - array to search
* @param {string} objProperty - object property to search
* @param {string|number} value - value of the property to search for
* @return {array} array of indexes for matching objects
*/
function findObjectsInArray(targetArray, objProperty, value) {
var i, totalItems = targetArray.length,
newArr = [];
for (i = 0; i < totalItems; i++) {
if (targetArray[i][objProperty] === value) {
newArr.push(i);
}
}
return newArr;
}
/**
* sort an array of objects based on an object property
*
* @param {array} targetArray - array to sort
* @param {string} objProperty - property whose value to sort on
* @return {array} the sorted array
*/
function sortArray(targetArray, objProperty) {
targetArray.sort(function (a, b) {
var propA = a[objProperty].toLowerCase(),
propB = b[objProperty].toLowerCase();
// sort ascending; reverse propA and propB to sort descending
if (propA < propB) {
return -1;
} else if (propA > propB) {
return 1;
}
return 0;
});
return targetArray;
}
/**
* create an element
*
* @param {string} type - the element type
* @param {object} attributes - attributes to add to the element
* @return {object} the HTML element
*/
function createEl(type, attributes) {
var el;
if (isDefined(type)) {
el = doc.createElement(type);
if (isDefined(attributes)) {
var attr;
for (attr in attributes) {
el.setAttribute(attr, attributes[attr]);
}
}
return el;
}
}
/**
* creates a text node and adds it to an element
* @param {object|node} el - the node (element) to add the text to
* @param {string} str - the text to add
*/
function addText(el, str) {
var text = doc.createTextNode(str);
el.appendChild(text);
}
/**
* finds the objects in the doc data for a fileName
*
* @param {array} arr - the array of objects to search
* @param {string} filename - the filename to look for in the meta object
* @return {array} - array of the objects found
*/
function findClassObjects(arr, filename) {
var i, totalItems = arr.length,
newArr = [];
for (i = 0; i < totalItems; i++) {
if (isDefined(arr[i].meta)) {
if (arr[i].meta.filename === filename) {
newArr.push(arr[i]);
}
}
}
return newArr;
}
/**
* add the class header content
*/
function addHeaderContent(callback) {
var topSection = createEl('section', {
id: 'top',
class: 'section'
}),
headerData = doc_data.thisClass.headerInfo,
header = createEl('h1'),
extendsNode = createEl('p'),
extendsLink,
definedIn = createEl('p'),
definedInLink = createEl('a', {
href: docsPathStem + '/js/' + classFilePath + '#L' + headerData.meta.lineno
}),
description = createEl('div', {
style: 'border:none',
id: 'classDescription',
class: 'description'
}),
constructorHeader = createEl('h3'),
constructorPre = createEl('pre'),
constructorCode = createEl('code'),
constructorParamsHeader = createEl('h4'),
constructorParams = [],
text;
// add main content wrapper
doc_body.appendChild(mainContent);
main = doc.getElementById('main');
// add elements
topSection.appendChild(header);
topSection.appendChild(description);
// source file
topSection.appendChild(definedIn);
addText(definedIn, 'DEFINED IN: ');
definedIn.appendChild(definedInLink);
addText(definedInLink, headerData.meta.filename + ' line number: ' + headerData.meta.lineno);
mainContent.appendChild(topSection);
// page header
addText(header, headerData.name);
// parent info if this class extends another
if (isDefined(doc_data.parentClasses)) {
topSection.appendChild(extendsNode);
addText(extendsNode, 'EXTENDS: ');
extendsLink = createEl('a', {
href: doc_data.parentClasses[0].headerInfo.meta.filename.replace('.js', '.html')
});
extendsNode.appendChild(extendsLink);
addText(extendsLink, doc_data.parentClasses[0].headerInfo.meta.filename);
}
// constructor info - don't add for video.js
if (doc_data.thisClass.headerInfo.name !== 'videojs') {
topSection.appendChild(constructorHeader);
topSection.appendChild(constructorPre);
constructorPre.appendChild(constructorCode);
// create the constructor info
addText(constructorHeader, 'Constructor');
// get constructor params if any
if (isDefined(headerData.params)) {
var paramTableHeaders = ['name', 'Type', 'Required', 'Description'],
paramTable = createEl('table'),
paramThead = createEl('thead'),
paramTbody = createEl('tbody'),
paramTheadRow = createEl('tr'),
paramTbodyRow = createEl('tr'),
paramTH,
paramTD,
k,
kMax;
addText(constructorParamsHeader, 'Parameters');
paramTable.appendChild(paramThead);
paramTable.appendChild(paramTbody);
paramThead.appendChild(paramTheadRow);
// set the table headers
kMax = paramTableHeaders.length;
for (k = 0; k < kMax; k++) {
paramTH = createEl('th');
paramTheadRow.appendChild(paramTH);
addText(paramTH, paramTableHeaders[k]);
}
// now the table info
kMax = headerData.params.length;
for (k = 0; k < kMax; k++) {
paramTbodyRow = createEl('tr');
paramTbody.appendChild(paramTbodyRow);
paramTD = createEl('td');
addText(paramTD, headerData.params[k].name);
paramTbodyRow.appendChild(paramTD);
paramTD = createEl('td');
addText(paramTD, headerData.params[k].type.names.join('|'));
paramTbodyRow.appendChild(paramTD);
paramTD = createEl('td');
if (headerData.params[k].optional) {
text = doc.createTextNode('no');
constructorParams.push('[' + headerData.params[k].name + ']');
} else {
text = doc.createTextNode('yes');
constructorParams.push(headerData.params[k].name);
}
paramTD.appendChild(text);
if (isDefined(headerData.params[k].description)) {
paramTbodyRow.appendChild(paramTD);
paramTD = createEl('td');
addText(paramTD, headerData.params[k].description.slice(3, headerData.params[k].description.indexOf('</p>')));
paramTbodyRow.appendChild(paramTD);
}
paramTbody.appendChild(paramTbodyRow);
}
topSection.appendChild(constructorParamsHeader);
topSection.appendChild(paramTable);
}
}
// add constructor params to signature if any
if (constructorParams.length > 0) {
text = doc.createTextNode(headerData.name + '( ' + constructorParams.join(',') + ' )');
} else {
text = doc.createTextNode(headerData.name + '()');
}
constructorCode.appendChild(text);
addText(description, headerData.description);
callback();
}
/**
* add the side nav
*/
function addIndex(callback) {
var section = createEl('section', {
id: 'index',
class: 'side-nav'
}),
navHeader = createEl('h2', {
class: 'sideNavHeader'
}),
navHeaderLink = createEl('a', {
href: 'index.html'
}),
memberIndex = createEl('div', {
id: 'memberIndex',
class: 'member-index'
}),
thisMember,
addedMembers = {},
item,
thisParent,
parentList,
header,
listItem,
listLink,
classHeader,
parentHeader,
i,
iMax,
j,
jMax,
// helper functions
classHasMembers = function (member) {
if (doc_data.thisClass[member].length > 0) {
return true;
}
return false;
},
parentsHaveMembers = function () {
if (doc_data.parentClasses.length > 0) {
for (i = 0; i < doc_data.parentClasses.length; i++) {
if (doc_data.parentClasses[i][thisMember].length > 0) {
return true;
}
}
return false;
}
},
makeList = function (classArr, parentArr, member, list) {
thisMember = member.toLowerCase();
if (classArr.length > 0 || (isDefined(doc_data.parentClass) && parentArr.length > 0)) {
// add member list header
if (classHasMembers(thisMember) || parentsHaveMembers(thisMember)) {
header = createEl('h3');
addText(header, doc_data.thisClass.headerInfo.name + ' ' + member);
} else {
return;
}
if (classHasMembers(thisMember)) {
classHeader = createEl('h4');
addText(classHeader, 'Class ' + member);
memberIndex.appendChild(header);
memberIndex.appendChild(classHeader);
// add the list & items
list = createEl('ul', {
id: list
});
memberIndex.appendChild(list);
iMax = classArr.length;
for (i = 0; i < iMax; i++) {
item = classArr[i].name;
if (!isItemInArray(addedMembers[member], item)) {
// keep track of added members to remove overridden ones
addedMembers[member].push(item);
listItem = createEl('li');
listLink = createEl('a', {
href: '#' + member + item
});
addText(listLink, item);
listItem.appendChild(listLink);
list.appendChild(listItem);
}
}
}
// add inherited items if any
if (isDefined(parentArr) && parentArr.length > 0) {
jMax = parentArr.length;
for (j = 0; j < jMax; j++) {
thisParent = parentArr[j];
if (thisParent[thisMember].length > 0) {
parentHeader = createEl('h4');
addText(parentHeader, 'Inherited ' + member + ' from ' + thisParent.headerInfo.name);
memberIndex.appendChild(parentHeader);
parentList = createEl('ul');
memberIndex.appendChild(parentList);
iMax = thisParent[thisMember].length;
for (i = 0; i < iMax; i++) {
item = thisParent[thisMember][i].name;
if (!isItemInArray(addedMembers[member], item)) {
addedMembers[member].push(item);
listItem = createEl('li');
listLink = createEl('a', {
href: '#' + member + item
});
listItem.appendChild(listLink);
addText(listLink, item);
parentList.appendChild(listItem);
}
}
}
}
}
}
};
// data structure to track members already added
addedMembers.Methods = [];
addedMembers.Properties = [];
addedMembers.Events = [];
navHeader.appendChild(navHeaderLink);
addText(navHeaderLink, 'API Index');
// add parent class members if any
if (isDefined(doc_data.parentClasses)) {
makeList(doc_data.thisClass.properties, doc_data.parentClasses, 'Properties', 'propertiesList');
makeList(doc_data.thisClass.methods, doc_data.parentClasses, 'Methods', 'methodsList');
makeList(doc_data.thisClass.events, doc_data.parentClasses, 'Events', 'eventsList');
} else {
makeList(doc_data.thisClass.properties, [], 'Properties', 'propertiesList');
makeList(doc_data.thisClass.methods, [], 'Methods', 'methodsList');
makeList(doc_data.thisClass.events, [], 'Events', 'eventsList');
}
section.appendChild(navHeader);
section.appendChild(memberIndex);
doc_body.appendChild(section);
callback();
}
/**
* add the member content
* @param {function} callback - function to call when done
*/
function addMembersContent(callback) {
var members = [{
name: 'Properties',
data: 'properties'
}, {
name: 'Methods',
data: 'methods'
}, {
name: 'Events',
data: 'events'
}],
member,
addedMembers = {},
section,
header,
headerSuffix,
item,
itemWrapper,
itemHeader,
itemHeaderStr,
itemParams = [],
itemParamsHeader,
itemDescription,
itemFooter,
itemFooterLink,
itemFooterContent,
paramTable,
paramThead,
paramTbody,
paramTheadRow,
paramTbodyRow,
paramTH,
paramTD,
paramTableHeaders = ['name', 'Type', 'Required', 'Description'],
text,
i,
iMax,
j,
jMax,
k,
kMax,
m,
mMax,
topLinkP,
topLinkA,
// helper function
createMemberItem = function (classData, member) {
// create the class member items
jMax = classData[member.data].length;
for (j = 0; j < jMax; j++) {
item = classData[member.data][j];
if (!isItemInArray(addedMembers[member.name], item.name)) {
addedMembers[member.name].push(item.name);
itemWrapper = createEl('div', {
id: member.name + item.name
});
section.appendChild(itemWrapper);
itemHeader = createEl('h3', {
id: item.name + 'Header'
});
itemHeaderStr = item.name;
itemWrapper.appendChild(itemHeader);
itemDescription = createEl('div', {
id: item.name + 'Description',
class: 'description'
});
itemWrapper.appendChild(itemDescription);
itemFooter = createEl('p', {
class: 'vjs-only'
});
itemFooterLink = createEl('a', {
href: docsPathStem + item.meta.path.substr(item.meta.path.lastIndexOf('/js')) + '/' + item.meta.filename + '#L' + item.meta.lineno
});
itemFooterContent = createEl('em', {
id: item.name + 'Footer'
});
itemFooter.appendChild(itemFooterContent);
topLinkP = createEl('p');
topLinkA = createEl('a', {
href: '#top'
});
addText(topLinkA, '[back to top]');
topLinkP.appendChild(topLinkA);
// for methods only handle params if any
if (member.name === 'Methods' && isDefined(item.params)) {
itemParams = [];
itemParamsHeader = createEl('h4');
addText(itemParamsHeader, 'Parameters');
paramTable = createEl('table');
paramThead = createEl('thead');
paramTbody = createEl('tbody');
paramTable.appendChild(paramThead);
paramTable.appendChild(paramTbody);
paramTheadRow = createEl('tr');
paramThead.appendChild(paramTheadRow);
// set the table headers
kMax = paramTableHeaders.length;
for (k = 0; k < kMax; k++) {
paramTH = createEl('th');
paramTheadRow.appendChild(paramTH);
addText(paramTH, paramTableHeaders[k]);
}
// now the table info
kMax = item.params.length;
for (k = 0; k < kMax; k++) {
paramTbodyRow = createEl('tr');
paramTbody.appendChild(paramTbodyRow);
paramTD = createEl('td');
addText(paramTD, item.params[k].name);
paramTbodyRow.appendChild(paramTD);
paramTD = createEl('td');
addText(paramTD, item.params[k].type.names.join('|'));
paramTbodyRow.appendChild(paramTD);
paramTD = createEl('td');
if (item.params[k].optional) {
text = doc.createTextNode('no');
itemParams.push('[' + item.params[k].name + ']');
} else {
text = doc.createTextNode('yes');
itemParams.push(item.params[k].name);
}
paramTD.appendChild(text);
if (isDefined(item.params[k].description)) {
paramTbodyRow.appendChild(paramTD);
paramTD = createEl('td');
addText(paramTD, item.params[k].description.slice(3, item.params[k].description.indexOf('</p>')));
paramTbodyRow.appendChild(paramTD);
}
paramTbody.appendChild(paramTbodyRow);
}
itemHeaderStr += '( ' + itemParams.join(', ') + ' )';
if (item.scope === 'static') {
itemHeaderStr = 'static ' + itemHeaderStr;
}
itemWrapper.appendChild(itemParamsHeader);
itemWrapper.appendChild(paramTable);
} else if (member.name === 'Methods') {
itemHeaderStr += '()';
}
itemWrapper.appendChild(itemFooter);
itemWrapper.appendChild(topLinkP);
addText(itemHeader, itemHeaderStr);
if (isDefined(item.deprecated)) {
headerSuffix = createEl('em', {
class: 'deprecated'
});
text = doc.createTextNode();
addText(headerSuffix, ' (deprecated)');
itemHeader.appendChild(headerSuffix);
}
addText(itemDescription, item.description);
addText(itemFooterContent, 'Defined in ');
itemFooterContent.appendChild(itemFooterLink);
addText(itemFooterLink, docsPathStem + item.meta.path.substr(item.meta.path.lastIndexOf('/js')) + '/' + item.meta.filename + ' line number: ' + item.meta.lineno);
}
}
};
// data structure to track members already added
addedMembers.Methods = [];
addedMembers.Properties = [];
addedMembers.Events = [];
iMax = members.length;
for (i = 0; i < iMax; i++) {
member = members[i];
if (doc_data.thisClass[member.data].length > 0) {
// create the member section
section = createEl('section', {
id: member.name.toLowerCase(),
class: 'section'
});
main.appendChild(section);
header = createEl('h2');
addText(header, member.name);
section.appendChild(header);
// create the member items
createMemberItem(doc_data.thisClass, member);
if (isDefined(doc_data.parentClasses)) {
mMax = doc_data.parentClasses.length;
for (m = 0; m < mMax; m++) {
if (doc_data.parentClasses[m][member.data].length > 0) {
createMemberItem(doc_data.parentClasses[m], member);
}
}
}
}
}
callback();
}
/**
* gets things going
* @param {string} docFileName - name of the HTML doc we're building
* @param {function} callback - function to call when done
*/
function contentInit(docFileName, callback) {
var fileName,
parent_class_name,
privateItems = [],
srcFileName,
idx,
text,
j,
parentCounter = 0,
// helper function to get the chain of parent classes
getAncestorData = function (parent_class) {
// get data objects for the class
classes.parentClasses[parentCounter] = findClassObjects(docData, parent_class + '.js');
// check to see if there are any parent class items
if (classes.parentClasses[parentCounter].length > 0) {
doc_data.parentClasses[parentCounter] = {};
// get parent header info
idx = findObjectInArray(classes.parentClasses[parentCounter], 'kind', 'class');
doc_data.parentClasses[parentCounter].headerInfo = copyObj(classes.parentClasses[parentCounter][idx]);
// get parent class path
idx = findObjectInArray(classes.parentClasses[parentCounter], 'kind', 'file');
if (idx > -1) {
parentClassFilePath = classes.parentClasses[parentCounter][idx].name;
} else {
parentClassFilePath = doc_data.parentClasses[parentCounter].headerInfo.meta.filename;
}
// remove any private items
privateItems = findObjectsInArray(classes.parentClasses[parentCounter], 'access', 'private');
j = privateItems.length;
while (j > 0) {
j--;
classes.parentClasses[parentCounter].splice(privateItems[j], 1);
}
// now get the member arrays
doc_data.parentClasses[parentCounter].methods = getSubArray(classes.parentClasses[parentCounter], 'kind', 'function');
doc_data.parentClasses[parentCounter].methods = sortArray(doc_data.parentClasses[parentCounter].methods, 'name');
doc_data.parentClasses[parentCounter].events = getSubArray(classes.parentClasses[parentCounter], 'kind', 'event');
doc_data.parentClasses[parentCounter].events = sortArray(doc_data.parentClasses[parentCounter].events, 'name');
doc_data.parentClasses[parentCounter].properties = getSubArray(classes.parentClasses[parentCounter], 'kind', 'property');
doc_data.parentClasses[parentCounter].properties = sortArray(doc_data.parentClasses[parentCounter].properties, 'name');
}
// get parent class, if any, and anything it inherits
if (isDefined(doc_data.parentClasses[parentCounter].headerInfo.augments)) {
idx = findObjectInArray(docData, 'name', doc_data.parentClasses[parentCounter].headerInfo.augments[0]);
parent_class_name = docData[idx].meta.filename.replace('.js', '');
parentCounter++;
getAncestorData(parent_class_name);
}
};
// get reference to doc body and title
doc_body = doc.getElementsByTagName('body')[0];
title = doc.getElementsByTagName('title')[0];
// content wrapper
mainContent = createEl('div', {
id: 'main',
class: 'section'
});
// src file is the js file of the same name
srcFileName = docFileName.replace('.html', '.js');
// video.js is a special case - all others will be the same
if (srcFileName === 'video.js') {
// for doc purposes, treat video like a class, though it's not
// get the data objects for this class
classes.thisClass = findClassObjects(docData, srcFileName);
idx = findObjectInArray(classes.thisClass, 'name', 'videojs');
doc_data.thisClass = {};
// get the class overview object
doc_data.thisClass.headerInfo = copyObj(classes.thisClass[idx]);
doc_data.thisClass.headerInfo.name = 'videojs';
idx = findObjectInArray(classes.thisClass, 'kind', 'file');
if (idx > -1) {
classFilePath = classes.thisClass[idx].name;
} else {
classFilePath = doc_data.thisClass.headerInfo.meta.filename;
}
// get docsFolder to complete path for links to src
docsFolder = classes.thisClass[idx].meta.path.substr(doc_data.thisClass.headerInfo.meta.path.lastIndexOf('/js')) + '/';
// set the doc title
text = doc.createTextNode(doc_data.thisClass.headerInfo.name);
title.appendChild(text);
// remove any private items
privateItems = findObjectsInArray(classes.thisClass, 'access', 'private');
j = privateItems.length;
while (j > 0) {
j--;
classes.thisClass.splice(privateItems[j], 1);
}
// now get the member arrays
doc_data.thisClass.methods = getSubArray(classes.thisClass, 'kind', 'function');
doc_data.thisClass.methods = sortArray(doc_data.thisClass.methods, 'name');
doc_data.thisClass.events = getSubArray(classes.thisClass, 'kind', 'event');
doc_data.thisClass.events = sortArray(doc_data.thisClass.events, 'name');
doc_data.thisClass.properties = getSubArray(classes.thisClass, 'kind', 'property');
doc_data.thisClass.properties = sortArray(doc_data.thisClass.properties, 'name');
} else {
// get the data objects for this class
classes.thisClass = findClassObjects(docData, srcFileName);
idx = findObjectInArray(classes.thisClass, 'kind', 'class');
doc_data.thisClass = {};
doc_data.thisClass.headerInfo = copyObj(classes.thisClass[idx]);
// get the file path from @file object
idx = findObjectInArray(classes.thisClass, 'kind', 'file');
if (idx > -1) {
classFilePath = classes.thisClass[idx].name;
} else {
classFilePath = doc_data.thisClass.headerInfo.meta.filename;
}
// get docsFolder to complete path for links to src
docsFolder = doc_data.thisClass.headerInfo.meta.path.substr(doc_data.thisClass.headerInfo.meta.path.lastIndexOf('/js')) + '/';
// set the doc title
text = doc.createTextNode(doc_data.thisClass.headerInfo.name);
title.appendChild(text);
// remove any private items
privateItems = findObjectsInArray(classes.thisClass, 'access', 'private');
j = privateItems.length;
while (j > 0) {
j--;
classes.thisClass.splice(privateItems[j], 1);
}
// now get the member arrays
doc_data.thisClass.methods = getSubArray(classes.thisClass, 'kind', 'function');
doc_data.thisClass.methods = sortArray(doc_data.thisClass.methods, 'name');
doc_data.thisClass.events = getSubArray(classes.thisClass, 'kind', 'event');
doc_data.thisClass.events = sortArray(doc_data.thisClass.events, 'name');
doc_data.thisClass.properties = getSubArray(classes.thisClass, 'kind', 'property');
doc_data.thisClass.properties = sortArray(doc_data.thisClass.properties, 'name');
// get parent class, if any, and anything it inherits
if (isDefined(doc_data.thisClass.headerInfo.augments)) {
doc_data.parentClass = {};
doc_data.parentClasses = [];
classes.parentClasses = [];
idx = findObjectInArray(docData, 'name', doc_data.thisClass.headerInfo.augments[0]);
parent_class_name = docData[idx].meta.filename.replace('.js', '');
getAncestorData(parent_class_name);
}
}
// now we're ready to roll
addIndex(function () {
addHeaderContent(function () {
addMembersContent(function () {
// add scripts to highlight syntax in code blocks
var highlighter = createEl('script', {src: '//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js'});
addText(highlighter, '\n // syntax highlighter for code samples \n');
doc_body.appendChild(highlighter);
highlighter = createEl('script', {src: './js/highlight-syntax.js'});
addText(highlighter, '\n // activates syntax highlighting \n');
doc_body.appendChild(highlighter);
// now we're ready to write the file
callback();
});
});
});
}
});
// Default task.
grunt.registerTask('no-clone', ['shell:generateJSON', 'copy:guides', 'copy:examples', 'copy:fontawesome', 'markdown', 'clean', 'concat', 'uglify', 'createFiles']);
grunt.registerTask('default', ['shell:cloneVideoJS', 'no-clone']);
};