mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
25 lines
679 B
TypeScript
25 lines
679 B
TypeScript
import { RenderBreakError, RenderError } from 'src/util/error'
|
|
import assert from 'src/util/assert'
|
|
import Scope from 'src/scope/scope';
|
|
import ITemplate from 'src/template/itemplate';
|
|
|
|
export default class Render {
|
|
async renderTemplates (templates: ITemplate[], scope: Scope) {
|
|
assert(scope, 'unable to evalTemplates: scope undefined')
|
|
|
|
let html = ''
|
|
for (const tpl of templates) {
|
|
try {
|
|
html += await tpl.render(scope)
|
|
} catch (e) {
|
|
if (e.name === 'RenderBreakError') {
|
|
e.resolvedHTML = html
|
|
throw e
|
|
}
|
|
throw e.name === 'RenderError' ? e : new RenderError(e, tpl)
|
|
}
|
|
}
|
|
return html
|
|
}
|
|
}
|