feat: support in-memory template mapping, inspired by @jg-rp #714

This commit is contained in:
Harttle
2024-07-08 02:25:25 +08:00
parent 834328b9cb
commit df27ac6947
5 changed files with 115 additions and 0 deletions
+30
View File
@@ -49,4 +49,34 @@ describe('LiquidOptions#fs', function () {
} as any)
expect(engine.options.relativeReference).toBe(false)
})
it('should render from in-memory templates', () => {
const engine = new Liquid({
templates: {
entry: '{% layout "main" %}entry',
main: 'header {% block %}{% endblock %} footer'
}
})
expect(engine.renderFileSync('entry')).toEqual('header entry footer')
})
it('should render relative in-memory templates', () => {
const engine = new Liquid({
templates: {
'views/entry': 'header {% include "../partials/footer" %}',
'partials/footer': 'footer'
}
})
expect(engine.renderFileSync('views/entry')).toEqual('header footer')
})
it('should ignore root/layouts/partials', () => {
const engine = new Liquid({
root: '/foo/bar/',
layouts: '/foo/bar/',
partials: '/foo/bar/',
templates: {
entry: '{% layout "main" %}entry',
main: 'header {% block %}{% endblock %} footer'
}
})
expect(engine.renderFileSync('entry')).toEqual('header entry footer')
})
})