Files
cypress/packages/server/lib/template_engine.js
Brian Mann 91a4477ad0 replace handlebars with squirrelly (#5521)
* WIP: rip out handlebars and implement with squirrelly

- handle caching ourselves
- TODO: add tests, make sure escaping and all that jazz works

* fixes squirrelly template handling

* only fire mocha events when in run mode

* add unit tests for template engine rendering + caching
2019-10-30 02:21:53 -04:00

30 lines
642 B
JavaScript

const Sqrl = require('squirrelly')
const fs = require('./util/fs')
const cache = {}
module.exports = {
cache,
render (filePath, options, cb) {
const cachedFn = cache[filePath]
// if we already have a cachedFn function
if (cachedFn) {
// just return it and move in
return cb(null, cachedFn(options, Sqrl))
}
// else go read it off the filesystem
return fs
.readFileAsync(filePath, 'utf8')
.then((str) => {
// and cache the Sqrl compiled template fn
const compiledFn = cache[filePath] = Sqrl.Compile(str)
return compiledFn(options, Sqrl)
})
.asCallback(cb)
},
}