-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
3182f62
commit 91a4477
Showing
7 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require('../spec_helper') | ||
|
||
const os = require('os') | ||
const path = require('path') | ||
const Bluebird = require('bluebird') | ||
const { cache, render } = require('../../lib/template_engine') | ||
const fs = require('../../lib/util/fs') | ||
|
||
describe('lib/template_engine', () => { | ||
it('renders and caches a template function', () => { | ||
sinon.spy(fs, 'readFile') | ||
|
||
expect(cache).to.deep.eq({}) | ||
|
||
const tmpPath = path.join(os.tmpdir(), 'index.html') | ||
|
||
return fs | ||
.writeFileAsync(tmpPath, 'My favorite template engine is {{favorite}}.') | ||
.then(() => { | ||
return Bluebird.fromCallback((cb) => { | ||
const opts = { | ||
favorite: 'Squirrelly', | ||
} | ||
|
||
return render(tmpPath, opts, cb) | ||
}) | ||
}) | ||
.then((str) => { | ||
expect(str).to.eq('My favorite template engine is Squirrelly.') | ||
|
||
expect(fs.readFile).to.be.calledOnce | ||
|
||
const compiledFn = cache[tmpPath] | ||
|
||
expect(compiledFn).to.be.a('function') | ||
|
||
return Bluebird.fromCallback((cb) => { | ||
const opts = { | ||
favorite: 'Squirrelly2', | ||
} | ||
|
||
return render(tmpPath, opts, cb) | ||
}) | ||
.then((str) => { | ||
expect(str).to.eq('My favorite template engine is Squirrelly2.') | ||
|
||
expect(cache[tmpPath]).to.eq(compiledFn) | ||
|
||
expect(fs.readFile).to.be.calledOnce | ||
}) | ||
}) | ||
}) | ||
}) |
91a4477
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppVeyor has built the
win32 ia32
version of the Test Runner.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.91a4477
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppVeyor has built the
win32 x64
version of the Test Runner.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.91a4477
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux x64
version of the Test Runner.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.91a4477
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin x64
version of the Test Runner.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.