Skip to content

Commit

Permalink
Proposed fix for #22 but it was passing prior to code change
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 2, 2022
1 parent d83cb7a commit f7bc146
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/eleventyWebcTemplate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");

const { EleventyRenderPlugin } = require("@11ty/eleventy");
const EleventyRenderManager = EleventyRenderPlugin.RenderManager;
const CompileString = EleventyRenderPlugin.String;

const CodeManager = require("./codeManager.js");
const WebCIncremental = require("./incremental.js");
Expand All @@ -22,7 +22,6 @@ function relativePath(inputPath, newGlob) {
module.exports = function(eleventyConfig, options = {}) {
eleventyConfig.addTemplateFormats("webc");

let renderManager = new EleventyRenderManager();
let cssManager = new CodeManager();
let jsManager = new CodeManager();
let incremental = new WebCIncremental();
Expand Down Expand Up @@ -112,8 +111,10 @@ module.exports = function(eleventyConfig, options = {}) {
page.setTransform("11ty", async function(content) {
let syntax = this["11ty:type"];
if(syntax) {
let fn = await renderManager.compile(content, syntax);
return renderManager.render(fn, this, {});
let fn = await CompileString(content, syntax, {
templateConfig: eleventyConfig
});
return fn(data);
}
return content;
});
Expand Down
10 changes: 10 additions & 0 deletions test/render-plugin/eleventy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const EleventyWebcPlugin = require("../../eleventyWebcPlugin.js");
const { EleventyRenderPlugin } = require("@11ty/eleventy");

module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(EleventyWebcPlugin, {
components: "./test/render-plugin/webc/*.webc"
});

eleventyConfig.addPlugin(EleventyRenderPlugin);
}
3 changes: 3 additions & 0 deletions test/render-plugin/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hello

<p>{% renderTemplate "webc" %}<my-component></my-component>{% endrenderTemplate %}</p>
1 change: 1 addition & 0 deletions test/render-plugin/webc/my-component.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My component<slot></slot>
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,17 @@ test("Add JS Functions as helpers (universal filters) (issue #3)", async t => {
<body>helloAlways return this</body>
</html>`);
});



test("Use render plugin #22", async t => {
let elev = new Eleventy("./test/render-plugin/page.md", "./test/render-plugin/_site", {
configPath: "./test/render-plugin/eleventy.config.js"
});

let results = await elev.toJSON();
let [result] = results;

t.is(normalize(result.content), `<h1>Hello</h1>
<p>My component</p>`);
});

0 comments on commit f7bc146

Please sign in to comment.