feat: add layouts, partials apart from root, #395

This commit is contained in:
harttle
2021-10-03 18:51:14 +08:00
parent 0cb520d2d1
commit b9ae479b65
10 changed files with 142 additions and 58 deletions
+10 -1
View File
@@ -76,6 +76,15 @@ describe('tags/layout', function () {
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('XAYBZ')
})
it('should support `options.layouts`', async () => {
mock({
'/layouts/parent.html': 'X{% block "a"%}{%endblock%}Y'
})
const src = '{% layout "parent.html" %}{%block a%}A{%endblock%}'
const liquid = new Liquid({ layouts: '/layouts' })
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('XAY')
})
it('should support block.super', async function () {
mock({
'/parent.html': '{% block css %}<link href="base.css" rel="stylesheet">{% endblock %}'
@@ -171,7 +180,7 @@ describe('tags/layout', function () {
})
describe('static partial', function () {
it('should support filename with extention', async function () {
it('should support filename with extension', async function () {
mock({
'/parent.html': '{{color}}{%block%}{%endblock%}',
'/main.html': '{% layout parent.html color:"black"%}{%block%}A{%endblock%}'
+9
View File
@@ -21,6 +21,15 @@ describe('tags/render', function () {
const html = await liquid.renderFile('/current.html')
expect(html).to.equal('barfoobar')
})
it('should support render', async function () {
mock({
'/current.html': 'bar{% render "foo.html" %}bar',
'/partials/foo.html': 'foo'
})
const liquid = new Liquid({ partials: '/partials' })
const html = await liquid.renderFile('/current.html')
expect(html).to.equal('barfoobar')
})
it('should support template string', async function () {
mock({
'/current.html': 'bar{% render "bar/{{name}}" %}bar',