Files
liquidjs/src/render/render.ts
T
2019-02-23 00:49:54 +08:00

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
}
}