@@ -6,6 +6,12 @@ import { PresTemplate } from './interfaces/pres-template';
66import { RootPresTemplate } from './interfaces/root-pres-template' ;
77import { Template } from './classes/template' ;
88
9+ /**
10+ * Automizer
11+ *
12+ * The basic class for `pptx-automizer` package.
13+ * This class will be exported as `Automizer` by `index.ts`.
14+ */
915export default class Automizer implements IPresentationProps {
1016 rootTemplate : RootPresTemplate ;
1117 templates : PresTemplate [ ] ;
@@ -15,8 +21,8 @@ export default class Automizer implements IPresentationProps {
1521 params : AutomizerParams ;
1622
1723 /**
18- * Parameters for Automizer constructor .
19- * @param params
24+ * Creates an instance of `pptx-automizer` .
25+ * @param [ params]
2026 */
2127 constructor ( params ?: AutomizerParams ) {
2228 this . templates = [ ] ;
@@ -30,25 +36,32 @@ export default class Automizer implements IPresentationProps {
3036
3137 /**
3238 * Load a pptx file and set it as root template.
33- * @param { string } location - Filename or path to the template. Will be prefixed with 'templateDir'
34- * @return { Automizer } Instance of Automizer
39+ * @param location - Filename or path to the template. Will be prefixed with 'templateDir'
40+ * @returns Instance of Automizer
3541 */
3642 public loadRoot ( location : string ) : this {
3743 return this . loadTemplate ( location ) ;
3844 }
3945
4046 /**
4147 * Load a template pptx file.
42- * @param { string } location - Filename or path to the template. Will be prefixed with 'templateDir'
43- * @param { string } name - Optional: A short name for the template. If skipped, the template will be named by its location.
44- * @return { Automizer } Instance of Automizer
48+ * @param location - Filename or path to the template. Will be prefixed with 'templateDir'
49+ * @param name - Optional: A short name for the template. If skipped, the template will be named by its location.
50+ * @returns Instance of Automizer
4551 */
4652 public load ( location : string , name ?: string ) : this {
4753 name = name === undefined ? location : name ;
4854 return this . loadTemplate ( location , name ) ;
4955 }
5056
51- public loadTemplate ( location : string , name ?: string ) : this {
57+ /**
58+ * Loads a pptx file either as a root template as a template file.
59+ * A name can be specified to give templates an alias.
60+ * @param location
61+ * @param [name]
62+ * @returns template
63+ */
64+ private loadTemplate ( location : string , name ?: string ) : this {
5265 location = this . getLocation ( location , 'template' ) ;
5366
5467 const newTemplate = Template . import ( location , name ) ;
@@ -62,18 +75,23 @@ export default class Automizer implements IPresentationProps {
6275 return this ;
6376 }
6477
65- isPresTemplate (
78+ /**
79+ * Determines whether template is root or default template.
80+ * @param template
81+ * @returns pres template
82+ */
83+ private isPresTemplate (
6684 template : PresTemplate | RootPresTemplate ,
6785 ) : template is PresTemplate {
6886 return 'name' in template ;
6987 }
7088
7189 /**
72- * Find imported template by given name and return a certain slide by number .
73- * @param { string } name - Name of template; must be imported by Automizer.importTemplate()
74- * @param { number } slideNumber - Number of slide in template presentation
75- * @param callback - Executed when slide is created. Passes the newly created slide
76- * @return { Automizer } Instance of Automizer
90+ * Find a slide in by number in one of the imported templates .
91+ * @param name - Name or alias of the template; must have been loaded with ` Automizer.load()`
92+ * @param slideNumber - Number of slide in template presentation
93+ * @param callback - Executed after slide was added. The newly created slide will be passed to the callback as first argument.
94+ * @returns Instance of Automizer
7795 */
7896 public addSlide (
7997 name : string ,
@@ -102,7 +120,12 @@ export default class Automizer implements IPresentationProps {
102120 return this ;
103121 }
104122
105- public getTemplate ( name : string ) : PresTemplate {
123+ /**
124+ * Searches this.templates to find template by given name.
125+ * @param name Alias name if given to loaded template.
126+ * @returns template
127+ */
128+ private getTemplate ( name : string ) : PresTemplate {
106129 const template = this . templates . find ( ( t ) => t . name === name ) ;
107130 if ( template === undefined ) {
108131 throw new Error ( `Template not found: ${ name } ` ) ;
@@ -112,9 +135,10 @@ export default class Automizer implements IPresentationProps {
112135
113136 /**
114137 * Write all imports and modifications to a file.
115- * @param {string } location - Filename or path for the file. Will be prefixed with 'outputDir'
138+ * @param location - Filename or path for the file. Will be prefixed with 'outputDir'
139+ * @returns summary object.
116140 */
117- async write ( location : string ) : Promise < AutomizerSummary > {
141+ public async write ( location : string ) : Promise < AutomizerSummary > {
118142 const rootArchive = await this . rootTemplate . archive ;
119143
120144 for ( const slide of this . rootTemplate . slides ) {
@@ -130,6 +154,12 @@ export default class Automizer implements IPresentationProps {
130154 ) ;
131155 }
132156
157+ /**
158+ * Applies path prefix to given location string.
159+ * @param location path and/or filename
160+ * @param [type] template or output
161+ * @returns location
162+ */
133163 private getLocation ( location : string , type ?: string ) : string {
134164 switch ( type ) {
135165 case 'template' :
0 commit comments