mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-25 00:19:22 -06:00
Co-authored-by: Jessica Sachs <jess@jessicasachs.io> Co-authored-by: Barthélémy Ledoux <bart@cypress.io> Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com> Co-authored-by: Zach Bloomquist <github@chary.us> Co-authored-by: Dmitriy Kovalenko <dmtr.kovalenko@outlook.com> Co-authored-by: ElevateBart <ledouxb@gmail.com> Co-authored-by: Ben Kucera <14625260+Bkucera@users.noreply.github.com>
30 lines
646 B
JavaScript
30 lines
646 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)
|
|
},
|
|
}
|