Skip to content

Commit d2e3082

Browse files
committed
Make doc pages MD
1 parent 7a8817d commit d2e3082

File tree

22 files changed

+283
-290
lines changed

22 files changed

+283
-290
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{! BEGIN-SNIPPET docs-demo-basic-src }}
2+
{{#docs-demo as |demo|}}
3+
{{#demo.example name='docs-demo-basic'}}
4+
<p>I am a <strong>handlebars</strong> template!</p>
5+
<p>The value is: {{val}}</p>
6+
<div>
7+
{{input value=val}}
8+
</div>
9+
{{/demo.example}}
10+
11+
{{demo.snippet 'docs-demo-basic.hbs'}}
12+
{{/docs-demo}}
13+
{{! END-SNIPPET }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Component from '@ember/component';
2+
3+
export default Component.extend({
4+
5+
actions: {
6+
// BEGIN-SNIPPET docs-demo-multiple
7+
toggleIsShowing() {
8+
this.toggleProperty('isShowing');
9+
}
10+
// END-SNIPPET
11+
}
12+
13+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{#docs-demo as |demo|}}
2+
{{#demo.example data-test-id='docs-demo-multiple'}}
3+
{{!-- BEGIN-SNIPPET docs-demo-multiple --}}
4+
<button onclick={{action 'toggleIsShowing'}}>
5+
Press me!
6+
</button>
7+
8+
{{#if isShowing}}
9+
<p>Yep</p>
10+
{{else}}
11+
<p>Nope</p>
12+
{{/if}}
13+
{{!-- END-SNIPPET --}}
14+
{{/demo.example}}
15+
16+
{{demo.snippet 'docs-demo-multiple.hbs'}}
17+
{{demo.snippet 'docs-demo-multiple.js' label='component.js'}}
18+
{{/docs-demo}}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{!-- BEGIN-SNIPPET docs-demo-custom-src --}}
2+
{{#docs-demo as |demo|}}
3+
{{#demo.example name='docs-demo-custom'}}
4+
<pre>
5+
# Markdown
6+
- Has syntax highlighting, too
7+
</pre>
8+
{{/demo.example}}
9+
10+
{{demo.snippet 'docs-demo-custom-src.hbs' label='Source'}}
11+
{{demo.snippet 'docs-demo-custom.hbs' label='My Custom Label' language='markdown'}}
12+
{{/docs-demo}}
13+
{{!-- END-SNIPPET --}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{! BEGIN-SNIPPET live-example-src }}
2+
{{#docs-demo as |demo|}}
3+
{{#demo.live-example name='live-example'}}
4+
<p>The air up here is {{foo}}</p>
5+
6+
{{input value=foo}}
7+
{{/demo.live-example}}
8+
{{/docs-demo}}
9+
{{! END-SNIPPET }}

tests/dummy/app/pods/docs/components/docs-demo/template.hbs

Lines changed: 0 additions & 120 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Docs Demo
2+
3+
This component provides you with a way to show example code. It also renders the actual template used to generate the example, so you don't have to worry about keeping the code snippet and the live example in sync.
4+
5+
It's also an important part of your addon's testing story. If you write demos for most of your addon's functionality in your documentation app using this helper component, and then write acceptance tests against those demos, your acceptance tests will accomplish two things:
6+
7+
- They verify your addon's behavior
8+
- They ensure all of that behavior is working in your docs site, and up-to-date with your addon's actual APIs
9+
10+
This saves you from ever having to remember that second step of "updating the docs" every time you change your libary.
11+
12+
Of course, if your addon's components have some edge cases that would muddle up your documentation site too much, you can fall back to using integration tests. But try to keep most of the behavior in the docs pages — that way your users will know about it.
13+
14+
## Basic usage
15+
16+
Let's look at a basic example:
17+
18+
{{docs/components/docs-demo/demo1}}
19+
20+
Here's the code that rendered the above demo (you can copy-paste this block to get going in your own app):
21+
22+
{{docs-snippet name='docs-demo-basic-src.hbs'}}
23+
24+
To explain,
25+
26+
- `{{docs-demo}}` is the wrapping component
27+
- The contextual component `{{#demo.example}}{{/demo.example}}` provides a wrapper to display your example. You'll pass a block to this component with the actual code you're demoing - for example, showing off how to use your button.
28+
- You also need to pass a `name=` to demo.example in order to identify your snippet.
29+
- Finally, the `{{demo.snippet}}` component lets you render different named snippets that you've identified via demo.example wrappers or other code comment blocks in your source.
30+
31+
## Multiple snippets
32+
33+
You can render multiple snippets to support your example. This can be useful when part of your example relies on code defined elsewhere, for example in a controller or stylesheet.
34+
35+
Use a file extension to help docs-snippet identify and properly syntax highlight your snippet. Templates end in `.hbs`, JavaScript snippets end in `.js`, stylesheets in `.css` or `.scss`.
36+
37+
{{docs/components/docs-demo/demo2}}
38+
39+
## Custom Snippet Handling
40+
41+
If you wish to override the inferred label or syntax highlighting for a snippet, you can specify `label` and `language` properties.
42+
43+
{{docs/components/docs-demo/demo3}}
44+
45+
## Live examples
46+
47+
You can also make a live example, so your users can edit your demos and try out your components for themselves.
48+
49+
{{docs/components/docs-demo/demo4}}
50+
51+
Here's the code for this:
52+
53+
{{docs-snippet name='live-example-src.hbs'}}
54+
55+
Note that we're using the `demo.live-example` contextual component now. This component takes a block as a starting template for the user to see. It then puts that template into the `textarea`, and every time its value changes the template is recompiled and rerendered.
56+
57+
If there is a template compilation error it should show instead of the rendered output.

tests/dummy/app/pods/docs/components/docs-hero/template.hbs renamed to tests/dummy/app/pods/docs/components/docs-hero/demo/template.hbs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
<h1>Docs Hero</h1>
2-
3-
<p>This component helps you quickly get a hero section on your addon's homepage. The hero on the homepage of this site is an example.</p>
4-
51
{{#docs-demo as |demo|}}
62
{{#demo.example name='docs-hero'}}
73
{{docs-hero
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Docs Hero
2+
3+
This component helps you quickly get a hero section on your addon's homepage. The hero on the homepage of this site is an example.
4+
5+
{{docs/components/docs-hero/demo}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// BEGIN-SNIPPET docs-logo-ember-styles
2+
.my-ember-addon-logo {
3+
background: #333;
4+
color: white;
5+
width: 50%;
6+
height: 50%;
7+
margin: 0 auto;
8+
padding: 20px;
9+
}
10+
// END-SNIPPET

0 commit comments

Comments
 (0)