mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 14:30:38 -07:00
@@ -0,0 +1,4 @@
|
||||
export interface Emitter {
|
||||
write (html: any): void;
|
||||
end (): void;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { stringify, toValue } from '../util/underscore'
|
||||
|
||||
export class KeepingTypeEmitter {
|
||||
public html: any = '';
|
||||
|
||||
public write (html: any) {
|
||||
html = toValue(html)
|
||||
// This will only preserve the type if the value is isolated.
|
||||
// I.E:
|
||||
// {{ my-port }} -> 42
|
||||
// {{ my-host }}:{{ my-port }} -> 'host:42'
|
||||
if (typeof html !== 'string' && this.html === '') {
|
||||
this.html = html
|
||||
} else {
|
||||
this.html = stringify(this.html) + stringify(html)
|
||||
}
|
||||
}
|
||||
|
||||
public end () {
|
||||
return this.html
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { stringify } from '../util/underscore'
|
||||
import { Emitter } from './emitter'
|
||||
|
||||
export class SimpleEmitter implements Emitter {
|
||||
public html: any = '';
|
||||
|
||||
public write (html: any) {
|
||||
this.html += stringify(html)
|
||||
}
|
||||
|
||||
public end () {
|
||||
return this.html
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { stringify } from '../util/underscore'
|
||||
|
||||
export class StreamedEmitter {
|
||||
public html: any = '';
|
||||
public stream = new (require('stream').PassThrough)()
|
||||
public write (html: any) {
|
||||
this.stream.write(stringify(html))
|
||||
}
|
||||
public end () {
|
||||
this.stream.end()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user