pi-rfid-jukebox/jukebox/views.js

25 lines
631 B
JavaScript
Raw Normal View History

2017-04-09 14:46:59 +00:00
"use strict";
const mustache = require('mustache');
const readFileSync = require('fs').readFileSync;
class View {
constructor(base_dir, path) {
this.path = base_dir + '/templates/' + path;
this.template = readFileSync(this.path, {encoding: 'utf8'})
mustache.parse(this.template)
}
render(vars, partials) {
return mustache.render(this.template, vars, partials);
}
}
module.exports = function(base_dir) {
return {
base: new View(base_dir, 'base.mustache')
, index: new View(base_dir, 'index.mustache')
, log: new View(base_dir, 'log.mustache')
};
}