Skip to content

Commit

Permalink
Changes dynamicPartials default from false to true. Fixes #240
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 12, 2021
1 parent 70133c0 commit 2623e77
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/Engines/Liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Liquid extends TemplateEngine {
let defaults = {
root: [super.getIncludesDir()], // overrides in compile with inputPath below
extname: ".liquid",
dynamicPartials: false,
dynamicPartials: true,
strictFilters: true,
// TODO?
// cache: true,
Expand Down
163 changes: 82 additions & 81 deletions test/TemplateRenderLiquidTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ test("Liquid Render Include", async (t) => {
"liquid"
);

let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% include included %}</p>");
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate("<p>{% include included %}</p>");
t.is(await fn(), "<p>This is an include.</p>");
});

Expand All @@ -77,26 +78,35 @@ test("Liquid Render Relative Include", async (t) => {
"liquid"
);

let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% include ./included %}</p>");
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate("<p>{% include ./included %}</p>");
t.is(await fn(), "<p>This is an include.</p>");
});

test("Liquid Render Relative (current dir) Include", async (t) => {
let fn = await getNewTemplateRender(
let tr = await getNewTemplateRender(
"./test/stubs/relative-liquid/does_not_exist_and_thats_ok.liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% include ./dir/included %}</p>");
);
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate("<p>{% include ./dir/included %}</p>");
t.is(await fn(), "<p>TIME IS RELATIVE.</p>");
});

test("Liquid Render Relative (parent dir) Include", async (t) => {
let fn = await getNewTemplateRender(
let tr = await getNewTemplateRender(
"./test/stubs/relative-liquid/dir/does_not_exist_and_thats_ok.liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% include ../dir/included %}</p>");
);
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate("<p>{% include ../dir/included %}</p>");
t.is(await fn(), "<p>TIME IS RELATIVE.</p>");
});

Expand All @@ -106,7 +116,7 @@ test.skip("Liquid Render Relative (relative include should ignore _includes dir)
"./test/stubs/"
);

let fn = await tr.getCompiledTemplate(`<p>{% include ./included %}</p>`);
let fn = await tr.getCompiledTemplate(`<p>{% include './included' %}</p>`);

// This is currently wrong, it uses _includes/included.liquid instead of ./included.liquid
// Not changing the above to ../stubs/included works fine because that’s not an ambiguous reference.
Expand All @@ -119,10 +129,11 @@ test("Liquid Render Include with Liquid Suffix", async (t) => {
"liquid"
);

let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% include included.liquid %}</p>");
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate("<p>{% include included.liquid %}</p>");
t.is(await fn(), "<p>This is an include.</p>");
});

Expand All @@ -132,10 +143,11 @@ test("Liquid Render Include with HTML Suffix", async (t) => {
"liquid"
);

let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate("<p>{% include included.html %}</p>");
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate("<p>{% include included.html %}</p>");
t.is(await fn(), "<p>This is an include.</p>");
});

Expand All @@ -145,10 +157,11 @@ test("Liquid Render Include with HTML Suffix and Data Pass in", async (t) => {
"liquid"
);

let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate(
"{% include included-data.html, myVariable: 'myValue' %}"
);
t.is((await fn()).trim(), "This is an include. myValue");
Expand Down Expand Up @@ -432,93 +445,99 @@ test("Liquid Async Paired Shortcode", async (t) => {
});

test("Liquid Render Include Subfolder", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include subfolder/included.liquid %}</p>`);
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate(
`<p>{% include subfolder/included.liquid %}</p>`
);
t.is(await fn(), "<p>This is an include.</p>");
});

test("Liquid Render Include Subfolder HTML", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include subfolder/included.html %}</p>`);
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate(
`<p>{% include subfolder/included.html %}</p>`
);
t.is(await fn(), "<p>This is an include.</p>");
});

test("Liquid Render Include Subfolder No file extension", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include subfolder/included %}</p>`);
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({
dynamicPartials: false,
});
let fn = await tr.getCompiledTemplate(
`<p>{% include subfolder/included %}</p>`
);
t.is(await fn(), "<p>This is an include.</p>");
});

// Skipped tests pending https://github.com/harttle/liquidjs/issues/61
// Resolution: we’re going to leave this skipped as LiquidJS will require dynamicPartials
// to be on for quoted includes!
test.skip("Liquid Render Include Subfolder Single quotes", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include 'subfolder/included.liquid' %}</p>`);
// Related to https://github.com/harttle/liquidjs/issues/61
// Note that we swapped the dynamicPartials default in Eleventy 1.0 from false to true
test("Liquid Render Include Subfolder Single quotes", async (t) => {
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
let fn = await tr.getCompiledTemplate(
`<p>{% include 'subfolder/included.liquid' %}</p>`
);
t.is(await fn(), "<p>This is an include.</p>");
});

test.skip("Liquid Render Include Subfolder Double quotes", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include "subfolder/included.liquid" %}</p>`);
test("Liquid Render Include Subfolder Double quotes", async (t) => {
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
let fn = await tr.getCompiledTemplate(
`<p>{% include "subfolder/included.liquid" %}</p>`
);
t.is(await fn(), "<p>This is an include.</p>");
});

test.skip("Liquid Render Include Subfolder Single quotes HTML", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include 'subfolder/included.html' %}</p>`);
test("Liquid Render Include Subfolder Single quotes HTML", async (t) => {
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
let fn = await tr.getCompiledTemplate(
`<p>{% include 'subfolder/included.html' %}</p>`
);
t.is(await fn(), "<p>This is an include.</p>");
});

test.skip("Liquid Render Include Subfolder Double quotes HTML", async (t) => {
test("Liquid Render Include Subfolder Double quotes HTML", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include "subfolder/included.html" %}</p>`);
t.is(await fn(), "<p>This is an include.</p>");
});

test.skip("Liquid Render Include Subfolder Single quotes No file extension", async (t) => {
test("Liquid Render Include Subfolder Single quotes No file extension", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include 'subfolder/included' %}</p>`);
t.is(await fn(), "<p>This is an include.</p>");
});

test.skip("Liquid Render Include Subfolder Double quotes No file extension", async (t) => {
test("Liquid Render Include Subfolder Double quotes No file extension", async (t) => {
let fn = await getNewTemplateRender(
"liquid",
"./test/stubs/"
).getCompiledTemplate(`<p>{% include "subfolder/included" %}</p>`);
t.is(await fn(), "<p>This is an include.</p>");
});
/* End skipped tests */
/* End tests related to dynamicPartials */

test("Liquid Options Overrides", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });
tr.engine.setLiquidOptions({ dynamicPartials: false });

let options = tr.engine.getLiquidOptions();
t.is(options.dynamicPartials, true);
t.is(options.dynamicPartials, false);
});

test("Liquid Render Include Subfolder Single quotes no extension dynamicPartials true", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include 'subfolder/included' %}</p>`
);
Expand All @@ -530,8 +549,6 @@ test("Liquid Render Include Subfolder Single quotes (relative include current di
"./test/stubs/does_not_exist_and_thats_ok.liquid",
"./test/stubs/"
);
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include './relative-liquid/dir/included' %}</p>`
);
Expand All @@ -543,8 +560,6 @@ test("Liquid Render Include Subfolder Single quotes (relative include parent dir
"./test/stubs/subfolder/does_not_exist_and_thats_ok.liquid",
"./test/stubs/"
);
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include '../relative-liquid/dir/included' %}</p>`
);
Expand All @@ -553,8 +568,6 @@ test("Liquid Render Include Subfolder Single quotes (relative include parent dir

test("Liquid Render Include Subfolder Double quotes no extension dynamicPartials true", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include "subfolder/included" %}</p>`
);
Expand All @@ -563,8 +576,6 @@ test("Liquid Render Include Subfolder Double quotes no extension dynamicPartials

test("Liquid Render Include Subfolder Single quotes dynamicPartials true", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include 'subfolder/included.liquid' %}</p>`
);
Expand All @@ -573,8 +584,6 @@ test("Liquid Render Include Subfolder Single quotes dynamicPartials true", async

test("Liquid Render Include Subfolder Double quotes dynamicPartials true", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include "subfolder/included.liquid" %}</p>`
);
Expand All @@ -583,8 +592,6 @@ test("Liquid Render Include Subfolder Double quotes dynamicPartials true", async

test("Liquid Render Include Subfolder Single quotes HTML dynamicPartials true", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include 'subfolder/included.html' %}</p>`
);
Expand All @@ -593,8 +600,6 @@ test("Liquid Render Include Subfolder Single quotes HTML dynamicPartials true",

test("Liquid Render Include Subfolder Double quotes HTML dynamicPartials true", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include "subfolder/included.html" %}</p>`
);
Expand All @@ -603,8 +608,6 @@ test("Liquid Render Include Subfolder Double quotes HTML dynamicPartials true",

test("Liquid Render Include Subfolder Single quotes HTML dynamicPartials true, data passed in", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include 'subfolder/included.html', myVariable: 'myValue' %}</p>`
);
Expand All @@ -613,8 +616,6 @@ test("Liquid Render Include Subfolder Single quotes HTML dynamicPartials true, d

test("Liquid Render Include Subfolder Double quotes HTML dynamicPartials true, data passed in", async (t) => {
let tr = getNewTemplateRender("liquid", "./test/stubs/");
tr.engine.setLiquidOptions({ dynamicPartials: true });

let fn = await tr.getCompiledTemplate(
`<p>{% include "subfolder/included.html", myVariable: "myValue" %}</p>`
);
Expand Down
2 changes: 1 addition & 1 deletion test/stubs-layout-cache/_includes/layout.liquid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<script>{%- include include-script-2.js -%}</script>
<script>{%- include 'include-script-2.js' -%}</script>
2 changes: 1 addition & 1 deletion test/stubs/includer.liquid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>{% include included %}</p>
<p>{% include 'included' %}</p>

0 comments on commit 2623e77

Please sign in to comment.