feat: promise support for drops, working on #65

This commit is contained in:
Jun Yang
2019-03-10 18:05:52 +08:00
parent ad0930f152
commit 4a8088d4e4
25 changed files with 260 additions and 250 deletions
+2 -3
View File
@@ -14,10 +14,9 @@ export default {
this.key = match[1]
this.value = match[2]
},
render: function (scope: Scope) {
render: async function (scope: Scope) {
const ctx = new AssignScope()
ctx[this.key] = this.liquid.evalValue(this.value, scope)
ctx[this.key] = await this.liquid.evalValue(this.value, scope)
scope.push(ctx)
return Promise.resolve('')
}
} as ITagImplOptions
+3 -3
View File
@@ -30,11 +30,11 @@ export default {
stream.start()
},
render: function (scope: Scope) {
render: async function (scope: Scope) {
for (let i = 0; i < this.cases.length; i++) {
const branch = this.cases[i]
const val = evalExp(branch.val, scope)
const cond = evalExp(this.cond, scope)
const val = await evalExp(branch.val, scope)
const cond = await evalExp(this.cond, scope)
if (val === cond) {
return this.liquid.renderer.renderTemplates(branch.templates, scope)
}
+2 -2
View File
@@ -24,8 +24,8 @@ export default <ITagImplOptions>{
assert(this.candidates.length, `empty candidates: ${tagToken.raw}`)
},
render: function (scope: Scope) {
const group = evalValue(this.group, scope)
render: async function (scope: Scope) {
const group = await evalValue(this.group, scope)
const fingerprint = `cycle:${group}:` + this.candidates.join(',')
const groups = scope.groups
let idx = groups[fingerprint]
+1 -1
View File
@@ -42,7 +42,7 @@ export default <ITagImplOptions>{
stream.start()
},
render: async function (scope: Scope, hash: Hash) {
let collection = evalExp(this.collection, scope)
let collection = await evalExp(this.collection, scope)
if (!isArray(collection)) {
if (isString(collection) && collection.length > 0) {
+2 -2
View File
@@ -33,9 +33,9 @@ export default {
stream.start()
},
render: function (scope: Scope) {
render: async function (scope: Scope) {
for (const branch of this.branches) {
const cond = evalExp(branch.cond, scope)
const cond = await evalExp(branch.cond, scope)
if (isTruthy(cond)) {
return this.liquid.renderer.renderTemplates(branch.templates, scope)
}
+2 -2
View File
@@ -34,7 +34,7 @@ export default <ITagImplOptions>{
const template = this.value.slice(1, -1)
filepath = await this.liquid.parseAndRender(template, scope.getAll(), scope.opts)
} else {
filepath = evalValue(this.value, scope)
filepath = await evalValue(this.value, scope)
}
} else {
filepath = this.staticValue
@@ -47,7 +47,7 @@ export default <ITagImplOptions>{
scope.blocks = {}
scope.blockMode = BlockMode.OUTPUT
if (this.with) {
hash[filepath] = evalValue(this.with, scope)
hash[filepath] = await evalValue(this.with, scope)
}
const templates = await this.liquid.getTemplate(filepath, scope.opts)
scope.push(hash)
+1 -1
View File
@@ -26,7 +26,7 @@ export default {
},
render: async function (scope: Scope, hash: Hash) {
const layout = scope.opts.dynamicPartials
? evalValue(this.layout, scope)
? await evalValue(this.layout, scope)
: this.staticLayout
assert(layout, `cannot apply layout with empty filename`)
+1 -1
View File
@@ -36,7 +36,7 @@ export default {
},
render: async function (scope: Scope, hash: Hash) {
let collection = evalExp(this.collection, scope) || []
let collection = await evalExp(this.collection, scope) || []
const offset = hash.offset || 0
const limit = (hash.limit === undefined) ? collection.length : hash.limit
+2 -2
View File
@@ -25,8 +25,8 @@ export default {
stream.start()
},
render: function (scope: Scope) {
const cond = evalExp(this.cond, scope)
render: async function (scope: Scope) {
const cond = await evalExp(this.cond, scope)
return isFalsy(cond)
? this.liquid.renderer.renderTemplates(this.templates, scope)
: this.liquid.renderer.renderTemplates(this.elseTemplates, scope)