mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
refactor: add emitter for code generation
This commit is contained in:
@@ -2,23 +2,24 @@ import { RenderError } from '../util/error'
|
||||
import assert from '../util/assert'
|
||||
import Context from '../context/context'
|
||||
import ITemplate from '../template/itemplate'
|
||||
import { Emitter } from './emitter'
|
||||
|
||||
export default class Render {
|
||||
public async renderTemplates (templates: ITemplate[], ctx: Context) {
|
||||
assert(ctx, 'unable to evalTemplates: context undefined')
|
||||
|
||||
let html = ''
|
||||
const emitter = new Emitter()
|
||||
for (const tpl of templates) {
|
||||
try {
|
||||
html += await tpl.render(ctx)
|
||||
emitter.write(await tpl.render(ctx, emitter))
|
||||
} catch (e) {
|
||||
if (e.name === 'RenderBreakError') {
|
||||
e.resolvedHTML = html
|
||||
e.resolvedHTML = emitter.html
|
||||
throw e
|
||||
}
|
||||
throw e.name === 'RenderError' ? e : new RenderError(e, tpl)
|
||||
}
|
||||
}
|
||||
return html
|
||||
return emitter.html
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user