fix: break/continue omitting output before them, #123

BREAKING CHANGE: remove default export, now should be used like import
{Liquid} from 'liquidjs'
This commit is contained in:
harttle
2019-08-26 10:15:43 -05:00
committed by Jun Yang
parent 854e12ba53
commit ae45c4622e
99 changed files with 373 additions and 407 deletions
+6 -13
View File
@@ -1,22 +1,15 @@
import { RenderError } from '../util/error'
import assert from '../util/assert'
import Context from '../context/context'
import ITemplate from '../template/itemplate'
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')
const emitter = new Emitter()
export class Render {
public async renderTemplates (templates: ITemplate[], ctx: Context, emitter = new Emitter()) {
for (const tpl of templates) {
try {
emitter.write(await tpl.render(ctx, emitter))
await tpl.render(ctx, emitter)
} catch (e) {
if (e.name === 'RenderBreakError') {
e.resolvedHTML = emitter.html
throw e
}
if (e.name === 'RenderBreakError') throw e
throw e.name === 'RenderError' ? e : new RenderError(e, tpl)
}
}