25 lines
631 B
JavaScript
25 lines
631 B
JavaScript
|
"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')
|
||
|
};
|
||
|
}
|