@11ty/eleventy-plugin-webc 0.10.1 → 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/eleventyWebcPlugin.js
CHANGED
|
@@ -18,6 +18,7 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
18
18
|
|
|
19
19
|
options = Object.assign({
|
|
20
20
|
components: "_components/**/*.webc", // glob for no-import global components
|
|
21
|
+
scopedHelpers: ["css", "js", "html"],
|
|
21
22
|
useTransform: false, // global transform
|
|
22
23
|
transformData: {}, // extra global data for transforms specifically
|
|
23
24
|
}, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@11ty/eleventy-plugin-webc",
|
|
3
|
-
"version": "0.
|
|
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
|
-
"@11ty/webc": "^0.
|
|
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");
|
|
@@ -25,6 +38,7 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
25
38
|
let globalComponentManager;
|
|
26
39
|
let componentsMap = false; // cache the glob search
|
|
27
40
|
let moduleScript;
|
|
41
|
+
let scopedHelpers = new Set(options.scopedHelpers);
|
|
28
42
|
|
|
29
43
|
eleventyConfig.on("eleventy.before", async () => {
|
|
30
44
|
// For ESM in CJS
|
|
@@ -93,18 +107,12 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
93
107
|
page.defineComponents(componentsMap);
|
|
94
108
|
}
|
|
95
109
|
|
|
96
|
-
// Add Eleventy JavaScript Functions as WebC helpers
|
|
97
|
-
// Note that Universal Filters and Shortcodes populate into javascriptFunctions and will be present here
|
|
98
|
-
for(let helperName in this.config.javascriptFunctions) {
|
|
99
|
-
page.setHelper(helperName, this.config.javascriptFunctions[helperName]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
110
|
// Support both casings (I prefer getCss, but yeah)
|
|
103
|
-
page.setHelper("getCss", (url, bucket) => this.config.javascriptFunctions.getBundle("css", bucket));
|
|
104
|
-
page.setHelper("getCSS", (url, bucket) => this.config.javascriptFunctions.getBundle("css", bucket));
|
|
111
|
+
page.setHelper("getCss", (url, bucket) => this.config.javascriptFunctions.getBundle("css", bucket), scopedHelpers.has("getCss"));
|
|
112
|
+
page.setHelper("getCSS", (url, bucket) => this.config.javascriptFunctions.getBundle("css", bucket), scopedHelpers.has("getCSS"));
|
|
105
113
|
|
|
106
|
-
page.setHelper("getJs", (url, bucket) => this.config.javascriptFunctions.getBundle("js", bucket));
|
|
107
|
-
page.setHelper("getJS", (url, bucket) => this.config.javascriptFunctions.getBundle("js", bucket));
|
|
114
|
+
page.setHelper("getJs", (url, bucket) => this.config.javascriptFunctions.getBundle("js", bucket), scopedHelpers.has("getJs"));
|
|
115
|
+
page.setHelper("getJS", (url, bucket) => this.config.javascriptFunctions.getBundle("js", bucket), scopedHelpers.has("getJS"));
|
|
108
116
|
|
|
109
117
|
page.setTransform("11ty", async function(content) {
|
|
110
118
|
let syntax = this["11ty:type"];
|
|
@@ -119,6 +127,13 @@ module.exports = function(eleventyConfig, options = {}) {
|
|
|
119
127
|
|
|
120
128
|
// Render function
|
|
121
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
|
+
|
|
122
137
|
let setupObject = {
|
|
123
138
|
data,
|
|
124
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);
|