Skip to content

Commit

Permalink
feat: upgrade liquidjs to ^9.28.4, fixes 11ty#1995
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Nov 5, 2021
1 parent a9c29f4 commit 6246e24
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"husky": "^7.0.4",
"js-yaml": "^4.1.0",
"lint-staged": "^11.2.5",
"liquidjs": "^9.28.4",
"markdown-it-emoji": "^2.0.0",
"nyc": "^15.1.0",
"prettier": "^2.4.1",
Expand All @@ -104,7 +105,6 @@
"hamljs": "^0.6.2",
"handlebars": "^4.7.7",
"is-glob": "^4.0.3",
"liquidjs": "9.25.1",
"lodash": "^4.17.21",
"luxon": "^2.0.2",
"markdown-it": "^12.2.0",
Expand Down
78 changes: 62 additions & 16 deletions test/TemplateRenderLiquidTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const test = require("ava");
const TemplateRender = require("../src/TemplateRender");
const TemplateConfig = require("../src/TemplateConfig");
const EleventyExtensionMap = require("../src/EleventyExtensionMap");
const { Drop } = require("liquidjs");

function getNewTemplateRender(name, inputDir, userConfig = {}) {
let eleventyConfig = new TemplateConfig();
function getNewTemplateRender(name, inputDir, userConfig = {}, templateConfig) {
let eleventyConfig = new TemplateConfig(templateConfig);
for (let key in userConfig) {
eleventyConfig.userConfig[key] = userConfig[key];
}
Expand Down Expand Up @@ -102,6 +103,11 @@ test("Liquid Render Relative (current dir) Include", async (t) => {
liquidOptions: {
dynamicPartials: false,
},
},
{
dir: {
includes: "relative-liquid",
},
}
);

Expand All @@ -117,17 +123,28 @@ test("Liquid Render Relative (parent dir) Include", async (t) => {
liquidOptions: {
dynamicPartials: false,
},
},
{
dir: {
includes: "relative-liquid",
},
}
);

let fn = await tr.getCompiledTemplate("<p>{% include ../dir/included %}</p>");
t.is(await fn(), "<p>TIME IS RELATIVE.</p>");
});

test.skip("Liquid Render Relative (relative include should ignore _includes dir) Include", async (t) => {
test("Liquid Render Relative (relative include should ignore _includes dir) Include", async (t) => {
let tr = getNewTemplateRender(
"./test/stubs/does_not_exist_and_thats_ok.liquid",
"./test/stubs/"
"./test/stubs/",
{},
{
dir: {
includes: ".",
},
}
);

let fn = await tr.getCompiledTemplate(`<p>{% include './included' %}</p>`);
Expand Down Expand Up @@ -575,7 +592,13 @@ test("Liquid Render Include Subfolder Single quotes no extension dynamicPartials
test("Liquid Render Include Subfolder Single quotes (relative include current dir) dynamicPartials true", async (t) => {
let tr = getNewTemplateRender(
"./test/stubs/does_not_exist_and_thats_ok.liquid",
"./test/stubs/"
"./test/stubs/",
{},
{
dir: {
includes: "relative-liquid",
},
}
);
let fn = await tr.getCompiledTemplate(
`<p>{% include './relative-liquid/dir/included' %}</p>`
Expand All @@ -586,7 +609,13 @@ test("Liquid Render Include Subfolder Single quotes (relative include current di
test("Liquid Render Include Subfolder Single quotes (relative include parent dir) dynamicPartials true", async (t) => {
let tr = getNewTemplateRender(
"./test/stubs/subfolder/does_not_exist_and_thats_ok.liquid",
"./test/stubs/"
"./test/stubs/",
{},
{
dir: {
includes: "relative-liquid",
},
}
);
let fn = await tr.getCompiledTemplate(
`<p>{% include '../relative-liquid/dir/included' %}</p>`
Expand Down Expand Up @@ -704,17 +733,32 @@ test("Liquid Shortcode Multiple Args", async (t) => {
);
});

test.skip("Liquid Include Scope Leak", async (t) => {
test("Liquid Include Scope Leak", async (t) => {
t.is(
getNewTemplateRender("liquid", "./test/stubs/").getEngineName(),
"liquid"
);

// This might be by design?
// This is by design, `include` assigns value to its parent scope,
// use `{% render %}` for separated, clean scope
// see: https://github.com/harttle/liquidjs/issues/404#issuecomment-955660149
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% include scopeleak %}{{ test }}</p>");
).getCompiledTemplate("<p>{% include 'scopeleak' %}{{ test }}</p>");
t.is(await fn({ test: 1 }), "<p>22</p>");
});

test("Liquid Render Scope Leak", async (t) => {
t.is(
getNewTemplateRender("liquid", "./test/stubs/").getEngineName(),
"liquid"
);

let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% render 'scopeleak' %}{{ test }}</p>");
t.is(await fn({ test: 1 }), "<p>21</p>");
});

Expand Down Expand Up @@ -957,15 +1001,17 @@ test("Issue 600: Liquid Shortcode argument with underscores", async (t) => {
);
});

test.skip("Issue 611: Run a function", async (t) => {
// This works in Nunjucks
test("Issue 611: Run a function", async (t) => {
// function calls in Nunjucks can be replaced by custom Drops
let tr = getNewTemplateRender("liquid", "./test/stubs/");

class CustomDrop extends Drop {
valueOf() {
return "alkdsjfksljaZach";
}
}
t.is(
await tr._testRender("{{ test() }}", {
test: function () {
return "alkdsjfksljaZach";
},
await tr._testRender("{{ test }}", {
test: new CustomDrop(),
}),
"alkdsjfksljaZach"
);
Expand Down

0 comments on commit 6246e24

Please sign in to comment.