mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
fix: `Nil`(null, undefined) now renders as empty string change: `parser.parseValue()` renamed to `parser.parseOutput` change: registered tags/filters become static and shared across different liquid instances
31 lines
851 B
TypeScript
31 lines
851 B
TypeScript
import { evalExp } from 'src/render/syntax'
|
|
import * as lexical from 'src/parser/lexical'
|
|
import assert from 'src/util/assert'
|
|
import Filter from './filter'
|
|
import Scope from 'src/scope/scope'
|
|
|
|
export default class {
|
|
initial: any
|
|
filters: Array<any>
|
|
constructor(str: string, strict_filters?: boolean) {
|
|
let match = lexical.matchValue(str)
|
|
assert(match, `illegal value string: ${str}`)
|
|
|
|
const initial = match[0]
|
|
str = str.substr(match.index + match[0].length)
|
|
|
|
const filters = []
|
|
while ((match = lexical.filter.exec(str))) {
|
|
filters.push([match[0].trim()])
|
|
}
|
|
|
|
this.initial = initial
|
|
this.filters = filters.map(str => new Filter(str, strict_filters))
|
|
}
|
|
value(scope: Scope) {
|
|
return this.filters.reduce(
|
|
(prev, filter) => filter.render(prev, scope),
|
|
evalExp(this.initial, scope))
|
|
}
|
|
}
|