smartmustache/ts/index.ts

30 lines
581 B
TypeScript
Raw Normal View History

2017-02-25 22:40:15 +00:00
import * as handlebars from 'handlebars'
2016-11-20 16:41:26 +00:00
/**
* class Tlt allows templates to be used with different sets of data
*/
export class Tlt {
2017-02-25 22:40:15 +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) {
this.template = handlebars.compile(templateStringArg)
}
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 {
return this.template(data)
}
2016-11-20 16:41:26 +00:00
2017-02-25 22:40:15 +00:00
/**
* set a new template string
*/
setTemplate(templateStringArg: string) {
this.template = handlebars.compile(templateStringArg)
}
2016-11-20 16:41:26 +00:00
}