Skip to content
Merged
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
21 changes: 12 additions & 9 deletions addon/components/docs-viewer/x-main/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Component from '@ember/component';
import layout from './template';
import { computed } from '@ember/object';
import appFiles from 'ember-cli-addon-docs/app-files';
import { dasherize } from '@ember/string';
import addonFiles from 'ember-cli-addon-docs/addon-files';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to add the logic to also expose the addon tree contents, otherwise you had to really guess a lot about what the current URL on Github would be. At least now we have a reference of the actual files to try and match against.

import config from 'dummy/config/environment';
import { getOwner } from '@ember/application';

Expand All @@ -23,20 +23,23 @@ export default Component.extend({
editCurrentPageUrl: computed('router.currentRouteName', function() {
let path = this.get('router.currentRouteName');
if (!path) {
// `routing` doesn't exist for old ember versions via ember-try
// `router` doesn't exist for old ember versions via ember-try
return;
}

path = path.replace(/\./g, '/');

if (path === 'docs/api/class') {
let params = getOwner(this).lookup('route:application').paramsFor('docs.api.class');
let klass = dasherize(params.class_id.replace(/-.+$/g, ''));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class_id is no longer what the catch-all param for the route is called.

let path = `pods/${path}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, remove the assumption that the files are within pods

if (path === 'docs/api/item') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/api/class was what the original documentation had, but no longer matches what the guide suggests.

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

return `${packageJson.repository}/edit/master/addon/components/${klass}/component.js`;
if (file) {
return `${packageJson.repository}/edit/master/addon/${file}`;
}
} else {
let templatePath = `pods/${path}`;
let file = appFiles.find(file => file.match(`${templatePath}/template.(hbs|md)`));
let file = appFiles
.filter(file => file.match(/template.(hbs|md)/))
.find(file => file.match(path));

return `${packageJson.repository}/edit/master/tests/dummy/app/${file}`;
}
Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ module.exports = {

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

return this._super(new MergeTrees([ tree, dummyAppFiles ]));
return this._super(new MergeTrees([ tree, dummyAppFiles, addonFiles ]));
},

treeForVendor(vendor) {
Expand Down Expand Up @@ -280,6 +281,16 @@ class FindDummyAppFiles extends Plugin {
}
}

class FindAddonFiles extends Plugin {
build() {
let addonPath = this.inputPaths[0];
let paths = walkSync(addonPath, { directories: false })
let pathsString = JSON.stringify(paths);

fs.writeFileSync(path.join(this.outputPath, 'addon-files.js'), `export default ${pathsString};`);
}
}

class AutoExportAddonToApp extends Plugin {
build() {
let addonPath = this.inputPaths[0];
Expand Down