Skip to content

Commit

Permalink
Merge pull request #104 from josemarluedke/feat/deep-nested-scope
Browse files Browse the repository at this point in the history
[Ember] Allow deep nested scope for docfy output
  • Loading branch information
josemarluedke authored Jun 26, 2021
2 parents 7b68fb9 + fa910e7 commit ba9b60a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/ember/addon/services/docfy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,25 @@ export default class DocfyService extends Service {
return this.findByUrl(this.router.currentURL);
}

findNestedChildrenByName(name: string): NestedPageMetadata | undefined {
return this.nested.children.find((item) => {
findNestedChildrenByName(
scope: string,
previousNested: NestedPageMetadata | undefined | null = null
): NestedPageMetadata | undefined {
if (previousNested === null) {
previousNested = this.nested;
}
const parts = scope.split('/');
const name = parts.shift();

const foundScope = previousNested?.children.find((item) => {
return item.name === name;
});

if (parts.length > 0) {
return this.findNestedChildrenByName(parts.join('/'), foundScope);
}

return foundScope;
}

findByUrl(url: string, scopeByNestedName?: string): PageMetadata | undefined {
Expand Down
9 changes: 9 additions & 0 deletions packages/ember/tests/unit/services/docfy-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ module('Unit | Service | docfy', function (hooks) {
assert.equal(service.findNestedChildrenByName('docs')?.name, 'docs');
});

test('it returns the nested children by name when scope has slashes', function (assert) {
const service: DocfyService = this.owner.lookup('service:docfy');
assert.equal(service.findNestedChildrenByName('docs/core')?.name, 'core');
assert.equal(
service.findNestedChildrenByName('docs/ember/components')?.name,
'components'
);
});

test('it returns the page by current url', function (assert) {
const service: DocfyService = this.owner.lookup('service:docfy');
const routerService = this.owner.lookup('service:router');
Expand Down

0 comments on commit ba9b60a

Please sign in to comment.