docs: update docs and demo for Value usage, fixes #568

This commit is contained in:
Harttle
2022-12-14 02:14:03 +08:00
committed by Harttle
parent a9f93d7235
commit d24655887f
12 changed files with 187 additions and 127 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ export class Liquid {
public _evalValue (str: string, scope?: object | Context): IterableIterator<any> {
const value = new Value(str, this)
const ctx = scope instanceof Context ? scope : new Context(scope, this.options)
return value.value(ctx, false)
return value.value(ctx)
}
public async evalValue (str: string, scope?: object | Context): Promise<any> {
return toPromise(this._evalValue(str, scope))
+1 -1
View File
@@ -17,7 +17,7 @@ export class Value {
this.initial = tokenizer.readExpression()
this.filters = tokenizer.readFilters().map(({ name, args }) => new Filter(name, this.getFilter(liquid, name), args, liquid))
}
public * value (ctx: Context, lenient: boolean): Generator<unknown, unknown, unknown> {
public * value (ctx: Context, lenient?: boolean): Generator<unknown, unknown, unknown> {
lenient = lenient || (ctx.opts.lenientIf && this.filters.length > 0 && this.filters[0].name === 'default')
let val = yield this.initial.evaluate(ctx, lenient)