fix: allow {%render%} to reassign argument, #404

This commit is contained in:
AleksandrHovhannisyan
2021-10-31 16:28:33 +08:00
committed by Harttle
parent 432d1c7ccb
commit 124f4c4485
9 changed files with 44 additions and 6 deletions
+5
View File
@@ -69,6 +69,11 @@ describe('tags/assign', function () {
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('-6')
})
it('should allow reassignment', async function () {
const src = '{% assign var = 1 %}{% assign var = 2 %}{{ var }}'
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('2')
})
describe('scope', function () {
it('should read from parent scope', async function () {
const src = '{%for a in (1..2)%}{{num}}{%endfor%}'
+1 -1
View File
@@ -19,7 +19,7 @@ describe('tags/capture', function () {
return expect(html).to.equal('A')
})
it('should shading rather than overwriting', async function () {
it('should not change root scope', async function () {
const src = '{% capture var %}10{% endcapture %}{{var}}'
const ctx = { 'var': 20 }
const html = await liquid.parseAndRender(src, ctx)
+1 -1
View File
@@ -39,7 +39,7 @@ describe('tags/increment', function () {
return expect(html).to.equal('012 10')
})
it('should not shading capture', async function () {
it('should not hide capture', async function () {
const src = '{% capture var %}10{% endcapture %}{% increment var %}{% increment var %}{% increment var %} {{var}}'
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('012 10')
+10
View File
@@ -86,6 +86,16 @@ describe('tags/render', function () {
expect(html).to.equal('InParent: harttle InChild: ')
})
it('should allow argument reassignment', async function () {
mock({
'/parent.html': '{% render child.html, color: "red" %}',
'/child.html': '{% assign color = "green" %}{{ color }}'
})
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
const html = await staticLiquid.renderFile('parent.html')
return expect(html).to.equal('green')
})
it('should be able to access globals', async function () {
liquid = new Liquid({ root: '/', extname: '.html', globals: { name: 'Harttle' } })
mock({