22 lines
601 B
JavaScript
22 lines
601 B
JavaScript
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
|
|
}
|