From 90e0d62629467e350b06c118f73cdb5eabec2c02 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 13 Jan 2024 16:24:34 -0500 Subject: [PATCH] add typedefs and default values to docs --- JS/HTMLGeneration.js | 21 +++++++++++++++++++++ JS/navigation.js | 15 +++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/JS/HTMLGeneration.js b/JS/HTMLGeneration.js index 256a126..29e5219 100644 --- a/JS/HTMLGeneration.js +++ b/JS/HTMLGeneration.js @@ -116,6 +116,11 @@ const genParam = (param) => { let typeSpan = evalLinks(param.type, true); paramSpan.appendChild(typeSpan); + if (param.default_value) { + paramSpan.appendText(" = ", "punctuation"); + paramSpan.appendText(param.default_value, "default-value"); + } + return paramSpan; } @@ -151,6 +156,16 @@ const genFunctionSummary = (node) => { return functionSpan; } +const genTypedefSummary = (child) => { + let typedefSpan = document.createElement('span'); + typedefSpan.classList.add('typedef'); + typedefSpan.appendText("typedef ", "keyword"); + typedefSpan.appendText(child.name); + typedefSpan.appendText(" = ", "punctuation"); + typedefSpan.appendChild(evalLinks(child.type)); + return typedefSpan; +} + const genVariable = (node) => { let variableSpan = document.createElement('span'); variableSpan.classList.add('variable'); @@ -293,3 +308,9 @@ const genFunction = (node) => { return functionDiv; } + +const genTypedef = (node) => { + let div = document.createElement('div'); + div.appendChild(genTypedefSummary(node)); + return div; +} diff --git a/JS/navigation.js b/JS/navigation.js index 4857d9b..5d12773 100644 --- a/JS/navigation.js +++ b/JS/navigation.js @@ -15,6 +15,7 @@ const nodeMap = new Map([ ["unions", "Unions"], ["functions", "Functions"], ["methods", "Methods"], + ["typedefs", "TypeDefs"], ]) window.addEventListener('hashchange', (event) => { @@ -91,6 +92,13 @@ function addFunctionMethodContent(node, title) { }) } +function addTypedefContent(node, title) { + main.appendChild(genHeader(title)) + Object.values(node).forEach((child) => { + main.appendChild(genTypedefSummary(child)); + }); +} + function addMainContent(node) { genSourceLink(node.source) if (node.description) { @@ -122,6 +130,10 @@ function addMainContent(node) { main.appendChild(genFunction(node)); main.appendChild(document.createElement('br')) break; + case "typedef": + main.appendChild(genTypedef(node)); + main.appendChild(document.createElement('br')) + break; } nodeMap.forEach((value, key) => { @@ -146,6 +158,9 @@ function addMainContent(node) { case "methods": addFunctionMethodContent(node[key], value); break; + case "typedefs": + addTypedefContent(node[key], value); + break; default: console.log(node); }