Skip to content

Commit e12fbdc

Browse files
authored
Merge branch 'master' into tailwind-prefix
2 parents 2c9d8f1 + 2ee3daa commit e12fbdc

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

addon/components/docs-viewer/x-main/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default Component.extend({
8080
}
8181
} else {
8282
let file = appFiles
83-
.filter(file => file.match(/template.(hbs|md)/))
83+
.filter(file => file.match(/template.+(hbs|md)/))
8484
.find(file => file.match(path));
8585

8686
return `${projectHref}/edit/${primaryBranch}/tests/dummy/app/${file}`;

addon/components/docs-viewer/x-main/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{{/if}}
2727
</div>
2828

29-
<div class="ad-w-1/2 ad-text-right">
29+
<div class="ad-w-1/2 ad-text-right" data-test-next-link>
3030
{{#if docsRoutes.next}}
3131
<div class='ad-text-sm ad-text-grey-dark'>
3232
Next

addon/services/docs-routes.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ export default Service.extend({
3939
if (this.get('routeUrls.length')) {
4040
let router = this.get('router.router');
4141
let currentURL = router.get('rootURL') + router.get('url');
42-
currentURL = currentURL
43-
.replace('//', '/') // dedup slashes
44-
.replace(/\?.+$/, '') // remove query-params
45-
.replace(/\/$/, '') // remove trailing slash
46-
.replace(/#.+$/, ''); // remove # anchor links
47-
let index = this.get('routeUrls').indexOf(currentURL);
48-
assert(`DocsRoutes wasn't able to correctly detect the current route. The current url is ${currentURL}`, index > -1);
49-
return index;
42+
currentURL = currentURL.replace('//', '/') // dedup slashes
43+
let longestIndex, longestPrefix;
44+
this.get('routeUrls').forEach((url, index) => {
45+
if (currentURL.indexOf(url) === 0 && (!longestPrefix || url.length > longestPrefix.length)) {
46+
longestIndex = index;
47+
longestPrefix = url;
48+
}
49+
});
50+
assert(`DocsRoutes wasn't able to correctly detect the current route. The current url is ${currentURL}`, longestIndex != null);
51+
return longestIndex;
5052
}
5153
}),
5254

tests/acceptance/docs-route-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ module('Acceptance | Docs route test', function(hooks) {
1919

2020
assert.dom('h1').hasText('DocsHero');
2121
});
22+
23+
test('I can visit a nested child route within the docs pages and still have the correct links', async function(assert) {
24+
await visit('/sandbox/docs/one/child');
25+
assert.dom('[data-test-next-link] > a').hasText('Two');
26+
});
2227
});

tests/dummy/app/pods/sandbox/template.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{{#viewer.nav project=model root='sandbox' as |nav|}}
33
{{nav.section 'The Sandbox'}}
44
{{nav.item 'Welcome' 'sandbox.index'}}
5+
{{nav.item 'One' 'sandbox.docs.one'}}
6+
{{nav.item 'Two' 'sandbox.docs.two'}}
57
{{/viewer.nav}}
68

79
{{#viewer.main}}

tests/dummy/app/router.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ Router.map(function() {
2626

2727
this.route('sandbox', function() {
2828
apiRoute(this);
29+
docsRoute(this, function() {
30+
this.route('one', function() {
31+
this.route('child');
32+
});
33+
this.route('two');
34+
});
2935
});
3036

3137
this.route('not-found', { path: '/*path' });

0 commit comments

Comments
 (0)