feat: support {{block.super}}, see #38

This commit is contained in:
harttle
2021-01-24 02:57:48 +08:00
parent 0e0dc2adf0
commit a3af44dc10
5 changed files with 81 additions and 21 deletions
+30
View File
@@ -69,6 +69,36 @@ describe('tags/layout', function () {
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('XAYBZ')
})
it('should support block.super', async function () {
mock({
'/parent.html': '{% block css %}<link href="base.css" rel="stylesheet">{% endblock %}'
})
const src = '{% layout "parent.html" %}' +
'{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
const html = await liquid.parseAndRender(src)
const output = '<link href="base.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
return expect(html).to.equal(output)
})
it('should render block.super to empty if no parent exists', async function () {
mock({
'/parent.html': '{% block css %}{{block.super}}<link href="base.css" rel="stylesheet">{% endblock %}'
})
const src = '{% layout "parent.html" %}' +
'{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
const html = await liquid.parseAndRender(src)
const output = '<link href="base.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
return expect(html).to.equal(output)
})
it('should support nested block.super', async function () {
mock({
'/root.html': '{% block css %}<link href="root.css" rel="stylesheet">{% endblock %}',
'/parent.html': '{% layout "root.html" %}{% block css %}{{block.super}}<link href="parent.css" rel="stylesheet">{% endblock %}'
})
const src = '{% layout "parent.html" %}{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
const html = await liquid.parseAndRender(src)
const output = '<link href="root.css" rel="stylesheet"><link href="parent.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
return expect(html).to.equal(output)
})
it('should support variable as layout name', async function () {
mock({
'/parent.html': 'X{% block "a"%}{% endblock %}Y'