fix: pass drops directly to filters/tags

This commit is contained in:
harttle
2019-05-12 20:03:32 +08:00
parent 4282accaa2
commit bef290923c
15 changed files with 93 additions and 42 deletions
+27
View File
@@ -83,6 +83,33 @@ describe('tags/include', function () {
const html = await liquid.renderFile('with.html')
return expect(html).to.equal('color:red, shape:rect')
})
it('should support include: with as Liquid Drop', async function () {
class ColorDrop extends Liquid.Types.Drop {
valueOf (): string {
return 'red!'
}
}
mock({
'/with.html': '{% include "color" with color %}',
'/color.html': 'color:{{color}}'
})
const html = await liquid.renderFile('with.html', { color: new ColorDrop() })
expect(html).to.equal('color:red!')
})
it('should support include: with passed as Liquid Drop', async function () {
class ColorDrop extends Liquid.Types.Drop {
valueOf (): string {
return 'red!'
}
}
liquid.registerFilter('name', x => x.constructor.name)
mock({
'/with.html': '{% include "color" with color %}',
'/color.html': '{{color | name}}'
})
const html = await liquid.renderFile('with.html', { color: new ColorDrop() })
expect(html).to.equal('ColorDrop')
})
it('should support nested includes', async function () {
mock({
+6
View File
@@ -49,6 +49,12 @@ describe('filter', function () {
expect(await new Filter('add', ['2', '"c"'], false).render(3, ctx)).to.equal('5c')
})
it('should pass Objects/Drops as it is', async function () {
Filter.register('name', a => a.constructor.name)
class Foo {}
expect(await new Filter('name', [], false).render(new Foo(), ctx)).to.equal('Foo')
})
it('should not throw when filter name illegal', function () {
expect(function () {
new Filter('/', [], false)