Skip to content

Commit

Permalink
Cherry pick #2369 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed May 9, 2022
1 parent 5cae435 commit 880255e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
29 changes: 29 additions & 0 deletions test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Eleventy = require("../src/Eleventy");
const EleventyWatchTargets = require("../src/EleventyWatchTargets");
const TemplateConfig = require("../src/TemplateConfig");
const DateGitLastUpdated = require("../src/Util/DateGitLastUpdated");
const normalizeNewLines = require("./Util/normalizeNewLines");

test("Eleventy, defaults inherit from config", async (t) => {
let elev = new Eleventy();
Expand Down Expand Up @@ -424,3 +425,31 @@ test("#142: date 'git Last Modified' populates page.date", async (t) => {
let comparisonDate = DateGitLastUpdated("./test/stubs-142/index.njk");
t.is(result.content.trim(), "" + comparisonDate.getTime());
});

test("Liquid shortcode with multiple arguments(issue #2348)", async (t) => {
// NOTE issue #2348 was only active when you were processing multiple templates at the same time.

let elev = new Eleventy("./test/stubs-2367/", "./test/stubs-2367/_site", {
config: function (eleventyConfig) {
eleventyConfig.addShortcode("simplelink", function (...args) {
return JSON.stringify(args);
});
},
});

let arr = [
"layout",
"/mylayout",
"layout",
"/mylayout",
"layout",
"/mylayout",
];
let str = normalizeNewLines(`${JSON.stringify(arr)}
${JSON.stringify(arr)}`);
let results = await elev.toJSON();
t.is(results.length, 2);
let content = results.map((entry) => entry.content).sort();
t.is(normalizeNewLines(content[0]), str);
t.is(normalizeNewLines(content[1]), str);
});
39 changes: 0 additions & 39 deletions test/TemplateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,45 +293,6 @@ test("One Layout (_layoutContent deprecated but supported)", async (t) => {
t.is(data.keylayout, "valuelayout");
});

test("Liquid shortcode with multiple arguments(issue #2348)", async (t) => {
// NOTE issue #2348 was only active when you were processing multiple templates at the same time.

let eleventyConfig = new TemplateConfig();
eleventyConfig.userConfig.addShortcode("simplelink", function (text, url) {
return `<a href="${url}">${text} (${url})</a>`;
});

let dataObj = new TemplateData("./test/stubs/", eleventyConfig);

let tmpl = getNewTemplate(
"./test/stubs/templateWithLiquidShortcodeMultipleArguments.liquid",
"./test/stubs/",
"dist",
dataObj,
null,
eleventyConfig
);

t.is(
(await tmpl.getFrontMatter()).data[tmpl.config.keys.layout],
"layoutLiquid.liquid"
);

let data = await tmpl.getData();
t.is(data[tmpl.config.keys.layout], "layoutLiquid.liquid");

t.is(
normalizeNewLines(cleanHtml(await tmpl.renderLayout(tmpl, data))),
`<div id="layout">
<p>Hello.</p>
<a href="/somepage">world (/somepage)</a>
</div>`
);

t.is(data.keymain, "valuemain");
t.is(data.keylayout, "valuelayout");
});

test("One Layout (liquid test)", async (t) => {
let eleventyConfig = new TemplateConfig();
let dataObj = new TemplateData("./test/stubs/", eleventyConfig);
Expand Down
6 changes: 6 additions & 0 deletions test/stubs-2367/_includes/layout.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
text: layout
url: "/mylayout"
---
{% simplelink text url text url text url %}
{% simplelink text, url, text, url, text, url %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
layout: layout.liquid
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
layout: layout.liquid
---

This file was deleted.

0 comments on commit 880255e

Please sign in to comment.