Skip to content

Commit 0ef8f62

Browse files
authored
Merge pull request #175 from ember-learn/document-router-hooks
[feat] Document AddonDocsRouter and hooks
2 parents 2651062 + c713bcd commit 0ef8f62

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

addon/components/api/x-sections/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div data-test-item>
1010
{{#if (or item.isClass item.isComponent)}}
1111
<h3 id={{item.name}} data-test-item-header class="item-section__class-header mb-1">
12-
{{#link-to 'docs.api.item' (concat 'root/' item.id)}}
12+
{{#link-to 'docs.api.item' (concat 'modules/' item.id)}}
1313
{{#if (eq item.exportType 'default')}}
1414
<span class="item-section__default-label">Default</span>
1515
{{/if}}

addon/router.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
1+
/** @documenter yuidoc */
2+
13
import EmberRouter from '@ember/routing/router';
24
import RouterScroll from 'ember-router-scroll';
35

6+
/**
7+
The AddonDocsRouter, which adds some extra functionality. This should be used
8+
instead of the standard EmberRouter class in your docs app.
9+
10+
```js
11+
import AddonDocsRouter, { docsRoute } from 'ember-cli-addon-docs/router';
12+
import config from './config/environment';
13+
14+
const Router = AddonDocsRouter.extend({
15+
location: config.locationType,
16+
rootURL: config.rootURL,
17+
});
18+
```
19+
20+
@class AddonDocsRouter
21+
@extends EmberRouter
22+
*/
423
export default EmberRouter.extend(RouterScroll);
524

25+
/**
26+
Creates the docs route and api docs routes. Can receive a callback with the
27+
routes you want to add to your docs.
28+
29+
```js
30+
import AddonDocsRouter, { docsRoute } from 'ember-cli-addon-docs/router';
31+
32+
Router.map(function() {
33+
docsRoute(this, function() {
34+
this.route('usage');
35+
});
36+
});
37+
```
38+
39+
@function docsRoute
40+
*/
641
export function docsRoute(router, callback) {
742
router.route('docs', function() {
843
callback.apply(this);

tests/dummy/app/pods/docs/quickstart/template.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ marketing/demo page you can use to promote your addon.
1111
ember install ember-cli-addon-docs
1212
```
1313

14-
2. **Add the docs routes.** Open `tests/dummy/app/router.js` and add the
15-
following route definitions to your main route.
14+
2. **Add the docs routes.** Open `tests/dummy/app/router.js` and replace the
15+
standard EmberRouter with the AddonDocsRouter:
1616

1717
{{#docs-snippet name='quickstart-router.js' title='tests/dummy/app/router.js'}}
18-
this.route('docs', function() { // docs homepage (required)
19-
this.route('usage'); // docs subpage
20-
this.route('api', function() { // autogenerated API homepage (required)
21-
this.route('item', { path: '/*path' }); // autogenerated API subpages (required)
22-
});
18+
import AddonDocsRouter, { docsRoute } from 'ember-cli-addon-docs/router';
19+
import config from './config/environment';
20+
21+
const Router = AddonDocsRouter.extend({
22+
location: config.locationType,
23+
rootURL: config.rootURL,
24+
});
25+
26+
Router.map(function() {
27+
docsRoute(this, function() { /* Your docs routes go here */ });
2328
});
29+
30+
export default Router;
2431
{{/docs-snippet}}
2532

2633
3. **Create your docs skeleton.** Create a new template for the `docs` route

0 commit comments

Comments
 (0)