mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix: pass drops directly to filters/tags
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { evalValue } from '../../render/syntax'
|
||||
import { parseValue } from '../../render/syntax'
|
||||
import Context from '../../context/context'
|
||||
import { isArray } from '../../util/underscore'
|
||||
import { FilterImplOptions } from './filter-impl-options'
|
||||
|
||||
export type FilterArgs = Array<string|[string?, string?]>
|
||||
type KeyValuePair = [string?, string?]
|
||||
type FilterArg = string|KeyValuePair
|
||||
export type FilterArgs = Array<FilterArg>
|
||||
|
||||
export class Filter {
|
||||
name: string
|
||||
@@ -22,8 +24,8 @@ export class Filter {
|
||||
async render (value: any, context: Context) {
|
||||
const argv: any[] = []
|
||||
for (const arg of this.args) {
|
||||
if (isArray(arg)) argv.push([arg[0], await evalValue(arg[1], context)])
|
||||
else argv.push(await evalValue(arg, context))
|
||||
if (isKeyValuePair(arg)) argv.push([arg[0], await parseValue(arg[1], context)])
|
||||
else argv.push(await parseValue(arg, context))
|
||||
}
|
||||
return this.impl.apply({ context }, [value, ...argv])
|
||||
}
|
||||
@@ -34,3 +36,7 @@ export class Filter {
|
||||
Filter.impls = {}
|
||||
}
|
||||
}
|
||||
|
||||
function isKeyValuePair (arr: FilterArg): arr is KeyValuePair {
|
||||
return isArray(arr)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Value from './value'
|
||||
import { stringify } from '../util/underscore'
|
||||
import { stringify, toValue } from '../util/underscore'
|
||||
import Template from '../template/template'
|
||||
import ITemplate from '../template/itemplate'
|
||||
import Context from '../context/context'
|
||||
@@ -12,7 +12,7 @@ export default class Output extends Template<OutputToken> implements ITemplate {
|
||||
this.value = new Value(token.value, strictFilters)
|
||||
}
|
||||
async render (ctx: Context): Promise<string> {
|
||||
const html = await this.value.value(ctx)
|
||||
return stringify(html)
|
||||
const val = await this.value.value(ctx)
|
||||
return stringify(toValue(val))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { hashCapture } from '../../parser/lexical'
|
||||
import { evalValue } from '../../render/syntax'
|
||||
import { parseValue } from '../../render/syntax'
|
||||
import Context from '../../context/context'
|
||||
|
||||
/**
|
||||
@@ -17,7 +17,7 @@ export default class Hash {
|
||||
while ((match = hashCapture.exec(markup))) {
|
||||
const k = match[1]
|
||||
const v = match[2]
|
||||
instance[k] = await evalValue(v, ctx)
|
||||
instance[k] = await parseValue(v, ctx)
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { evalExp } from '../render/syntax'
|
||||
import { parseExp } from '../render/syntax'
|
||||
import { FilterArgs, Filter } from './filter/filter'
|
||||
import Context from '../context/context'
|
||||
|
||||
@@ -48,7 +48,7 @@ export default class Value {
|
||||
this.filters.push(new Filter(name, args, this.strictFilters))
|
||||
}
|
||||
async value (ctx: Context) {
|
||||
let val = await evalExp(this.initial, ctx)
|
||||
let val = await parseExp(this.initial, ctx)
|
||||
for (const filter of this.filters) {
|
||||
val = await filter.render(val, ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user