Skip to content

Commit 2804cb4

Browse files
authored
Fix embed matching for single 0-indexed test attribute (#26)
1 parent 2428888 commit 2804cb4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/embed.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 DigitalOcean
2+
Copyright 2024 DigitalOcean
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -29,8 +29,11 @@ export default class GlobEmbed {
2929
// Save the elm
3030
this.element = element;
3131

32-
// Get the gob string and remove from elm
32+
// Get the glob string and check we have it
3333
this.glob = element.getAttribute('data-glob-string');
34+
if (!this.glob) throw new Error('Glob Embed missing required data-glob-string attribute');
35+
36+
// Clear out the attributes we don't need
3437
element.removeAttribute('data-glob-tool-embed');
3538
element.removeAttribute('data-glob-string');
3639

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

4650
// Prep results store
4751
this.results = [];

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 DigitalOcean
2+
Copyright 2024 DigitalOcean
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ window.GlobToolEmbeds = scope => {
2020
scope = scope || document;
2121

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

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

0 commit comments

Comments
 (0)