fix: relative root (by default) yields LookupError, fixes #419, #424, also related to #395

This commit is contained in:
Harttle
2021-10-27 23:55:39 +08:00
committed by Harttle
parent 564972ba74
commit aebeae9e1b
7 changed files with 67 additions and 50 deletions
+21
View File
@@ -85,6 +85,17 @@ describe('tags/layout', function () {
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('XAY')
})
it('should use `layouts` if specified', async function () {
mock({
'/layouts/parent.html': 'LAYOUTS {%block%}{%endblock%}',
'/root/parent.html': 'ROOT {%block%}{%endblock%}',
'/root/main.html': '{% layout parent.html %}{%block%}A{%endblock%}'
})
const staticLiquid = new Liquid({ root: '/root', layouts: '/layouts', dynamicPartials: false })
const html = await staticLiquid.renderFile('main.html')
return expect(html).to.equal('LAYOUTS A')
})
it('should support block.super', async function () {
mock({
'/parent.html': '{% block css %}<link href="base.css" rel="stylesheet">{% endblock %}'
@@ -189,6 +200,16 @@ describe('tags/layout', function () {
return expect(html).to.equal('blackA')
})
it('should support relative root', async function () {
mock({
[process.cwd() + '/foo/parent.html']: '{{color}}{%block%}{%endblock%}',
[process.cwd() + '/foo/bar/main.html']: '{% layout parent.html color:"black"%}{%block%}A{%endblock%}'
})
const staticLiquid = new Liquid({ root: './foo', dynamicPartials: false })
const html = await staticLiquid.renderFile('bar/main.html')
return expect(html).to.equal('blackA')
})
describe('static partial', function () {
it('should support filename with extension', async function () {
mock({
+2 -6
View File
@@ -3,13 +3,9 @@ import { expect } from 'chai'
describe('liquid-options', () => {
describe('.normalize()', () => {
it('should return plain object for empty input', () => {
const options = normalize()
expect(JSON.stringify(options)).to.equal('{}')
})
it('should set falsy cache to undefined', () => {
it('should set cache to undefined if specified to falsy', () => {
const options = normalize({ cache: false })
expect(JSON.stringify(options)).to.equal('{}')
expect(options.cache).to.equal(undefined)
})
})
})