@11ty/eleventy-plugin-webc 0.11.0 → 0.11.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@11ty/eleventy-plugin-webc",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1-alpha.1",
|
|
4
4
|
"description": "WebC support for Eleventy adds for Single File Web Components",
|
|
5
5
|
"main": "eleventyWebcPlugin.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"node": ">=14.18"
|
|
15
15
|
},
|
|
16
16
|
"11ty": {
|
|
17
|
-
"compatibility": ">=2.0.0
|
|
17
|
+
"compatibility": ">=2.0.0"
|
|
18
18
|
},
|
|
19
19
|
"funding": {
|
|
20
20
|
"type": "opencollective",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
]
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@11ty/eleventy": "^2.0.0",
|
|
46
45
|
"@11ty/eleventy-plugin-bundle": "^1.0.4",
|
|
47
46
|
"@11ty/webc": "^0.11.0"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
49
|
+
"@11ty/eleventy": "^2.0.0",
|
|
50
50
|
"ava": "^5.2.0",
|
|
51
|
-
"node-retrieve-globals": "^2.0.
|
|
51
|
+
"node-retrieve-globals": "^2.0.8"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -17,6 +17,19 @@ function relativePath(inputPath, newGlob) {
|
|
|
17
17
|
return templateRelativePath;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
function addContextToJavaScriptFunction(data, fn) {
|
|
21
|
+
let CONTEXT_KEYS = ["eleventy", "page"];
|
|
22
|
+
return function (...args) {
|
|
23
|
+
for (let key of CONTEXT_KEYS) {
|
|
24
|
+
if (data && data[key]) {
|
|
25
|
+
this[key] = data[key];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return fn.call(this, ...args);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
module.exports = function(eleventyConfig, options = {}) {
|
|
21
34
|
// TODO remove this when WebC is moved out of plugin-land into core.
|
|
22
35
|
eleventyConfig.addTemplateFormats("webc");
|
|
@@ -94,12 +107,6 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
94
107
|
page.defineComponents(componentsMap);
|
|
95
108
|
}
|
|
96
109
|
|
|
97
|
-
// Add Eleventy JavaScript Functions as WebC helpers
|
|
98
|
-
// Note that Universal Filters and Shortcodes populate into javascriptFunctions and will be present here
|
|
99
|
-
for(let helperName in this.config.javascriptFunctions) {
|
|
100
|
-
page.setHelper(helperName, this.config.javascriptFunctions[helperName], scopedHelpers.has(helperName));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
110
|
// Support both casings (I prefer getCss, but yeah)
|
|
104
111
|
page.setHelper("getCss", (url, bucket) => this.config.javascriptFunctions.getBundle("css", bucket), scopedHelpers.has("getCss"));
|
|
105
112
|
page.setHelper("getCSS", (url, bucket) => this.config.javascriptFunctions.getBundle("css", bucket), scopedHelpers.has("getCSS"));
|
|
@@ -120,6 +127,13 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
120
127
|
|
|
121
128
|
// Render function
|
|
122
129
|
return async (data) => {
|
|
130
|
+
// Add Eleventy JavaScript Functions as WebC helpers
|
|
131
|
+
// Note that Universal Filters and Shortcodes populate into javascriptFunctions and will be present here
|
|
132
|
+
for(let helperName in this.config.javascriptFunctions) {
|
|
133
|
+
let helperFunction = addContextToJavaScriptFunction(data, this.config.javascriptFunctions[helperName]);
|
|
134
|
+
page.setHelper(helperName, helperFunction, scopedHelpers.has(helperName));
|
|
135
|
+
}
|
|
136
|
+
|
|
123
137
|
let setupObject = {
|
|
124
138
|
data,
|
|
125
139
|
};
|
|
@@ -5,6 +5,8 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
5
5
|
componentsMap = false;
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
+
let scopedHelpers = new Set(options.scopedHelpers);
|
|
9
|
+
|
|
8
10
|
eleventyConfig.addTransform("@11ty/eleventy-plugin-webc", async function(content) {
|
|
9
11
|
// Skip non-.html output
|
|
10
12
|
// Skip .webc input
|
|
@@ -19,7 +21,11 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
19
21
|
let page = new WebC();
|
|
20
22
|
|
|
21
23
|
if(componentsMap === false && options.components) {
|
|
22
|
-
componentsMap = WebC.getComponentsMap(options.components); // "./
|
|
24
|
+
componentsMap = WebC.getComponentsMap(options.components); // "./_components/**/*.webc"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for(let helperName in eleventyConfig.javascriptFunctions) {
|
|
28
|
+
page.setHelper(helperName, eleventyConfig.javascriptFunctions[helperName], scopedHelpers.has(helperName));
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
page.setBundlerMode(false);
|