Skip to content

Commit

Permalink
Fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 16, 2022
1 parent 0df5672 commit 79450f9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
]
},
"dependencies": {
"@11ty/eleventy": "^2.0.0-canary.16",
"@11ty/eleventy": "^2.0.0-canary.17",
"@11ty/webc": "^0.7.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/eleventyWebcTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = function(eleventyConfig, options = {}) {
let fn = await CompileString(content, syntax, {
templateConfig: eleventyConfig
});
return fn(data);
return fn(this);
}
return content;
});
Expand Down
1 change: 1 addition & 0 deletions test/shortcodes-issue-16/_components/say-hello.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPONENTS DIR
17 changes: 17 additions & 0 deletions test/shortcodes-issue-16/eleventy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const EleventyWebcPlugin = require("../../eleventyWebcPlugin.js");

module.exports = function (eleventyConfig) {
eleventyConfig.addShortcode("testing", () => {
// WebC in a shortcode!
return "<undefined-component></undefined-component><say-hello></say-hello>";
});

eleventyConfig.addFilter("uppercase", (str) => {
return str.toUpperCase();
});


eleventyConfig.addPlugin(EleventyWebcPlugin, {
components: "./test/shortcodes-issue-16/_components/*.webc"
});
};
8 changes: 8 additions & 0 deletions test/shortcodes-issue-16/page.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
frontmatterdata: "HELLO FROM FRONT MATTER"
---
<template webc:type="11ty" 11ty:type="liquid">
{{frontmatterdata}}
{% testing %}
{{ "lowercase" | uppercase }}
</template>
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,15 @@ hi
</html>`);
});


test("Shortcodes, issue #16", async t => {
let elev = new Eleventy("./test/shortcodes-issue-16/page.webc", "./test/shortcodes-issue-16/_site", {
configPath: "./test/shortcodes-issue-16/eleventy.config.js"
});

let results = await elev.toJSON();
let [result] = results;
t.is(normalize(result.content), `HELLO FROM FRONT MATTER
<undefined-component></undefined-component>COMPONENTS DIR
LOWERCASE`);
});

0 comments on commit 79450f9

Please sign in to comment.