fix: pass drops directly to filters/tags

This commit is contained in:
harttle
2019-05-12 20:03:32 +08:00
parent 4282accaa2
commit bef290923c
15 changed files with 93 additions and 42 deletions
+4 -1
View File
@@ -1,5 +1,8 @@
import { isFalsy } from '../../render/syntax'
import { toValue } from '../../util/underscore'
export default {
'default': <T1, T2>(v: string | T1, arg: T2): string | T1 | T2 => isFalsy(v) || v === '' ? arg : v
'default': function<T1, T2> (v: string | T1, arg: T2): string | T1 | T2 {
return isFalsy(toValue(v)) || v === '' ? arg : v
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { isString, isObject, isArray } from '../../util/underscore'
import { evalExp } from '../../render/syntax'
import { parseExp } from '../../render/syntax'
import assert from '../../util/assert'
import { identifier, value, hash } from '../../parser/lexical'
import TagToken from '../../parser/tag-token'
@@ -42,7 +42,7 @@ export default <ITagImplOptions>{
stream.start()
},
render: async function (ctx: Context, hash: Hash) {
let collection = await evalExp(this.collection, ctx)
let collection = await parseExp(this.collection, ctx)
if (!isArray(collection)) {
if (isString(collection) && collection.length > 0) {
+5 -11
View File
@@ -1,6 +1,6 @@
import assert from '../../util/assert'
import { value, quotedLine } from '../../parser/lexical'
import { evalValue } from '../../render/syntax'
import { evalValue, parseValue } from '../../render/syntax'
import BlockMode from '../../context/block-mode'
import TagToken from '../../parser/tag-token'
import Context from '../../context/context'
@@ -13,19 +13,13 @@ const withRE = new RegExp(`with\\s+(${value.source})`)
export default <ITagImplOptions>{
parse: function (token: TagToken) {
let match = staticFileRE.exec(token.args)
if (match) {
this.staticValue = match[0]
}
if (match) this.staticValue = match[0]
match = value.exec(token.args)
if (match) {
this.value = match[0]
}
if (match) this.value = match[0]
match = withRE.exec(token.args)
if (match) {
this.with = match[1]
}
if (match) this.with = match[1]
},
render: async function (ctx: Context, hash: Hash) {
let filepath
@@ -47,7 +41,7 @@ export default <ITagImplOptions>{
ctx.setRegister('blocks', {})
ctx.setRegister('blockMode', BlockMode.OUTPUT)
if (this.with) {
hash[filepath] = await evalValue(this.with, ctx)
hash[filepath] = await parseValue(this.with, ctx)
}
const templates = await this.liquid.getTemplate(filepath, ctx.opts)
ctx.push(hash)