feat: add option for keeping variable type in output

This commit is contained in:
Alex de Wergifosse
2020-12-16 10:20:10 +08:00
committed by Jun Yang
parent e84fbf32ad
commit cd92e77726
11 changed files with 42 additions and 21 deletions
+12 -3
View File
@@ -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
}
}
}
+1 -1
View File
@@ -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)