Skip to content

Commit

Permalink
Add test for comma separated list of bucket names
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 31, 2023
1 parent b5faeec commit 3113ac7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = function(eleventyConfig, options = {}) {
options.bundleNames.forEach(name => {
managers[name] = new CodeManager(name);

// e.g. `css` shortcode to add code to page bundle
let addShortcodeName = name;
if(options.shortcodes.add && options.shortcodes.add[name] !== undefined) {
addShortcodeName = options.shortcodes.add[name];
Expand All @@ -54,6 +55,7 @@ module.exports = function(eleventyConfig, options = {}) {
});
}

// e.g. `getPageCss` shortcode to get code in current page bundle
let getShortcodeName;
if(options.shortcodes.get && options.shortcodes.get[name] !== undefined) {
getShortcodeName = options.shortcodes.get[name];
Expand All @@ -63,6 +65,7 @@ module.exports = function(eleventyConfig, options = {}) {
if(getShortcodeName) {
isTransformNeeded = true;

// bucket can be an array
eleventyConfig.addShortcode(getShortcodeName, function getContent(bucket) {
return OutOfOrderRender.getAssetKey(name, bucket);
});
Expand Down
5 changes: 5 additions & 0 deletions test/stubs/buckets-get-multiple-comma-sep/index.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%- css "defer" %}* { color: blue; }{% endcss %}
{%- css %}* { color: blue; }{% endcss %}
{%- css "defer" %}* { color: red; }{% endcss %}
{%- css %}* { color: orange; }{% endcss -%}
<style>{% getPageCss "default,defer" %}</style>
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,13 @@ test("CSS, get two buckets at once, reverse order", async t => {
* { color: red; }
* { color: orange; }</style>`); // note that blue is only listed once, we de-dupe entries across buckets
});

test("CSS, get two buckets at once (comma separated list)", async t => {
// automatically uses eleventy.config.js in root
let elev = new Eleventy("test/stubs/buckets-get-multiple-comma-sep/");
let results = await elev.toJSON();
t.deepEqual(results[0].content, `<style>* { color: blue; }
* { color: orange; }
* { color: red; }</style>`); // note that blue is only listed once, we de-dupe entries across buckets
});

0 comments on commit 3113ac7

Please sign in to comment.