Skip to content

Commit

Permalink
Fix embed matching for single 0-indexed test attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Jan 16, 2024
1 parent 2428888 commit 30815e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/embed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 DigitalOcean
Copyright 2024 DigitalOcean
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,8 +29,11 @@ export default class GlobEmbed {
// Save the elm
this.element = element;

// Get the gob string and remove from elm
// Get the glob string and check we have it
this.glob = element.getAttribute('data-glob-string');
if (!this.glob) throw new Error('Glob Embed missing required data-glob-string attribute');

// Clear out the attributes we don't need
element.removeAttribute('data-glob-tool-embed');
element.removeAttribute('data-glob-string');

Expand All @@ -42,6 +45,7 @@ export default class GlobEmbed {
element.removeAttribute(attr.name);
}
}
if (!this.tests.length) throw new Error('Glob Embed missing required data-glob-test-[0-9]+ attribute(s)');

// Prep results store
this.results = [];
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 DigitalOcean
Copyright 2024 DigitalOcean
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@ window.GlobToolEmbeds = scope => {
scope = scope || document;

// Detect all valid embeds to run
const embedsElms = Array.from(scope.querySelectorAll('[data-glob-tool-embed][data-glob-string][data-glob-test-1]'));
const embedsElms = Array.from(scope.querySelectorAll('[data-glob-tool-embed]'));

// Convert to GlobEmbed instances
const embeds = embedsElms.map(x => new GlobEmbed(x));
Expand Down

0 comments on commit 30815e7

Please # to comment.