mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
feat: add option for keeping variable type in output
This commit is contained in:
committed by
Jun Yang
parent
e84fbf32ad
commit
cd92e77726
+12
-3
@@ -1,9 +1,18 @@
|
||||
export class Emitter {
|
||||
public html = '';
|
||||
public html: any = '';
|
||||
public break = false;
|
||||
public continue = false;
|
||||
private keepOutputType? = false;
|
||||
|
||||
public write (html: string) {
|
||||
this.html += html
|
||||
constructor (keepOutputType: boolean|undefined) {
|
||||
this.keepOutputType = keepOutputType
|
||||
}
|
||||
|
||||
public write (html: any) {
|
||||
if (this.keepOutputType && typeof html !== 'string') {
|
||||
this.html = html
|
||||
} else {
|
||||
this.html += html as string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Template } from '../template/template'
|
||||
import { Emitter } from './emitter'
|
||||
|
||||
export class Render {
|
||||
public * renderTemplates (templates: Template[], ctx: Context, emitter = new Emitter()): IterableIterator<string> {
|
||||
public * renderTemplates (templates: Template[], ctx: Context, emitter: Emitter): IterableIterator<any> {
|
||||
for (const tpl of templates) {
|
||||
try {
|
||||
const html = yield tpl.render(ctx, emitter)
|
||||
|
||||
Reference in New Issue
Block a user