smartmustache/ts/index.ts

30 lines
591 B
TypeScript
Raw Normal View History

2022-08-07 15:55:40 +00:00
import handlebars from 'handlebars';
2016-11-20 16:41:26 +00:00
/**
* class Tlt allows templates to be used with different sets of data
*/
2018-09-15 10:43:01 +00:00
export class SmartMustache {
2018-09-14 21:02:17 +00:00
template: any;
2016-11-20 16:41:26 +00:00
2017-02-25 22:40:15 +00:00
/**
* constructor of class Tlt
*/
constructor(templateStringArg: string) {
2018-09-14 21:02:17 +00:00
this.template = handlebars.compile(templateStringArg);
2017-02-25 22:40:15 +00:00
}
2016-11-20 16:41:26 +00:00
2017-02-25 22:40:15 +00:00
/**
* returns template string with data applied
*/
applyData(data: any): string {
2018-09-14 21:02:17 +00:00
return this.template(data);
2017-02-25 22:40:15 +00:00
}
2016-11-20 16:41:26 +00:00
2017-02-25 22:40:15 +00:00
/**
* set a new template string
*/
setTemplate(templateStringArg: string) {
2018-09-14 21:02:17 +00:00
this.template = handlebars.compile(templateStringArg);
2017-02-25 22:40:15 +00:00
}
2016-11-20 16:41:26 +00:00
}