@tinymce/moxiedoc
Advanced tools
Comparing version 0.2.0-feature.20220218054734314.sha231e752 to 0.2.0-feature.20220218062203506.sha55c37e0
import { Param, ParamData } from './param'; | ||
import { Target } from './target'; | ||
import { Type } from './type'; | ||
interface ReturnType { | ||
export interface Return { | ||
readonly types: string[]; | ||
@@ -11,3 +11,3 @@ readonly desc: string; | ||
readonly mixType?: string; | ||
readonly return?: ReturnType; | ||
readonly return?: Return; | ||
readonly staticLink?: boolean; | ||
@@ -27,3 +27,3 @@ readonly type?: string; | ||
mixType: string; | ||
return: ReturnType; | ||
return: Return; | ||
staticLink: boolean; | ||
@@ -30,0 +30,0 @@ type: string; |
@@ -35,7 +35,2 @@ "use strict"; | ||
}; | ||
// runs a bunch of required cleanup filters, where embedded code/text can break asciidoc rendering | ||
const cleanup = (str) => { | ||
const filters = [escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode]; | ||
return filters.reduce((acc, filter) => filter(acc), str); | ||
}; | ||
// convert <a href> into asciidoc link | ||
@@ -52,6 +47,36 @@ const encodeLinks = (str) => { | ||
}; | ||
// runs a bunch of required cleanup filters, where embedded code/text can break asciidoc rendering | ||
const cleanup = (str) => { | ||
const filters = [escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode]; | ||
return filters.reduce((acc, filter) => filter(acc), str); | ||
}; | ||
const getNameFromFullName = (name) => name.split('.').slice(-1).join(''); | ||
const generateTypeLink = (type) => type.includes('tinymce', 0) ? 'link:' + baseURL + type.toLowerCase() + '.html[' + getNameFromFullName(type) + ']' : type; | ||
const generateDefinedByLink = (definedBy) => 'link:' + baseURL + definedBy.toLowerCase() + '.html[' + getNameFromFullName(definedBy) + ']'; | ||
const generateSummary = (data) => { | ||
const generateExamples = (examples) => { | ||
let tmp = '\n==== Examples\n'; | ||
examples.forEach((example) => { | ||
tmp += '[source, javascript]\n'; | ||
tmp += '----\n'; | ||
tmp += example.content + '\n'; | ||
tmp += '----\n'; | ||
}); | ||
return tmp; | ||
}; | ||
const generateParameters = (params) => { | ||
let tmp = '\n==== Parameters\n'; | ||
params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
return tmp + '\n'; | ||
}; | ||
const generateReturn = (ret) => { | ||
let tmp = '\n==== Return value\n'; | ||
ret.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeLink(type) + '` - ' + cleanup(ret.desc); | ||
}); | ||
tmp += '\n'; | ||
return tmp; | ||
}; | ||
const buildSummary = (data) => { | ||
let tmp = ''; | ||
@@ -132,3 +157,3 @@ // settings | ||
}; | ||
const generateConstructor = (data) => { | ||
const buildConstructor = (data) => { | ||
let tmp = ''; | ||
@@ -147,24 +172,9 @@ if (hasValue(data.constructors)) { | ||
if (hasValue(constructor.examples)) { | ||
tmp += '\n==== Examples\n'; | ||
constructor.examples.forEach((example) => { | ||
tmp += '[source, javascript]\n'; | ||
tmp += '----\n'; | ||
tmp += example.content + '\n'; | ||
tmp += '----\n'; | ||
}); | ||
tmp += '\n'; | ||
tmp += generateExamples(constructor.examples); | ||
} | ||
if (hasValue(constructor.params)) { | ||
tmp += '\n==== Parameters'; | ||
constructor.params.forEach((param) => { | ||
tmp += '\n* `' + param.name + '` `(' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateParameters(constructor.params); | ||
} | ||
if (hasValue(constructor.return) && hasValue(constructor.return.types)) { | ||
// untested - no data | ||
constructor.return.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeLink(type) + '` - ' + cleanup(constructor.return.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateReturn(constructor.return); | ||
} | ||
@@ -175,3 +185,3 @@ }); | ||
}; | ||
const generateMethods = (data) => { | ||
const buildMethods = (data) => { | ||
let tmp = ''; | ||
@@ -190,23 +200,9 @@ if (hasValue(data.methods)) { | ||
if (hasValue(method.examples)) { | ||
tmp += '\n==== Examples\n'; | ||
method.examples.forEach((example) => { | ||
tmp += '[source, javascript]\n'; | ||
tmp += '----\n'; | ||
tmp += example.content + '\n'; | ||
tmp += '----\n'; | ||
}); | ||
tmp += generateExamples(method.examples); | ||
} | ||
if (hasValue(method.params)) { | ||
tmp += '\n==== Parameters\n'; | ||
method.params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateParameters(method.params); | ||
} | ||
if (hasValue(method.return) && hasValue(method.return.types)) { | ||
tmp += '\n==== Return value\n'; | ||
method.return.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeLink(type) + '` - ' + cleanup(method.return.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateReturn(method.return); | ||
} | ||
@@ -218,3 +214,3 @@ tmp += `\n'''\n`; | ||
}; | ||
const generateEvents = (data) => { | ||
const buildEvents = (data) => { | ||
let tmp = ''; | ||
@@ -230,7 +226,3 @@ // untested snippet, no events data | ||
if (hasValue(event.params)) { | ||
tmp += '\n==== Parameters\n'; | ||
event.params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateParameters(event.params); | ||
} | ||
@@ -281,6 +273,6 @@ }); | ||
} | ||
tmp += generateSummary(data); | ||
tmp += generateConstructor(data); | ||
tmp += generateMethods(data); | ||
tmp += generateEvents(data); | ||
tmp += buildSummary(data); | ||
tmp += buildConstructor(data); | ||
tmp += buildMethods(data); | ||
tmp += buildEvents(data); | ||
// return the applied antora page mutation | ||
@@ -287,0 +279,0 @@ page[1] = Object.assign(Object.assign({}, page[1]), { content: tmp }); |
{ | ||
"name": "@tinymce/moxiedoc", | ||
"version": "0.2.0-feature.20220218054734314.sha231e752", | ||
"version": "0.2.0-feature.20220218062203506.sha55c37e0", | ||
"description": "A tool for generating API documentation", | ||
@@ -5,0 +5,0 @@ "author": "Tiny Technologies, Inc", |
@@ -5,3 +5,3 @@ import { Param, ParamData } from './param'; | ||
interface ReturnType { | ||
export interface Return { | ||
readonly types: string[]; | ||
@@ -14,3 +14,3 @@ readonly desc: string; | ||
readonly mixType?: string; | ||
readonly return?: ReturnType; | ||
readonly return?: Return; | ||
readonly staticLink?: boolean; | ||
@@ -31,3 +31,3 @@ readonly type?: string; | ||
public mixType: string; | ||
public return: ReturnType; | ||
public return: Return; | ||
public staticLink: boolean; | ||
@@ -34,0 +34,0 @@ public type: string; |
@@ -0,1 +1,4 @@ | ||
import { Return } from '../../lib/member'; | ||
import { Param } from '../../lib/param'; | ||
export interface PageOutput { | ||
@@ -47,8 +50,2 @@ readonly type: 'adoc' | 'json'; | ||
// runs a bunch of required cleanup filters, where embedded code/text can break asciidoc rendering | ||
const cleanup = (str: string): string => { | ||
const filters = [ escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode ]; | ||
return filters.reduce((acc, filter) => filter(acc), str); | ||
}; | ||
// convert <a href> into asciidoc link | ||
@@ -65,2 +62,8 @@ const encodeLinks = (str: string): string => { | ||
// runs a bunch of required cleanup filters, where embedded code/text can break asciidoc rendering | ||
const cleanup = (str: string): string => { | ||
const filters = [ escapeComments, encodeBR, encodeEM, encodeStrong, encodeLinks, encodeCode ]; | ||
return filters.reduce((acc, filter) => filter(acc), str); | ||
}; | ||
const getNameFromFullName = (name: string): string => | ||
@@ -75,3 +78,31 @@ name.split('.').slice(-1).join(''); | ||
const generateSummary = (data: Record<string, any>): string => { | ||
const generateExamples = (examples: Array<{ content: string }>): string => { | ||
let tmp = '\n==== Examples\n'; | ||
examples.forEach((example) => { | ||
tmp += '[source, javascript]\n'; | ||
tmp += '----\n'; | ||
tmp += example.content + '\n'; | ||
tmp += '----\n'; | ||
}); | ||
return tmp; | ||
}; | ||
const generateParameters = (params: Param[]): string => { | ||
let tmp = '\n==== Parameters\n'; | ||
params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
return tmp + '\n'; | ||
}; | ||
const generateReturn = (ret: Return): string => { | ||
let tmp = '\n==== Return value\n'; | ||
ret.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeLink(type) + '` - ' + cleanup(ret.desc); | ||
}); | ||
tmp += '\n'; | ||
return tmp; | ||
}; | ||
const buildSummary = (data: Record<string, any>): string => { | ||
let tmp = ''; | ||
@@ -167,3 +198,3 @@ | ||
const generateConstructor = (data: Record<string, any>): string => { | ||
const buildConstructor = (data: Record<string, any>): string => { | ||
let tmp = ''; | ||
@@ -185,26 +216,11 @@ | ||
if (hasValue(constructor.examples)) { | ||
tmp += '\n==== Examples\n'; | ||
constructor.examples.forEach((example) => { | ||
tmp += '[source, javascript]\n'; | ||
tmp += '----\n'; | ||
tmp += example.content + '\n'; | ||
tmp += '----\n'; | ||
}); | ||
tmp += '\n'; | ||
tmp += generateExamples(constructor.examples); | ||
} | ||
if (hasValue(constructor.params)) { | ||
tmp += '\n==== Parameters'; | ||
constructor.params.forEach((param) => { | ||
tmp += '\n* `' + param.name + '` `(' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateParameters(constructor.params); | ||
} | ||
if (hasValue(constructor.return) && hasValue(constructor.return.types)) { | ||
// untested - no data | ||
constructor.return.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeLink(type) + '` - ' + cleanup(constructor.return.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateReturn(constructor.return); | ||
} | ||
@@ -217,3 +233,3 @@ }); | ||
const generateMethods = (data: Record<string, any>): string => { | ||
const buildMethods = (data: Record<string, any>): string => { | ||
let tmp = ''; | ||
@@ -234,25 +250,11 @@ | ||
if (hasValue(method.examples)) { | ||
tmp += '\n==== Examples\n'; | ||
method.examples.forEach((example) => { | ||
tmp += '[source, javascript]\n'; | ||
tmp += '----\n'; | ||
tmp += example.content + '\n'; | ||
tmp += '----\n'; | ||
}); | ||
tmp += generateExamples(method.examples); | ||
} | ||
if (hasValue(method.params)) { | ||
tmp += '\n==== Parameters\n'; | ||
method.params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateParameters(method.params); | ||
} | ||
if (hasValue(method.return) && hasValue(method.return.types)) { | ||
tmp += '\n==== Return value\n'; | ||
method.return.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeLink(type) + '` - ' + cleanup(method.return.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateReturn(method.return); | ||
} | ||
@@ -267,3 +269,3 @@ | ||
const generateEvents = (data: Record<string, any>): string => { | ||
const buildEvents = (data: Record<string, any>): string => { | ||
let tmp = ''; | ||
@@ -281,7 +283,3 @@ | ||
if (hasValue(event.params)) { | ||
tmp += '\n==== Parameters\n'; | ||
event.params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + generateTypeLink(param.types[0]) + ')` - ' + cleanup(param.desc); | ||
}); | ||
tmp += '\n'; | ||
tmp += generateParameters(event.params); | ||
} | ||
@@ -339,6 +337,6 @@ }); | ||
tmp += generateSummary(data); | ||
tmp += generateConstructor(data); | ||
tmp += generateMethods(data); | ||
tmp += generateEvents(data); | ||
tmp += buildSummary(data); | ||
tmp += buildConstructor(data); | ||
tmp += buildMethods(data); | ||
tmp += buildEvents(data); | ||
@@ -345,0 +343,0 @@ // return the applied antora page mutation |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
342998
6644