Skip to content

Commit a62d09d

Browse files
alexlafrosciasamselikoff
authored andcommitted
Fix template edit link (#130)
* Fix template edit link * Fix edit link for generated API pages
1 parent e388469 commit a62d09d

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Component from '@ember/component';
33
import layout from './template';
44
import { computed } from '@ember/object';
55
import appFiles from 'ember-cli-addon-docs/app-files';
6-
import { dasherize } from '@ember/string';
6+
import addonFiles from 'ember-cli-addon-docs/addon-files';
77
import config from 'dummy/config/environment';
88
import { getOwner } from '@ember/application';
99

@@ -23,20 +23,23 @@ export default Component.extend({
2323
editCurrentPageUrl: computed('router.currentRouteName', function() {
2424
let path = this.get('router.currentRouteName');
2525
if (!path) {
26-
// `routing` doesn't exist for old ember versions via ember-try
26+
// `router` doesn't exist for old ember versions via ember-try
2727
return;
2828
}
29+
2930
path = path.replace(/\./g, '/');
3031

31-
if (path === 'docs/api/class') {
32-
let params = getOwner(this).lookup('route:application').paramsFor('docs.api.class');
33-
let klass = dasherize(params.class_id.replace(/-.+$/g, ''));
34-
let path = `pods/${path}`;
32+
if (path === 'docs/api/item') {
33+
let { path } = getOwner(this).lookup('route:application').paramsFor('docs.api.item');
34+
let file = addonFiles.find(f => f.match(path));
3535

36-
return `${packageJson.repository}/edit/master/addon/components/${klass}/component.js`;
36+
if (file) {
37+
return `${packageJson.repository}/edit/master/addon/${file}`;
38+
}
3739
} else {
38-
let templatePath = `pods/${path}`;
39-
let file = appFiles.find(file => file.match(`${templatePath}/template.(hbs|md)`));
40+
let file = appFiles
41+
.filter(file => file.match(/template.(hbs|md)/))
42+
.find(file => file.match(path));
4043

4144
return `${packageJson.repository}/edit/master/tests/dummy/app/${file}`;
4245
}

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ module.exports = {
147147

148148
treeForAddon(tree) {
149149
let dummyAppFiles = new FindDummyAppFiles([ 'tests/dummy/app' ]);
150+
let addonFiles = new FindAddonFiles([ 'addon' ]);
150151

151-
return this._super(new MergeTrees([ tree, dummyAppFiles ]));
152+
return this._super(new MergeTrees([ tree, dummyAppFiles, addonFiles ]));
152153
},
153154

154155
treeForVendor(vendor) {
@@ -280,6 +281,16 @@ class FindDummyAppFiles extends Plugin {
280281
}
281282
}
282283

284+
class FindAddonFiles extends Plugin {
285+
build() {
286+
let addonPath = this.inputPaths[0];
287+
let paths = walkSync(addonPath, { directories: false })
288+
let pathsString = JSON.stringify(paths);
289+
290+
fs.writeFileSync(path.join(this.outputPath, 'addon-files.js'), `export default ${pathsString};`);
291+
}
292+
}
293+
283294
class AutoExportAddonToApp extends Plugin {
284295
build() {
285296
let addonPath = this.inputPaths[0];

0 commit comments

Comments
 (0)