diff --git a/src/Engines/Liquid.js b/src/Engines/Liquid.js index c45daf41f..876d5c1fb 100644 --- a/src/Engines/Liquid.js +++ b/src/Engines/Liquid.js @@ -93,7 +93,7 @@ class Liquid extends TemplateEngine { } } - static async parseArguments(lexer, str, scope, engine) { + static parseArguments(lexer, str) { let argArray = []; if (!lexer) { @@ -101,9 +101,8 @@ class Liquid extends TemplateEngine { } if (typeof str === "string") { - // TODO key=value key2=value - // TODO JSON? lexer.reset(str); + let arg = lexer.next(); while (arg) { /*{ @@ -119,13 +118,14 @@ class Liquid extends TemplateEngine { // Push the promise into an array instead of awaiting it here. // This forces the promises to run in order with the correct scope value for each arg. // Otherwise they run out of order and can lead to undefined values for arguments in layout template shortcodes. - argArray.push(engine.evalValue(arg.value, scope)); + // console.log( arg.value, scope, engine ); + argArray.push(arg.value); } arg = lexer.next(); } } - return await Promise.all(argArray); + return argArray; } static _normalizeShortcodeScope(ctx) { @@ -139,26 +139,26 @@ class Liquid extends TemplateEngine { addShortcode(shortcodeName, shortcodeFn) { let _t = this; - this.addTag(shortcodeName, function () { + this.addTag(shortcodeName, function (liquidEngine) { return { - parse: function (tagToken) { + parse(tagToken) { this.name = tagToken.name; this.args = tagToken.args; }, - render: async function (scope) { - let argArray = await Liquid.parseArguments( - _t.argLexer, - this.args, - scope, - this.liquid - ); - - return Promise.resolve( - shortcodeFn.call( - Liquid._normalizeShortcodeScope(scope), - ...argArray - ) + render: function* (ctx) { + let rawArgs = Liquid.parseArguments(_t.argLexer, this.args); + let argArray = []; + for (let arg of rawArgs) { + let b = yield liquidEngine.evalValue(arg, ctx); + argArray.push(b); + } + + let ret = shortcodeFn.call( + Liquid._normalizeShortcodeScope(ctx), + ...argArray ); + yield ret; + return ret; }, }; }); @@ -168,7 +168,7 @@ class Liquid extends TemplateEngine { let _t = this; this.addTag(shortcodeName, function (liquidEngine) { return { - parse: function (tagToken, remainTokens) { + parse(tagToken, remainTokens) { this.name = tagToken.name; this.args = tagToken.args; this.templates = []; @@ -184,21 +184,25 @@ class Liquid extends TemplateEngine { stream.start(); }, render: function* (ctx) { - let argArray = yield Liquid.parseArguments( - _t.argLexer, - this.args, - ctx, - this.liquid - ); - const html = yield this.liquid.renderer.renderTemplates( + let rawArgs = Liquid.parseArguments(_t.argLexer, this.args); + let argArray = []; + for (let arg of rawArgs) { + let b = yield liquidEngine.evalValue(arg, ctx); + argArray.push(b); + } + + const html = yield liquidEngine.renderer.renderTemplates( this.templates, ctx ); - return shortcodeFn.call( + + let ret = shortcodeFn.call( Liquid._normalizeShortcodeScope(ctx), html, ...argArray ); + yield ret; + return ret; }, }; }); diff --git a/src/Plugins/RenderPlugin.js b/src/Plugins/RenderPlugin.js index f9458efa5..0e052ab51 100644 --- a/src/Plugins/RenderPlugin.js +++ b/src/Plugins/RenderPlugin.js @@ -151,7 +151,7 @@ function EleventyPlugin(eleventyConfig, options = {}) { stream.start(); }, - render: async function (ctx) { + render: function* (ctx) { let normalizedContext = {}; if (ctx) { if (opts.accessGlobalData) { @@ -163,21 +163,24 @@ function EleventyPlugin(eleventyConfig, options = {}) { normalizedContext.eleventy = ctx.get(["eleventy"]); } - let argArray = await Liquid.parseArguments( - null, - this.args, - ctx, - this.liquid - ); + let rawArgs = Liquid.parseArguments(null, this.args); + let argArray = []; + for (let arg of rawArgs) { + let b = yield liquidEngine.evalValue(arg, ctx); + argArray.push(b); + } + // plaintext paired shortcode content let body = this.tokens.map((token) => token.getText()).join(""); - return _renderStringShortcodeFn.call( + let ret = _renderStringShortcodeFn.call( normalizedContext, body, // templateLang, data ...argArray ); + yield ret; + return ret; }, }; }