const config = require('./config') const fs = require('fs') const ejs = require('ejs') const Bluebird = require('bluebird') const {htmlEscape, htmlUnescape} = require('escape-goat') const readFileAsync = Bluebird.promisify(fs.readFile) async function render(name, data) { const tmplPath = `${__dirname}/templates/${name}.ejs` const buffer = await readFileAsync(tmplPath) const tmpl = buffer.toString() const context = Object.assign({ htmlEscape, htmlUnescape, config }, data) return ejs.render(tmpl, context, { views: [ `${__dirname}/templates` ] }) } module.exports = { render }