@@ -10,6 +10,8 @@ import { fieldsPartialTemplate } from './markdown/templates/fieldsPartialTemplat
1010import { classMarkdownTemplate } from './markdown/templates/class-template' ;
1111import { enumMarkdownTemplate } from './markdown/templates/enum-template' ;
1212import { interfaceMarkdownTemplate } from './markdown/templates/interface-template' ;
13+ import * as fs from 'fs' ;
14+ import * as path from 'path' ;
1315
1416export type CompilationRequest = {
1517 template : string ;
@@ -18,17 +20,43 @@ export type CompilationRequest = {
1820
1921export class Template {
2022 private static instance : Template ;
23+ private static customTemplateDir : string | undefined ;
24+
25+ /**
26+ * Set the custom template directory to use for overrides.
27+ * Should be called before getInstance().
28+ */
29+ public static setCustomTemplateDir ( dir : string ) {
30+ Template . customTemplateDir = dir ;
31+ }
2132
2233 private constructor ( ) {
23- Handlebars . registerPartial ( 'typeDocumentation' , typeDocPartial ) ;
24- Handlebars . registerPartial ( 'documentablePartialTemplate' , documentablePartialTemplate ) ;
25- Handlebars . registerPartial ( 'methodsPartialTemplate' , methodsPartialTemplate ) ;
26- Handlebars . registerPartial ( 'constructorsPartialTemplate' , constructorsPartialTemplate ) ;
27- Handlebars . registerPartial ( 'groupedMembersPartialTemplate' , groupedMembersPartialTemplate ) ;
28- Handlebars . registerPartial ( 'fieldsPartialTemplate' , fieldsPartialTemplate ) ;
29- Handlebars . registerPartial ( 'classTemplate' , classMarkdownTemplate ) ;
30- Handlebars . registerPartial ( 'enumTemplate' , enumMarkdownTemplate ) ;
31- Handlebars . registerPartial ( 'interfaceTemplate' , interfaceMarkdownTemplate ) ;
34+ // Template name to default value mapping
35+ const templates : Record < string , string > = {
36+ typeDocumentation : typeDocPartial ,
37+ documentablePartialTemplate : documentablePartialTemplate ,
38+ methodsPartialTemplate : methodsPartialTemplate ,
39+ constructorsPartialTemplate : constructorsPartialTemplate ,
40+ groupedMembersPartialTemplate : groupedMembersPartialTemplate ,
41+ fieldsPartialTemplate : fieldsPartialTemplate ,
42+ classTemplate : classMarkdownTemplate ,
43+ enumTemplate : enumMarkdownTemplate ,
44+ interfaceTemplate : interfaceMarkdownTemplate ,
45+ } ;
46+
47+ // If customTemplateDir is set, try to load each template from it
48+ for ( const [ name , defaultValue ] of Object . entries ( templates ) ) {
49+ let value = defaultValue ;
50+ if ( Template . customTemplateDir ) {
51+ const customPath = path . join ( Template . customTemplateDir , `${ name } .hbs` ) ;
52+
53+ if ( fs . existsSync ( customPath ) ) {
54+ value = fs . readFileSync ( customPath , 'utf8' ) ;
55+ }
56+ }
57+
58+ Handlebars . registerPartial ( name , value ) ;
59+ }
3260
3361 Handlebars . registerHelper ( 'link' , link ) ;
3462 Handlebars . registerHelper ( 'code' , convertCodeBlock ) ;
0 commit comments