Skip to content

Commit

Permalink
Merge pull request #347 from ember-learn/better-monorepo-support
Browse files Browse the repository at this point in the history
Fix icons and edit links for monorepo addons
  • Loading branch information
dfreeman authored Apr 4, 2019
2 parents a5889c4 + d0a33e1 commit ccfc0d5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 33 deletions.
4 changes: 0 additions & 4 deletions addon/components/api/x-section/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
<strong>{{item.name}}</strong>
{{/link-to}}
{{else}}
{{#if (eq item.exportType 'default')}}
<span class="item-section__default-label">Default</span>
{{/if}}

<a href="#{{item.name}}" class="heading-anchor">
{{type-signature item}}
</a>
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 @@ -86,7 +86,7 @@ export default Component.extend({
}),

highlightedTitle: computed('result.document.title', 'query', function() {
let title = this.result.document.title;
let title = this.result.document.title || '';
let match = title.match(new RegExp(this.query, 'i'));

if (match) {
Expand Down
10 changes: 6 additions & 4 deletions addon/components/docs-viewer/x-main/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { getOwner } from '@ember/application';

import layout from './template';

const { projectHref, primaryBranch } = config['ember-cli-addon-docs'];

const tagToSize = { H2: 'xxs', H3: 'xxs' };
const tagToIndent = { H2: '0', H3: '4' };
const tagToMarginTop = { H2: '2', H3: '2' };
Expand Down Expand Up @@ -74,19 +72,23 @@ export default Component.extend({

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

let { projectHref, projectPathInRepo, primaryBranch } = config['ember-cli-addon-docs'];
let projectPath = projectPathInRepo ? `/${projectPathInRepo}/` : '/';
let rootEditUrl = `${projectHref}/edit/${primaryBranch}${projectPath}`;

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

if (file) {
return `${projectHref}/edit/${primaryBranch}/addon/${file}`;
return `${rootEditUrl}addon/${file}`;
}
} else {
let file = appFiles
.filter(file => file.match(/\.(hbs|md)$/))
.find(file => file.match(path));

return `${projectHref}/edit/${primaryBranch}/tests/dummy/app/${file}`;
return `${rootEditUrl}tests/dummy/app/${file}`;
}
})

Expand Down
16 changes: 9 additions & 7 deletions addon/components/docs-viewer/x-main/template.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<div data-current-page-index-target>
{{yield}}

<div class="docs-mt-16 docs-mb-8" data-test-edit-page-link>
<a href={{editCurrentPageUrl}}
class='docs-transition docs-text-grey-darkest docs-opacity-50 docs-text-xs
hover:docs-opacity-75 docs-no-underline docs-border-b docs-border-grey hover:docs-border-grey-darkest'>
Edit this page
</a>
</div>
{{#if editCurrentPageUrl}}
<div class="docs-mt-16 docs-mb-8" data-test-edit-page-link>
<a href={{editCurrentPageUrl}}
class='docs-transition docs-text-grey-darkest docs-opacity-50 docs-text-xs
hover:docs-opacity-75 docs-no-underline docs-border-b docs-border-grey hover:docs-border-grey-darkest'>
Edit this page
</a>
</div>
{{/if}}
</div>

<div class="docs-mt-16 docs-pb-16 docs-border-t docs-border-grey-lighter docs-pt-4 docs-flex">
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
svgJar: {
sourceDirs: [
'public',
'node_modules/ember-cli-addon-docs/public',
`${__dirname}/public`,
'tests/dummy/public'
],
optimizer : {
Expand All @@ -47,6 +47,7 @@ module.exports = {
projectDescription: this.parent.pkg.description,
projectTag: this.parent.pkg.version,
projectHref: info && info.browse(),
projectPathInRepo: path.relative(this._getRepoRoot(), this.project.root),
primaryBranch: userConfig.getPrimaryBranch(),
latestVersionName: LATEST_VERSION_NAME,
deployVersion: 'ADDON_DOCS_DEPLOY_VERSION',
Expand Down Expand Up @@ -155,7 +156,7 @@ module.exports = {
},

treeForAddon(tree) {
let dummyAppFiles = new FindDummyAppFiles([ 'tests/dummy/app' ]);
let dummyAppFiles = new FindDummyAppFiles([ this.app.trees.app ]);
let addonFiles = new FindAddonFiles([ 'addon' ].filter(dir => fs.existsSync(dir)));

return this._super(new MergeTrees([ tree, dummyAppFiles, addonFiles ]));
Expand Down Expand Up @@ -246,6 +247,13 @@ module.exports = {
}

return this._userConfig;
},

_getRepoRoot() {
if (!this._repoRoot) {
this._repoRoot = require('git-repo-info')().root;
}
return this._repoRoot;
}
};

Expand Down
19 changes: 19 additions & 0 deletions tests/acceptance/sandbox/api/components-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { currentURL, visit, waitUntil } from '@ember/test-helpers';
import config from 'dummy/config/environment';

import modulePage from '../../../pages/api/module';

Expand Down Expand Up @@ -54,4 +55,22 @@ module('Acceptance | Sandbox | API | components', function(hooks) {

assert.equal(editThisPageLinkHref, 'https://github.com/ember-learn/ember-cli-addon-docs/edit/master/tests/dummy/app/pods/sandbox/index/template.md');
});

module('in a nested directory within a repo', function(hooks) {
hooks.beforeEach(function() {
config['ember-cli-addon-docs'].projectPathInRepo = 'packages/foo-bar';
});

hooks.afterEach(function() {
config['ember-cli-addon-docs'].projectPathInRepo = '';
});

test('welcome page \'Edit this page\' link is correct', async function(assert) {
await visit('/sandbox');

const editThisPageLinkHref = await modulePage.editLink.href;

assert.equal(editThisPageLinkHref, 'https://github.com/ember-learn/ember-cli-addon-docs/edit/master/packages/foo-bar/tests/dummy/app/pods/sandbox/index/template.md');
});
});
});
35 changes: 20 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3132,13 +3132,13 @@ browserslist@^3.2.6:
electron-to-chromium "^1.3.47"

browserslist@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.1.1.tgz#328eb4ff1215b12df6589e9ab82f8adaa4fc8cd6"
integrity sha512-VBorw+tgpOtZ1BYhrVSVTzTt/3+vSE3eFUh0N2GCFK1HffceOaf32YS/bs6WiFhjDAblAFrx85jMy3BG9fBK2Q==
version "4.5.3"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.5.3.tgz#969495c410314bc89f14e748505e58be968080f1"
integrity sha512-Tx/Jtrmh6vFg24AelzLwCaCq1IUJiMDM1x/LPzqbmbktF8Zo7F9ONUpOWsFK6TtdON95mSMaQUWqi0ilc8xM6g==
dependencies:
caniuse-lite "^1.0.30000884"
electron-to-chromium "^1.3.62"
node-releases "^1.0.0-alpha.11"
caniuse-lite "^1.0.30000955"
electron-to-chromium "^1.3.122"
node-releases "^1.1.12"

bser@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -3316,10 +3316,10 @@ can-symlink@^1.0.0:
dependencies:
tmp "0.0.28"

caniuse-lite@^1.0.30000792, caniuse-lite@^1.0.30000805, caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000884:
version "1.0.30000888"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000888.tgz#22edb50d91dd70612b5898e3b36f460600c6492f"
integrity sha512-vftg+5p/lPsQGpnhSo/yBuYL36ai/cyjLvU3dOPJY1kkKrekLWIy8SLm+wzjX0hpCUdFTasC4/ZT7uqw4rKOnQ==
caniuse-lite@^1.0.30000792, caniuse-lite@^1.0.30000805, caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000955:
version "1.0.30000955"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000955.tgz#360fdb9a1e41d6dd996130411334e44a39e4446d"
integrity sha512-6AwmIKgqCYfDWWadRkAuZSHMQP4Mmy96xAXEdRBlN/luQhlRYOKgwOlZ9plpCOsVbBuqbTmGqDK3JUM/nlr8CA==

capture-exit@^1.2.0:
version "1.2.0"
Expand Down Expand Up @@ -4424,7 +4424,12 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.30, electron-to-chromium@^1.3.47, electron-to-chromium@^1.3.62:
electron-to-chromium@^1.3.122:
version "1.3.122"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.122.tgz#b32a0805f48557bd3c3b8104eadc7fa511b14a9a"
integrity sha512-3RKoIyCN4DhP2dsmleuFvpJAIDOseWH88wFYBzb22CSwoFDSWRc4UAMfrtc9h8nBdJjTNIN3rogChgOy6eFInw==

electron-to-chromium@^1.3.30, electron-to-chromium@^1.3.47:
version "1.3.72"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.72.tgz#b69683081d5b7eee6e1ea07b2f5fa30b3c72252d"
integrity sha512-OFbXEC01Lq7A66e3UywkvWYNN00HO1I9MAPereGe0NIXrt2MeaovL1bbY+951HKG0euUdPBe0L7yfKxgqxBMMw==
Expand Down Expand Up @@ -9266,10 +9271,10 @@ node-pre-gyp@^0.10.0:
semver "^5.3.0"
tar "^4"

node-releases@^1.0.0-alpha.11:
version "1.0.0-alpha.12"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.0.0-alpha.12.tgz#32e461b879ea76ac674e511d9832cf29da345268"
integrity sha512-VPB4rTPqpVyWKBHbSa4YPFme3+8WHsOSpvbp0Mfj0bWsC8TEjt4HQrLl1hsBDELlp1nB4lflSgSuGTYiuyaP7Q==
node-releases@^1.1.12:
version "1.1.13"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.13.tgz#8c03296b5ae60c08e2ff4f8f22ae45bd2f210083"
integrity sha512-fKZGviSXR6YvVPyc011NHuJDSD8gFQvLPmc2d2V3BS4gr52ycyQ1Xzs7a8B+Ax3Ni/W+5h1h4SqmzeoA8WZRmA==
dependencies:
semver "^5.3.0"

Expand Down

0 comments on commit ccfc0d5

Please sign in to comment.