Improved template engine
All checks were successful
Build / Publish Docs (push) Successful in 1m9s
Build / Build NPM Project (push) Successful in 1m23s
Build / Tag Version (push) Successful in 10s

This commit is contained in:
2026-01-15 19:18:48 -05:00
parent 3048b74b2f
commit 1b0061b714
3 changed files with 183 additions and 63 deletions

View File

@@ -113,6 +113,39 @@ Total: {{ total }}
expect(result).toEqual({ cart: [], total: '' });
});
test('real world template', async () => {
const wrapper = `<div> {{body}} </div>`;
const tpl = `
{{ > email:body }}
<div style="text-align: center">
{{ ? title }}<h1 style="margin: 0">{{ title }}</h1>{{ /? }}
{{ ? subject }}<h2 style="margin: 0">{{ subject }}</h2>{{ /? }}
{{ ? message }}<p style="margin-top: 1rem">{{ message }}</p>{{ /? }}
{{ ? link }}
<br>
<div style="background: #dedede; padding: 8px 20px; border-radius: 10px; overflow-x: auto;">
{{ ? link.startsWith('http') }}
<a style="word-break: break-all;" target="_blank" href="{{ link }}">{{ link }}</a>
{{ !? }}
<p style="margin: 0; word-break: break-all;">{{ link }}</p>
{{ /? }}
</div>
{{ /? }}
{{ ? footer }}
<br>
<p>{{ footer }}</p>
{{ /? }}
</div>
{{ /> }}`;
console.log(await renderTemplate(tpl, {
title: 'test',
subject: 'test',
message: 'test',
link: 'test',
footer: 'test',
}, async () => wrapper))
});
test('real world invoice template', () => {
const tpl = `
{{ settings.title }}