Skip to content

Commit 5fb1cc8

Browse files
ef4samselikoff
authored andcommitted
Support standalone docs apps (#409)
This makes it possible to separate your docs application from your addon's dummy app. Fixes #383. The way it works is: - you're still required to keep both the addon and the docs app in the same repo (so we don't need to worry about separately versioning each) - but they can be peers or subdirectories of each other - in your docs application you add ember-cli-addon-docs - in your docs application you must set the `documentingAddonAt` option to point at the path of the actual addon. As a side-effect of refactoring the way "Edit this page" links work, I think I also fixed them for API-docs pages in all addon docs sites (not just ones using this new architecture).
1 parent 7574272 commit 5fb1cc8

File tree

20 files changed

+123
-50
lines changed

20 files changed

+123
-50
lines changed

addon/adapters/-addon-docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import DS from 'ember-data';
2-
import config from 'dummy/config/environment';
2+
import config from 'ember-get-config';
33
import { inject as service } from '@ember/service';
44

55
export default DS.Adapter.extend({

addon/components/api/x-class/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed } from '@ember/object';
33
import { or } from '@ember/object/computed';
44
import { capitalize } from '@ember/string';
55
import { memberFilter } from '../../../utils/computed';
6-
import config from 'dummy/config/environment';
6+
import config from 'ember-get-config';
77

88
const { showImportPaths } = config['ember-cli-addon-docs'];
99

addon/components/api/x-section/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Component from '@ember/component';
22
import { computed } from '@ember/object';
33
import layout from './template';
4-
import config from 'dummy/config/environment';
4+
import config from 'ember-get-config';
55

66
const { showImportPaths } = config['ember-cli-addon-docs'];
77

addon/components/docs-header/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component from '@ember/component';
22
import layout from './template';
3-
import config from 'dummy/config/environment';
3+
import config from 'ember-get-config';
44
import { computed } from '@ember/object';
55
import { classify } from '@ember/string';
66
import { addonLogo, addonPrefix } from 'ember-cli-addon-docs/utils/computed';

addon/components/docs-header/search-box/component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import layout from './template';
33
import { EKMixin, keyUp } from 'ember-keyboard';
44
import { on } from '@ember/object/evented';
55
import { task } from 'ember-concurrency';
6-
import config from 'dummy/config/environment';
6+
import config from 'ember-get-config';
77
import { inject as service } from '@ember/service';
88
import { formElementHasFocus } from 'ember-cli-addon-docs/keyboard-config';
99

@@ -18,7 +18,7 @@ export default Component.extend(EKMixin, {
1818
query: null,
1919

2020
keyboardActivated: true,
21-
21+
2222
didInsertElement() {
2323
this._super();
2424

addon/components/docs-header/search-results/component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { EKMixin, keyUp, keyDown } from 'ember-keyboard';
55
import { on } from '@ember/object/evented';
66
import { computed } from '@ember/object';
77
import { task } from 'ember-concurrency';
8-
import config from 'dummy/config/environment';
8+
import config from 'ember-get-config';
99

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

@@ -20,7 +20,7 @@ export default Component.extend(EKMixin, {
2020
selectedIndex: null,
2121

2222
keyboardActivated: true,
23-
23+
2424
didInsertElement() {
2525
this._super();
2626

addon/components/docs-header/version-selector/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Component from '@ember/component';
22
import { inject as service } from '@ember/service';
33
import layout from './template';
44
import { reads } from '@ember/object/computed';
5-
// import config from 'dummy/config/environment';
5+
// import config from 'ember-get-config';
66
import { computed } from '@ember/object';
77
import { A } from '@ember/array';
88
import { getOwner } from '@ember/application';

addon/components/docs-hero/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Component from '@ember/component';
22
import layout from './template';
33
import { addonPrefix, unprefixedAddonName } from 'ember-cli-addon-docs/utils/computed';
4-
import config from 'dummy/config/environment';
4+
import config from 'ember-get-config';
55
import { classify } from '@ember/string';
66
const { projectName, projectDescription } = config['ember-cli-addon-docs'];
77

addon/components/docs-snippet/component.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { computed } from '@ember/object';
22
import Component from '@ember/component';
33
import layout from './template';
4-
import Snippets from "dummy/snippets";
4+
import config from 'ember-get-config';
5+
import require from 'require';
56

67
/**
78
A snippet component for demonstrating some code
@@ -80,8 +81,10 @@ export default Component.extend({
8081
name += '.hbs';
8182
}
8283

84+
let snippet = require(config.modulePrefix + "/snippets")[name] || "";
85+
8386
return this._unindent(
84-
(Snippets[name] || "")
87+
snippet
8588
.replace(/^(\s*\n)*/, '')
8689
.replace(/\s*$/, '')
8790
);

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { bind } from '@ember/runloop';
44
import { computed } from '@ember/object';
55
import appFiles from 'ember-cli-addon-docs/app-files';
66
import addonFiles from 'ember-cli-addon-docs/addon-files';
7-
import config from 'dummy/config/environment';
7+
import config from 'ember-get-config';
88
import { getOwner } from '@ember/application';
99

1010
import layout from './template';
@@ -70,26 +70,38 @@ export default Component.extend({
7070
return;
7171
}
7272

73-
path = path.replace(/\./g, '/');
74-
75-
let { projectHref, projectPathInRepo, primaryBranch } = config['ember-cli-addon-docs'];
76-
let projectPath = projectPathInRepo ? `/${projectPathInRepo}/` : '/';
77-
let rootEditUrl = `${projectHref}/edit/${primaryBranch}${projectPath}`;
73+
let match = this._locateFile(path);
74+
if (match) {
75+
let { projectHref, addonPathInRepo, docsAppPathInRepo, primaryBranch } = config['ember-cli-addon-docs'];
76+
let parts = [projectHref, 'edit', primaryBranch];
77+
if (match.inTree === 'addon') {
78+
parts.push(addonPathInRepo);
79+
} else {
80+
parts.push(docsAppPathInRepo);
81+
}
82+
parts.push(match.file);
83+
return parts.filter(Boolean).join('/');
84+
}
85+
}),
7886

87+
_locateFile(path) {
88+
path = path.replace(/\./g, '/');
7989
if (path === 'docs/api/item') {
80-
let { path } = getOwner(this).lookup('route:application').paramsFor('docs.api.item');
81-
let file = addonFiles.find(f => f.match(path));
82-
90+
let { projectName } = config['ember-cli-addon-docs'];
91+
let model = getOwner(this).lookup('route:application').modelFor('docs.api.item');
92+
let filename = model.get('file').replace(new RegExp(`^${projectName}/`), '');
93+
let file = addonFiles.find(f => f.match(filename));
8394
if (file) {
84-
return `${rootEditUrl}addon/${file}`;
95+
return { file, inTree: 'addon' };
8596
}
8697
} else {
8798
let file = appFiles
8899
.filter(file => file.match(/\.(hbs|md)$/))
89100
.find(file => file.match(path));
90-
91-
return `${rootEditUrl}tests/dummy/app/${file}`;
101+
if (file) {
102+
return { file, inTree: 'app' };
103+
}
92104
}
93-
})
105+
}
94106

95107
});

0 commit comments

Comments
 (0)