Skip to content

Commit e1a29b1

Browse files
abel-nRobbieTheWagner
authored andcommitted
snippets support both classic & angle bracket invocation (ember-learn#421)
1 parent 5fb1cc8 commit e1a29b1

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ module.exports = {
129129
}
130130
}
131131
includer.options.snippetRegexes = Object.assign({}, {
132-
begin: /{{#(?:docs-snippet|demo.example)\sname=(?:"|')(\S+)(?:"|')/,
133-
end: /{{\/(?:docs-snippet|demo.example)}}/,
132+
begin: /(?:{{#|<)(?:DocsSnippet|docs-snippet|demo\.example)\s@?name=['"](\S*)['"]/,
133+
end: /(?:{{|<)\/(?:DocsSnippet|docs-snippet|demo\.example)(?:}}|>)/,
134134
}, includer.options.snippetRegexes);
135135
includer.options.includehighlightJS = false;
136136
includer.options.includeHighlightStyle = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { module, test } from 'qunit';
2+
import { visit, fillIn } from '@ember/test-helpers';
3+
import { setupApplicationTest } from 'ember-qunit';
4+
5+
const snippetIds = ['your-snippet-name.hbs', 'your-angle-bracket-snippet-name.hbs'];
6+
7+
module('Acceptance | snippets', function(hooks) {
8+
setupApplicationTest(hooks);
9+
10+
test('snippets support both classic & angle bracket invocation', async function(assert) {
11+
assert.expect(13);
12+
13+
await visit('/snippets');
14+
15+
snippetIds.forEach(id => {
16+
let snippet = `[data-test-id="${id}"]`;
17+
18+
assert.dom(`${snippet} pre`).includesText('<div id=\'foo\'>');
19+
assert.dom(`${snippet} button`).hasAttribute('data-clipboard-text', /.*<div id='foo'>.*/);
20+
});
21+
22+
let demo = '[data-test-id="your-angle-bracket-snippet-name.hbs"] ~ *:not([data-test-id])';
23+
let secondDemo = `${demo}:last-child`;
24+
25+
assert.dom(`${demo} input`).exists({ count: 2 });
26+
27+
await fillIn(`${demo} input`, '2');
28+
await fillIn(`${secondDemo} input`, '2');
29+
30+
assert.dom(demo).includesText('The value is: 2');
31+
assert.dom(`${demo} input`).hasClass('docs-border');
32+
assert.dom(`${demo} pre`).includesText('{{input value=this.val class=\'docs-border\'}}');
33+
assert.dom(`${demo} button`).hasAttribute('data-clipboard-text', /{{input value=this\.val class='docs-border'}}/);
34+
35+
assert.dom(`${secondDemo}`).includesText('The value is: 2');
36+
assert.dom(`${secondDemo} input`).hasClass('docs-border');
37+
assert.dom(`${secondDemo} pre`).includesText('<Input @value={{this.otherVal}} class=\'docs-border\' />');
38+
assert.dom(`${secondDemo} button`).hasAttribute('data-clipboard-text', /<Input @value={{this\.otherVal}} class='docs-border' \/>/);
39+
});
40+
});

test-apps/new-addon/tests/dummy/app/router.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const Router = AddonDocsRouter.extend({
88

99
Router.map(function() {
1010
this.route('route-using-compile-markdown');
11+
this.route('snippets');
1112

1213
docsRoute(this, function() {
1314

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{#docs-snippet name='your-snippet-name.hbs'}}
2+
<div id='foo'>
3+
{{#my-awesome-thing
4+
some=true
5+
options=false
6+
}}
7+
<p>Something old, something new</p>
8+
{{/my-awesome-thing}}
9+
</div>
10+
{{/docs-snippet}}
11+
12+
<DocsSnippet @name='your-angle-bracket-snippet-name.hbs'>
13+
<div id='foo'>
14+
{{#my-awesome-thing
15+
some=true
16+
options=false
17+
}}
18+
<p>Something old, something new</p>
19+
{{/my-awesome-thing}}
20+
</div>
21+
</DocsSnippet>
22+
23+
{{#docs-demo data-test-id='docs-demo-basic.hbs' as |demo|}}
24+
{{#demo.example name='docs-demo-basic.hbs'}}
25+
<p>I am a <strong>handlebars</strong> template!</p>
26+
<p>The value is: {{this.val}}</p>
27+
<div>
28+
{{input value=this.val class='docs-border'}}
29+
</div>
30+
{{/demo.example}}
31+
32+
{{demo.snippet 'docs-demo-basic.hbs'}}
33+
{{/docs-demo}}
34+
35+
<DocsDemo as |demo|>
36+
<demo.example @name='docs-demo-angle-brackets-basic.hbs'>
37+
<p>I am a <strong>handlebars</strong> template!</p>
38+
<p>The value is: {{this.otherVal}}</p>
39+
<div>
40+
<Input @value={{this.otherVal}} class='docs-border' />
41+
</div>
42+
</demo.example>
43+
44+
<demo.snippet @name='docs-demo-angle-brackets-basic.hbs' />
45+
</DocsDemo>

0 commit comments

Comments
 (0)