Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make generated API reference its own top-level section #231

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/components/api/x-section/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{/if}}

{{#if (or item.isClass item.isComponent)}}
{{#link-to 'docs.api.item' (concat 'modules/' item.id) class='hover:underline'}}
{{#link-to 'api.item' (concat 'modules/' item.id) class='hover:underline'}}
<strong>{{item.name}}</strong>
{{/link-to}}
{{else}}
Expand Down
6 changes: 6 additions & 0 deletions addon/components/docs-header/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export default Component.extend({

projectVersion: service(),

store: service(),

projectHref,
latestVersionName,

Expand All @@ -56,6 +58,10 @@ export default Component.extend({

currentVersion: reads('projectVersion.currentVersion'),

project: computed('store', function() {
return this.get('store').peekRecord('project', projectName);
}),

actions: {
didVisitPage() {
this.set('query', null);
Expand Down
2 changes: 1 addition & 1 deletion addon/components/docs-header/search-result/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default Component.extend({
args = [ this.get('result.document.route') ];

} else {
args = [ 'docs.api.item', this.get('result.model.routingId') ];
args = [ 'api.item', this.get('result.model.routingId') ];
}

return args;
Expand Down
4 changes: 2 additions & 2 deletions addon/components/docs-header/search-results/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default Component.extend(EKMixin, {

// Filter out the templates of the API items' pages, since we handle them separately
.filter(({ document }) => {
let isApiItemTemplate = (document.route === 'docs.api.item' && document.type === 'template');
let isApiItemTemplate = (document.route === 'api.item' && document.type === 'template');
return !isApiItemTemplate;
})

Expand Down Expand Up @@ -106,7 +106,7 @@ export default Component.extend(EKMixin, {
if (selectedResult.document.type === 'template') {
this.get('router').transitionTo(selectedResult.document.route);
} else {
this.get('router').transitionTo('docs.api.item', selectedResult.model.get('routingId'));
this.get('router').transitionTo('api.item', selectedResult.model.get('routingId'));
}
}

Expand Down
6 changes: 6 additions & 0 deletions addon/components/docs-header/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
Documentation
{{/docs-header/link}}

{{#if (gt project.modules.length 0)}}
{{#docs-header/link 'api'}}
API Reference
{{/docs-header/link}}
{{/if}}

{{yield (hash
link=(component 'docs-header/link')
)}}
Expand Down
2 changes: 1 addition & 1 deletion addon/components/docs-viewer/x-main/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default Component.extend({
path = path.replace(/\./g, '/');

if (path === 'docs/api/item') {
let { path } = getOwner(this).lookup('route:application').paramsFor('docs.api.item');
let { path } = getOwner(this).lookup('route:application').paramsFor('api.item');
let file = addonFiles.find(f => f.match(path));

if (file) {
Expand Down
2 changes: 1 addition & 1 deletion addon/components/docs-viewer/x-nav/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default Component.extend({
layout,
tagName: '',

root: 'docs',
root: 'api',

store: service(),

Expand Down
12 changes: 0 additions & 12 deletions addon/components/docs-viewer/x-nav/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@
subnav=(component 'docs-viewer/x-nav-list' class='ml-4')
)}}

{{!-- Autogenerated API docs --}}
{{#if (gt project.modules.length 0)}}
{{docs-viewer/x-section 'API Reference' style='large'}}

{{#each-in project.navigationIndex as |type items|}}
{{docs-viewer/x-section type}}

{{#each items as |item|}}
{{docs-viewer/x-nav-item (break-on item.name '/') (concat root '.api.item') item.path}}
{{/each}}
{{/each-in}}
{{/if}}
{{/docs-viewer/x-nav-list}}

<div class="docs-mt-16 lg:docs-mb-16 docs-mr-2 docs-text-xs docs-rounded">
Expand Down
3 changes: 1 addition & 2 deletions addon/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ export default EmberRouter.extend(RouterScroll);
export function docsRoute(router, callback) {
router.route('docs', function() {
callback.apply(this);

apiRoute(this);
});
apiRoute(router);
}

export function apiRoute(router) {
Expand Down
12 changes: 12 additions & 0 deletions addon/routes/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Route from '@ember/routing/route';
import config from 'dummy/config/environment';

const projectName = config['ember-cli-addon-docs'].projectName;

export default Route.extend({

model() {
return this.store.findRecord('project', projectName);
}

});
13 changes: 13 additions & 0 deletions addon/routes/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Route from '@ember/routing/route';

export default Route.extend({

beforeModel() {
let parentModel = this.modelFor('api');
let modules = parentModel.getWithDefault('navigationIndex.modules', []);
if (modules.length) {
return this.transitionTo('api.item', modules[0].path);
}
return this.transitionTo('docs');
}
});
File renamed without changes.
25 changes: 25 additions & 0 deletions app/templates/api.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{#docs-viewer as |viewer|}}

{{#viewer.nav as |nav|}}
{{!-- Autogenerated API docs --}}
{{#if (gt model.modules.length 0)}}
{{docs-viewer/x-section 'API Reference' style='large'}}

{{#each-in model.navigationIndex as |type items|}}
{{docs-viewer/x-section type}}

{{#each items as |item|}}
{{docs-viewer/x-nav-item (break-on item.name '/') 'api.item' item.path}}
{{/each}}
{{/each-in}}
{{/if}}
{{/viewer.nav}}

{{#viewer.main}}
<div class="docs-container">
{{outlet}}
</div>
{{/viewer.main}}

{{/docs-viewer}}

File renamed without changes.