fix: type compatible with v9 tag definition, support Context as scope in various render APIs, #570

This commit is contained in:
Jun Yang
2022-12-18 12:48:06 +08:00
parent 7526d4062d
commit fb6a9f8717
5 changed files with 55 additions and 20 deletions
+17 -1
View File
@@ -1,4 +1,4 @@
import { Tokenizer, Context, Liquid, Drop, toValueSync } from '../..'
import { TopLevelToken, TagToken, Tokenizer, Context, Liquid, Drop, toValueSync } from '../..'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import * as sinon from 'sinon'
@@ -346,4 +346,20 @@ describe('Issues', function () {
const html = await liquid.parseAndRender(tpl)
expect(html).to.match(/^\s*This is a love or luck potion.\s+This is a strength or health or love potion.\s*$/)
})
it('#570 tag registration compatible to v9', async () => {
const liquid = new Liquid()
liquid.registerTag('metadata_file', {
parse (tagToken: TagToken, remainTokens: TopLevelToken[]) {
this.str = tagToken.args
},
async render (ctx: Context) {
const content = await Promise.resolve(`{{${this.str}}}`)
return this.liquid.parseAndRender(content.toString(), ctx)
}
})
const tpl = '{% metadata_file foo %}'
const ctx = { foo: 'FOO' }
const html = await liquid.parseAndRender(tpl, ctx)
expect(html).to.equal('FOO')
})
})