-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
output.ts
26 lines (25 loc) · 988 Bytes
/
output.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Value } from './value'
import { Template, TemplateImpl } from '../template'
import { Context } from '../context/context'
import { Emitter } from '../emitters/emitter'
import { OutputToken } from '../tokens/output-token'
import { Liquid } from '../liquid'
import { Filter } from './filter'
export class Output extends TemplateImpl<OutputToken> implements Template {
value: Value
public constructor (token: OutputToken, liquid: Liquid) {
super(token)
this.value = new Value(token.content, liquid)
const filters = this.value.filters
const outputEscape = liquid.options.outputEscape
if (filters.length && filters[filters.length - 1].name === 'raw') {
filters.pop()
} else if (outputEscape) {
filters.push(new Filter(toString.call(outputEscape), outputEscape, [], liquid))
}
}
public * render (ctx: Context, emitter: Emitter): IterableIterator<unknown> {
const val = yield this.value.value(ctx, false)
emitter.write(val)
}
}