audio-vis/raw/javascript/templateLang/VTepLCore.js

35 lines
916 B
JavaScript
Raw Normal View History

'use strict';
class VTpeLCore {
constructor(options = {}) {
this.templates = {};
this.dir = options.path || '/tpl/';
this.suffix = options.suffix || 'tpl';
this.path = options.template || `${this.dir}%s.${this.suffix}`;
this.cache = options.cache === undefined ? true : options.cache;
}
async loadTemplate(name) {
let rawData = await fetch(this.path.replace('%s', name));
if (rawData.ok) {
let data = await rawData.text();
this.addTpl(name, data);
}
}
async loadArray(names) {
for (let name of names) {
await this.loadTemplate(name);
}
}
addTpl(name, content) {
let temp = this.templates[name] = new VTpeLTemplate(name, content)
temp.parseContent(this.cache);
}
renderOn(name, data) {
return this.templates[name].render(data);
}
}