smartmustache/ts/index.ts
2022-08-07 17:55:40 +02:00

30 lines
591 B
TypeScript

import handlebars from 'handlebars';
/**
* class Tlt allows templates to be used with different sets of data
*/
export class SmartMustache {
template: any;
/**
* constructor of class Tlt
*/
constructor(templateStringArg: string) {
this.template = handlebars.compile(templateStringArg);
}
/**
* returns template string with data applied
*/
applyData(data: any): string {
return this.template(data);
}
/**
* set a new template string
*/
setTemplate(templateStringArg: string) {
this.template = handlebars.compile(templateStringArg);
}
}