@tinymce/moxiedoc
Advanced tools
Comparing version 0.2.2-feature.20220725071105651.sha5bda993 to 0.2.2-feature.20220808075242229.sha7690926
@@ -6,2 +6,10 @@ "use strict"; | ||
const BASE_PATH = process.env.BASE_PATH || '/_data/antora'; | ||
const namespaceDescriptions = { | ||
'tinymce': 'Global APIs for working with the editor.', | ||
'tinymce.dom': 'APIs for working with the DOM from within the editor.', | ||
'tinymce.editor.ui': 'APIs for registering User Interface components.', | ||
'tinymce.geom': 'Various rectangle APIs.', | ||
'tinymce.html': 'APIs for working with HTML within the editor.', | ||
'tinymce.util': 'Browser related APIs.' | ||
}; | ||
const generateNavPages = (sortedTypes, structure) => { | ||
@@ -24,3 +32,3 @@ const nav = getNavFile(sortedTypes, structure); | ||
case 'legacy': | ||
return generateIndexPages(newNavPages, indexPage, structure); | ||
return generateIndexPages(newNavPages, indexPage, sortedTypes, structure); | ||
case 'default': | ||
@@ -53,8 +61,2 @@ return newNavPages; | ||
}); | ||
if (url === 'tinymce') { | ||
innerPages.unshift({ | ||
title: 'tinymce', | ||
path: getRootPath(structure) | ||
}); | ||
} | ||
return { | ||
@@ -87,8 +89,9 @@ title, | ||
}; | ||
const generateIndexPages = (newNavPages, indexPage, structure) => { | ||
const generateIndexPages = (newNavPages, indexPage, sortedTypes, structure) => { | ||
indexPage.pages.forEach((namespace) => { | ||
const descriptions = getDescriptionsFromTypes(sortedTypes); | ||
newNavPages.push({ | ||
type: 'adoc', | ||
filename: BASE_PATH + '/api/' + namespace.path + '/index.adoc', | ||
content: indexToAdoc(namespace, structure) | ||
content: indexToAdoc(namespace, descriptions, structure) | ||
}); | ||
@@ -98,4 +101,5 @@ }); | ||
}; | ||
const indexToAdoc = (namespace, structure) => { | ||
let adoc = '= ' + namespace.title + '\n\n'; | ||
const indexToAdoc = (namespace, descriptions, structure) => { | ||
let adoc = '= ' + namespace.title + '\n'; | ||
adoc += '==' + namespaceDescriptions[namespace.title.toLowerCase()] + '\n\n'; | ||
adoc += '[cols="1,1"]\n'; | ||
@@ -107,3 +111,5 @@ adoc += '|===\n\n'; | ||
adoc += '[.lead]\n'; | ||
adoc += pageFileLine(pageFile, structure) + '\n\n'; | ||
adoc += pageFileLine(pageFile, structure) + '\n'; | ||
const description = descriptions[pageFile.path]; | ||
adoc += description + '\n\n'; | ||
}); | ||
@@ -125,2 +131,11 @@ } | ||
}; | ||
const getDescriptionsFromTypes = (types) => { | ||
return types.reduce((descriptions, type) => { | ||
const name = type.fullName.toLowerCase(); | ||
if (name && !descriptions[name]) { | ||
descriptions[name] = type.desc; | ||
} | ||
return descriptions; | ||
}, {}); | ||
}; | ||
const getRootPath = (structure) => { | ||
@@ -143,7 +158,9 @@ switch (structure) { | ||
const pageFileLine = (pageFile, structure) => { | ||
const fileName = (pageFile.path === 'tinymce' ? getRootPath(structure) : pageFile.path) + '.adoc'; | ||
switch (structure) { | ||
case 'legacy': | ||
return generateNavXref('api/' + getNamespaceFromFullName(pageFile.path), pageFile.path + '.adoc', pageFile.title); | ||
const folder = getNamespaceFromFullName(pageFile.path); | ||
return generateNavXref('api/' + folder, fileName, pageFile.title); | ||
case 'default': | ||
return generateNavXref('apis', pageFile.path + '.adoc', pageFile.title); | ||
return generateNavXref('apis', fileName, pageFile.title); | ||
} | ||
@@ -150,0 +167,0 @@ }; |
{ | ||
"name": "@tinymce/moxiedoc", | ||
"version": "0.2.2-feature.20220725071105651.sha5bda993", | ||
"version": "0.2.2-feature.20220808075242229.sha7690926", | ||
"description": "A tool for generating API documentation", | ||
@@ -5,0 +5,0 @@ "author": "Tiny Technologies, Inc", |
@@ -20,2 +20,11 @@ import * as YAML from 'js-yaml'; | ||
const namespaceDescriptions = { | ||
'tinymce': 'Global APIs for working with the editor.', | ||
'tinymce.dom': 'APIs for working with the DOM from within the editor.', | ||
'tinymce.editor.ui': 'APIs for registering User Interface components.', | ||
'tinymce.geom': 'Various rectangle APIs.', | ||
'tinymce.html': 'APIs for working with HTML within the editor.', | ||
'tinymce.util': 'Browser related APIs.' | ||
}; | ||
const generateNavPages = (sortedTypes: Type[], structure: ExportStructure): PageOutput[] => { | ||
@@ -41,3 +50,3 @@ const nav = getNavFile(sortedTypes, structure); | ||
case 'legacy': | ||
return generateIndexPages(newNavPages, indexPage, structure); | ||
return generateIndexPages(newNavPages, indexPage, sortedTypes, structure); | ||
@@ -74,9 +83,2 @@ case 'default': | ||
if (url === 'tinymce') { | ||
innerPages.unshift({ | ||
title: 'tinymce', | ||
path: getRootPath(structure) | ||
}); | ||
} | ||
return { | ||
@@ -112,8 +114,9 @@ title, | ||
const generateIndexPages = (newNavPages: PageOutput[], indexPage: NavFile, structure: ExportStructure): PageOutput[] => { | ||
const generateIndexPages = (newNavPages: PageOutput[], indexPage: NavFile, sortedTypes: Type[], structure: ExportStructure): PageOutput[] => { | ||
indexPage.pages.forEach((namespace) => { | ||
const descriptions = getDescriptionsFromTypes(sortedTypes); | ||
newNavPages.push({ | ||
type: 'adoc', | ||
filename: BASE_PATH + '/api/' + namespace.path + '/index.adoc', | ||
content: indexToAdoc(namespace, structure) | ||
content: indexToAdoc(namespace, descriptions, structure) | ||
}); | ||
@@ -124,4 +127,5 @@ }); | ||
const indexToAdoc = (namespace: NavFile, structure: ExportStructure): string => { | ||
let adoc = '= ' + namespace.title + '\n\n'; | ||
const indexToAdoc = (namespace: NavFile, descriptions: Record<string, string>, structure: ExportStructure): string => { | ||
let adoc = '= ' + namespace.title + '\n'; | ||
adoc += '==' + namespaceDescriptions[namespace.title.toLowerCase()] + '\n\n'; | ||
adoc += '[cols="1,1"]\n'; | ||
@@ -133,3 +137,5 @@ adoc += '|===\n\n'; | ||
adoc += '[.lead]\n'; | ||
adoc += pageFileLine(pageFile, structure) + '\n\n'; | ||
adoc += pageFileLine(pageFile, structure) + '\n'; | ||
const description = descriptions[pageFile.path]; | ||
adoc += description + '\n\n'; | ||
}); | ||
@@ -153,2 +159,12 @@ } | ||
const getDescriptionsFromTypes = (types: Type[]): Record<string, string> => { | ||
return types.reduce((descriptions: Record<string, string>, type: Type) => { | ||
const name = type.fullName.toLowerCase(); | ||
if (name && !descriptions[name]) { | ||
descriptions[name] = type.desc; | ||
} | ||
return descriptions; | ||
}, {}); | ||
}; | ||
const getRootPath = (structure: ExportStructure): string => { | ||
@@ -175,8 +191,10 @@ switch (structure) { | ||
const pageFileLine = (pageFile: NavFile, structure: ExportStructure): string => { | ||
const fileName = (pageFile.path === 'tinymce' ? getRootPath(structure) : pageFile.path) + '.adoc'; | ||
switch (structure) { | ||
case 'legacy': | ||
return generateNavXref('api/' + getNamespaceFromFullName(pageFile.path), pageFile.path + '.adoc', pageFile.title); | ||
const folder = getNamespaceFromFullName(pageFile.path); | ||
return generateNavXref('api/' + folder, fileName, pageFile.title); | ||
case 'default': | ||
return generateNavXref('apis', pageFile.path + '.adoc', pageFile.title); | ||
return generateNavXref('apis', fileName, pageFile.title); | ||
} | ||
@@ -183,0 +201,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
362412
6891