mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 06:20:38 -07:00
+14
-28
@@ -1,29 +1,15 @@
|
||||
import { stringify, toValue } from '../util/underscore'
|
||||
|
||||
export class Emitter {
|
||||
public html: any = '';
|
||||
public break = false;
|
||||
public continue = false;
|
||||
private keepOutputType? = false;
|
||||
|
||||
constructor (keepOutputType: boolean|undefined) {
|
||||
this.keepOutputType = keepOutputType
|
||||
}
|
||||
|
||||
public write (html: any) {
|
||||
if (this.keepOutputType === true) {
|
||||
html = toValue(html)
|
||||
} else {
|
||||
html = stringify(html)
|
||||
}
|
||||
// This will only preserve the type if the value is isolated.
|
||||
// I.E:
|
||||
// {{ my-port }} -> 42
|
||||
// {{ my-host }}:{{ my-port }} -> 'host:42'
|
||||
if (this.keepOutputType === true && typeof html !== 'string' && this.html === '') {
|
||||
this.html = html
|
||||
} else {
|
||||
this.html = stringify(this.html) + stringify(html)
|
||||
}
|
||||
}
|
||||
export interface Emitter {
|
||||
/**
|
||||
* Write a html value into emitter
|
||||
* @param html string, Drop or other primitive value
|
||||
*/
|
||||
write (html: any): void;
|
||||
/**
|
||||
* Notify the emitter render has ended
|
||||
*/
|
||||
end (): void;
|
||||
/**
|
||||
* Collect rendered string value immediately
|
||||
*/
|
||||
collect (): string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user