feat: renderSync, parseAndRenderSync and renderFileSync, see #48

This commit is contained in:
harttle
2019-08-26 10:15:43 -05:00
committed by Jun Yang
parent 8028f82499
commit 7fb01ad69a
66 changed files with 896 additions and 272 deletions
+10
View File
@@ -60,4 +60,14 @@ describe('filter', function () {
new Filter('/', [], false)
}).to.not.throw()
})
it('should support sync', function () {
Filter.register('add', (a, b) => a + b)
expect(new Filter('add', ['2'], false).renderSync(3, ctx)).to.equal(5)
})
it('should support key value pairs', function () {
Filter.register('add', (a, b) => b[0] + ':' + (a + b[1]))
expect(new Filter('add', [['num', '2']], false).renderSync(3, ctx)).to.equal('num:5')
})
})
+20
View File
@@ -0,0 +1,20 @@
import * as chai from 'chai'
import { Hash } from '../../../src/template/tag/hash'
import { Context } from '../../../src/context/context'
const expect = chai.expect
describe('Hash', function () {
it('should parse variable', async function () {
const hash = await Hash.create('num:foo', new Context({ foo: 3 }))
expect(hash.num).to.equal(3)
})
it('should parse literals', async function () {
const hash = await Hash.create('num:3', new Context())
expect(hash.num).to.equal(3)
})
it('should support sync', function () {
const hash = Hash.createSync('num:3', new Context())
expect(hash.num).to.equal(3)
})
})
+1 -1
View File
@@ -10,7 +10,7 @@ chai.use(sinonChai)
const expect = chai.expect
const liquid = new Liquid()
describe('tag', function () {
describe('Tag', function () {
let ctx: Context
const emitter = { write: (html: string) => (emitter.html += html), html: '' }
before(function () {