mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-19 13:39:56 -06:00
* 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
30 lines
642 B
JavaScript
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)
|
|
},
|
|
}
|