From e436f65d4c7f07b27dd32af454c0973f0cc6fd3f Mon Sep 17 00:00:00 2001 From: milad Date: Sun, 20 May 2018 23:32:18 -0700 Subject: [PATCH] reworking gravprep to fix most links and oddities --- tools/jsdoc/gravPrep.js | 173 +++++++++++++++++++++++----------------- 1 file changed, 100 insertions(+), 73 deletions(-) diff --git a/tools/jsdoc/gravPrep.js b/tools/jsdoc/gravPrep.js index 96141da937..a58ad43b15 100644 --- a/tools/jsdoc/gravPrep.js +++ b/tools/jsdoc/gravPrep.js @@ -74,7 +74,7 @@ const html_reg_propertiesHeaderEdit_Replace = '

Properties

'; const html_reg_typeEdit = /(
Returns[\s\S]*?Type)(<\/dt[\s\S]*?type">)(.*?)(<\/span><\/dd>[\s\S]*?<\/dl>)/g; const html_reg_typeEdit_replace = '$1: $3' - const html_reg_methodSize = /()(<\/h4>)/g; + const html_reg_methodSize = /()/g; const html_reg_methodSize_replace = ''; const html_reg_typeDefSize = /()/g; const html_reg_typeDefSize_replace = ''; @@ -85,12 +85,14 @@ const html_reg_findByName = '
` const html_reg_findByArticleOpen = `
` const html_reg_findByArticleClose = `
` const html_reg_signalTitle = `

Signals

`; - const html_reg_typeDefinitonsTitle = `

Type Definitions

`; - const html_reg_firstTableClose = ``; + const html_reg_typeDefinitonsTitle = /

Type Definitions<\/h3>/; + const html_reg_typeDefinitonsTitle_replace = `

Type Definitions

` + const html_reg_firstDivClose = ``; const html_reg_fixLinkHashIssue = /()/g; const html_reg_fixLinkHashIssue_replace = "$1$2#$4" const html_reg_findLinks = /( curEndSplitTermIndex) { curIndex = content.indexOf(searchTerm); - console.log("curIndex", curIndex) - console.log("curEndSplitTermIndex", curEndSplitTermIndex) foundArray.push(content.slice(curIndex, curEndSplitTermIndex)) - console.log("foundArray[curfoundArrayIndex],", foundArray[curfoundArrayIndex],) content = content.replace(foundArray[curfoundArrayIndex], ""); break; } @@ -468,11 +462,9 @@ } // Split the signals and methods [Might make this more generic] - function splitMethodsSignalsAndTypeDefs(allItemToSplit){ + function splitMethodsSignals(allItemToSplit){ let methodArray = []; let signalArray = []; - let typeDefArray = []; - let description; allItemToSplit.forEach( (content, index) => { // console.log("content", content); @@ -482,25 +474,13 @@ // console.log("### FOUND SIGNAL", content); signalArray.push(content); } else if (firstLine.indexOf("span") > -1) { - // console.log("### FOUND SPAN", content); - if (content.indexOf("Available in:") > -1){ - // console.log("### DESCRIPTION", content); - description = content; - } else { - // console.log("### METHOD", content); - methodArray.push(content); - } + // console.log("### METHOD", content); + methodArray.push(content); } else { - // console.log("### TYPEDEF", content); - if(firstLine.trim() !== ""){ - // console.log("### TYPEDEF", content); - typeDefArray.push(content); - } else { - // console.log("not handled", content); - } + // console.log("not handled", content); } }) - return [methodArray, signalArray, typeDefArray, description]; + return [methodArray, signalArray]; } // Helper to append @@ -508,7 +488,9 @@ // and bool if the append is before the found area function append(content, searchTermToAppendto, contentToAppend, appendBefore){ let contentArray = content.split("\n"); + console.log("contentArray", contentArray); let foundIndex = findArrayTrim(contentArray, searchTermToAppendto) + console.log("foundIndex", foundIndex) foundIndex = appendBefore ? foundIndex : foundIndex +1 contentArray.splice(foundIndex,0,contentToAppend) @@ -618,58 +600,80 @@ // Further HTML Manipulation // Make end term either Type Definitions or by the article - let endTerm = html_reg_findByArticleClose; + let endTerm; + let foundTypeDefinitions; + let foundSignalsAndMethods; if (currentContent.indexOf("Type Definitions") > -1){ - console.log("Found Type Definitions") - endTerm = `

Type Definitions

` + console.log("Found Type Definitions"); + endTerm = `

Type Definitions

`; + // Split HTML by Each named entry + let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm); + foundSignalsAndMethods = contentSplitArray[1]; + // Create a reference to the current content after split and the split functions + currentContent = contentSplitArray[0] + .replace(html_reg_typeDefinitonsTitle, ""); // Remove Type Definitions Title to be remade later; + endTerm = html_reg_findByArticleClose; + // Grab split Type Definitions + let contentSplitArrayForTypeDefs = splitBy(currentContent, html_reg_findByName, endTerm); + currentContent = contentSplitArrayForTypeDefs[0]; + foundTypeDefinitions = contentSplitArrayForTypeDefs[1]; + } else { + endTerm = html_reg_findByArticleClose; + let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm); + foundSignalsAndMethods = contentSplitArray[1]; + currentContent = contentSplitArray[0]; } - // Split HTML by Each named entry - let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm); - - // Create a reference to the current content after split and the split functions - currentContent = contentSplitArray[0] - .replace(html_reg_typeDefinitonsTitle, "") // Remove Type Definitions Title to be remade later; - // Create references to the split methods and signals - let processedMethodsSignalsAndTypeDefs = splitMethodsSignalsAndTypeDefs(contentSplitArray[1]); - // let splitMethods = processedMethodsSignalsAndTypeDefs[0]; - // let splitSignals = processedMethodsSignalsAndTypeDefs[1]; - // let splitTypeDefintions = processedMethodsSignalsAndTypeDefs[2]; + + let processedMethodsSignalsAndTypeDefs = splitMethodsSignals(foundSignalsAndMethods); + let splitMethods = processedMethodsSignalsAndTypeDefs[0]; + let splitSignals = processedMethodsSignalsAndTypeDefs[1]; + let splitTypeDefinitionIDS; // let splitDescription = processedMethodsSignalsAndTypeDefs[3]; - // let splitMethodIDS = extractIDs(splitMethods); - // let splitSignalIDS = extractIDs(splitSignals); - // let splitTypeDefinitionIDS = extractIDs(splitTypeDefintions); + // console.log("getting split Methods") + let splitMethodIDS = extractIDs(splitMethods); + // console.log("getting split Signals") + let splitSignalIDS = extractIDs(splitSignals); + if (foundTypeDefinitions){ + // console.log("getting split typeDefs") + splitTypeDefinitionIDS = extractIDs(foundTypeDefinitions); + } let arrayToPassToClassToc = []; // if (splitDescription) { // currentContent = append(currentContent, html_reg_containerOverview, splitDescription); // } - // if (splitMethods.length > 0) { - // arrayToPassToClassToc.push({type: "Methods", array: splitMethodIDS}); - // // Add the Signals header to the Signals HTML - // splitMethods.unshift(html_reg_findByMethod) - // currentContent = append(currentContent, html_reg_findByArticleClose, splitMethods.join('\n'), true); - // } - // if (splitSignals.length > 0) { - // arrayToPassToClassToc.push({type: "Signals", array: splitSignalIDS}); - // // Add the Signals header to the Signals HTML - // splitSignals.unshift(html_reg_signalTitle) - // currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n'),true); - // } - // if (splitTypeDefintions.length > 0) { - // arrayToPassToClassToc.push({type: "Type Definitions", array: splitTypeDefinitionIDS}); - // // Add the Signals header to the Signals HTML - // splitTypeDefintions.unshift(html_reg_typeDefinitonsTitle) - // currentContent = append(currentContent, html_reg_findByArticleClose, splitTypeDefintions.join('\n'), true); - // } + if (splitMethods.length > 0) { + arrayToPassToClassToc.push({type: "Methods", array: splitMethodIDS}); + // Add the Signals header to the Signals HTML + splitMethods.unshift(html_reg_findByMethod_replace) + console.log("appending methods") + currentContent = append(currentContent, html_reg_findByArticleClose, splitMethods.join('\n'), true); + } + if (splitSignals.length > 0) { + arrayToPassToClassToc.push({type: "Signals", array: splitSignalIDS}); + // Add the Signals header to the Signals HTML + splitSignals.unshift(html_reg_signalTitle) + console.log("appending signals") + currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n'),true); + } + if (foundTypeDefinitions && foundTypeDefinitions.length > 0) { + arrayToPassToClassToc.push({type: "Type Definitions", array: splitTypeDefinitionIDS}); + // Add the Signals header to the Signals HTML + foundTypeDefinitions.unshift(html_reg_typeDefinitonsTitle_replace) + console.log("appending typedefs") + currentContent = append(currentContent, html_reg_findByArticleClose, foundTypeDefinitions.join('\n'), true); + } - // let classTOC = makeClassTOC(arrayToPassToClassToc); - // if (groupName === "Global"){ - // currentContent = append(currentContent, html_reg_findByTitle, classTOC); - // } else { - // currentContent = append(currentContent, html_reg_firstTableClose, classTOC); - // } + let classTOC = makeClassTOC(arrayToPassToClassToc); + if (groupName === "Global"){ + console.log("appending global toc") + currentContent = append(currentContent, html_reg_findByTitle, classTOC); + } else { + console.log("appending normal toc") + currentContent = append(currentContent, html_reg_firstDivClose, classTOC); + } // Final Pretty Content currentContent = htmlclean(currentContent); @@ -722,3 +726,26 @@ } copyFolderRecursiveSync(dir_md, targetMDDirectory); } + + + // function splitTypeDefs(allItemToSplit){ + // let typeDefArray = []; + // allItemToSplit.forEach( (content, index) => { + // firstLine = content.split("\n")[0]; + // if (firstLine.indexOf("{Signal}") > -1){ + // signalArray.push(content); + // } else if (firstLine.indexOf("span") > -1) { + // if (content.indexOf("Available in:") > -1){ + // description = content; + // } else { + // methodArray.push(content); + // } + // } else { + // if(firstLine.trim() !== ""){ + // typeDefArray.push(content); + // } else { + // } + // } + // }) + // return [methodArray, signalArray, typeDefArray, description]; + // } \ No newline at end of file