Skip to content

Commit 82bbdc7

Browse files
dfreemanRobbieTheWagner
authored andcommitted
Support non-block <DocsSnippet> invocation (#441)
1 parent 73f9eb1 commit 82bbdc7

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

addon/components/docs-snippet/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
docs-relative docs-subpixel-antialiased
1515
{{if title "docs-rounded-b" "docs-rounded"}}
1616
"
17-
data-test-id={{name}}
17+
data-test-id={{or data-test-id name}}
1818
>
1919
{{#with (get-code-snippet name unindent=unindent) as |snippet|}}
2020
{{#if showCopy}}

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,19 @@ module.exports = {
128128
includer.options.snippetSearchPaths = ['tests/dummy/app'];
129129
}
130130
}
131-
includer.options.snippetRegexes = Object.assign({}, {
132-
begin: /(?:{{#|<)(?:DocsSnippet|docs-snippet|demo\.example)\s@?name=['"](\S*)['"]/,
133-
end: /(?:{{|<)\/(?:DocsSnippet|docs-snippet|demo\.example)(?:}}|>)/,
134-
}, includer.options.snippetRegexes);
131+
132+
if (!includer.options.snippetRegexes) {
133+
includer.options.snippetRegexes = [
134+
{
135+
begin: /{{#(?:docs-snippet|demo\.example)\sname=['"](\S*)['"]/,
136+
end: /{{\/(?:docs-snippet|demo\.example)}}/,
137+
},
138+
{
139+
begin: /<(?:DocsSnippet|demo\.example)\s@name=['"](\S*)['"][^/]*>/,
140+
end: /<\/(?:DocsSnippet|demo\.example)>/
141+
}
142+
];
143+
}
135144

136145
let snippetExtensions = includer.options.snippetExtensions;
137146

test-apps/new-addon/tests/acceptance/snippets-test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import { module, test } from 'qunit';
22
import { visit, fillIn } from '@ember/test-helpers';
33
import { setupApplicationTest } from 'ember-qunit';
44

5-
const snippetIds = ['your-snippet-name.hbs', 'your-angle-bracket-snippet-name.hbs'];
5+
const snippetIds = [
6+
'your-snippet-name.hbs',
7+
'your-angle-bracket-snippet-name.hbs',
8+
'standalone-curlies',
9+
'standalone-angle-brackets'
10+
];
611

712
module('Acceptance | snippets', function(hooks) {
813
setupApplicationTest(hooks);
914

1015
test('snippets support both classic & angle bracket invocation', async function(assert) {
11-
assert.expect(13);
16+
assert.expect(17);
1217

1318
await visit('/snippets');
1419

test-apps/new-addon/tests/dummy/app/templates/snippets.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
</div>
2121
</DocsSnippet>
2222

23+
{{docs-snippet name="your-snippet-name.hbs" data-test-id="standalone-curlies"}}
24+
25+
<DocsSnippet @name="your-angle-bracket-snippet-name.hbs" @data-test-id="standalone-angle-brackets" />
26+
2327
{{#docs-demo data-test-id="docs-demo-basic.hbs" as |demo|}}
2428
{{#demo.example name="docs-demo-basic.hbs"}}
2529
<p>I am a <strong>handlebars</strong> template!</p>

0 commit comments

Comments
 (0)