mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 14:00:39 -07:00
feat: promise support for drops, working on #65
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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`)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user