Skip to content

Commit da9ad2f

Browse files
committed
Move <template> tags to the end of the class definition
1 parent 0c3fe90 commit da9ad2f

23 files changed

+560
-537
lines changed

app/components/color-scheme-menu.gjs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import eq from 'ember-truth-helpers/helpers/eq';
1010
import Dropdown from 'crates-io/components/dropdown';
1111

1212
export default class Header extends Component {
13+
/** @type {import("../services/dark-mode").default} */
14+
@service colorScheme;
15+
16+
colorSchemes = [
17+
{ mode: 'light', svg: 'sun' },
18+
{ mode: 'dark', svg: 'moon' },
19+
{ mode: 'system', svg: 'color-mode' },
20+
];
21+
22+
get icon() {
23+
return this.colorSchemes.find(({ mode }) => mode === this.colorScheme.scheme)?.svg;
24+
}
25+
1326
<template>
1427
<Dropdown data-test-dark-mode-menu ...attributes class='dropdown' as |dd|>
1528
<dd.Trigger @hideArrow={{true}} class='trigger' data-test-dark-mode-toggle>
@@ -33,16 +46,4 @@ export default class Header extends Component {
3346
</dd.Menu>
3447
</Dropdown>
3548
</template>
36-
/** @type {import("../services/dark-mode").default} */
37-
@service colorScheme;
38-
39-
colorSchemes = [
40-
{ mode: 'light', svg: 'sun' },
41-
{ mode: 'dark', svg: 'moon' },
42-
{ mode: 'system', svg: 'color-mode' },
43-
];
44-
45-
get icon() {
46-
return this.colorSchemes.find(({ mode }) => mode === this.colorScheme.scheme)?.svg;
47-
}
4849
}

app/components/copy-button.gjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { restartableTask } from 'ember-concurrency';
66
import perform from 'ember-concurrency/helpers/perform';
77

88
export default class CrateTomlCopy extends Component {
9-
<template>
10-
<button type='button' ...attributes {{on 'click' (perform this.copyTask)}}>
11-
{{yield}}
12-
</button>
13-
</template>
149
@service notifications;
1510

1611
copyTask = restartableTask(async () => {
@@ -22,4 +17,10 @@ export default class CrateTomlCopy extends Component {
2217
this.notifications.error('Copy to clipboard failed!');
2318
}
2419
});
20+
21+
<template>
22+
<button type='button' ...attributes {{on 'click' (perform this.copyTask)}}>
23+
{{yield}}
24+
</button>
25+
</template>
2526
}

app/components/crate-header.gjs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ import PageHeader from 'crates-io/components/page-header';
1414
import Tooltip from 'crates-io/components/tooltip';
1515

1616
export default class CrateHeader extends Component {
17+
@service session;
18+
19+
@alias('loadKeywordsTask.last.value') keywords;
20+
21+
constructor() {
22+
super(...arguments);
23+
24+
this.loadKeywordsTask.perform().catch(() => {
25+
// ignore all errors and just don't display keywords if the request fails
26+
});
27+
}
28+
29+
get isOwner() {
30+
let userId = this.session.currentUser?.id;
31+
return this.args.crate?.hasOwnerUser(userId) ?? false;
32+
}
33+
34+
loadKeywordsTask = task(async () => {
35+
return (await this.args.crate?.keywords) ?? [];
36+
});
37+
1738
<template>
1839
<PageHeader class='header' data-test-heading>
1940
<h1 class='heading'>
@@ -92,24 +113,4 @@ export default class CrateHeader extends Component {
92113
{{/if}}
93114
</NavTabs>
94115
</template>
95-
@service session;
96-
97-
@alias('loadKeywordsTask.last.value') keywords;
98-
99-
constructor() {
100-
super(...arguments);
101-
102-
this.loadKeywordsTask.perform().catch(() => {
103-
// ignore all errors and just don't display keywords if the request fails
104-
});
105-
}
106-
107-
get isOwner() {
108-
let userId = this.session.currentUser?.id;
109-
return this.args.crate?.hasOwnerUser(userId) ?? false;
110-
}
111-
112-
loadKeywordsTask = task(async () => {
113-
return (await this.args.crate?.keywords) ?? [];
114-
});
115116
}

app/components/crate-sidebar.gjs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,51 @@ import prettyBytes from 'crates-io/helpers/pretty-bytes';
2626
import { simplifyUrl } from './crate-sidebar/link';
2727

2828
export default class CrateSidebar extends Component {
29+
@service notifications;
30+
@service playground;
31+
@service sentry;
32+
33+
get showHomepage() {
34+
let { repository, homepage } = this.args.crate;
35+
return homepage && (!repository || simplifyUrl(repository) !== simplifyUrl(homepage));
36+
}
37+
38+
get playgroundLink() {
39+
let playgroundCrates = this.playground.crates;
40+
if (!playgroundCrates) return;
41+
42+
let playgroundCrate = playgroundCrates.find(it => it.name === this.args.crate.name);
43+
if (!playgroundCrate) return;
44+
45+
return `https://play.rust-lang.org/?edition=2021&code=use%20${playgroundCrate.id}%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20%2F%2F%20try%20using%20the%20%60${playgroundCrate.id}%60%20crate%20here%0A%7D`;
46+
}
47+
48+
get canHover() {
49+
return window?.matchMedia('(hover: hover)').matches;
50+
}
51+
52+
constructor() {
53+
super(...arguments);
54+
55+
// load Rust Playground crates list, if necessary
56+
this.playground.loadCrates().catch(error => {
57+
if (!(didCancel(error) || error.isServerError || error.isNetworkError)) {
58+
// report unexpected errors to Sentry
59+
this.sentry.captureException(error);
60+
}
61+
});
62+
}
63+
64+
@action
65+
async copyToClipboard(text) {
66+
try {
67+
await navigator.clipboard.writeText(text);
68+
this.notifications.success('Copied to clipboard!');
69+
} catch {
70+
this.notifications.error('Copy to clipboard failed!');
71+
}
72+
}
73+
2974
<template>
3075
<section aria-label='Crate metadata' ...attributes class='sidebar'>
3176
<div class='metadata'>
@@ -173,48 +218,4 @@ export default class CrateSidebar extends Component {
173218
</div>
174219
</section>
175220
</template>
176-
@service notifications;
177-
@service playground;
178-
@service sentry;
179-
180-
get showHomepage() {
181-
let { repository, homepage } = this.args.crate;
182-
return homepage && (!repository || simplifyUrl(repository) !== simplifyUrl(homepage));
183-
}
184-
185-
get playgroundLink() {
186-
let playgroundCrates = this.playground.crates;
187-
if (!playgroundCrates) return;
188-
189-
let playgroundCrate = playgroundCrates.find(it => it.name === this.args.crate.name);
190-
if (!playgroundCrate) return;
191-
192-
return `https://play.rust-lang.org/?edition=2021&code=use%20${playgroundCrate.id}%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20%2F%2F%20try%20using%20the%20%60${playgroundCrate.id}%60%20crate%20here%0A%7D`;
193-
}
194-
195-
get canHover() {
196-
return window?.matchMedia('(hover: hover)').matches;
197-
}
198-
199-
constructor() {
200-
super(...arguments);
201-
202-
// load Rust Playground crates list, if necessary
203-
this.playground.loadCrates().catch(error => {
204-
if (!(didCancel(error) || error.isServerError || error.isNetworkError)) {
205-
// report unexpected errors to Sentry
206-
this.sentry.captureException(error);
207-
}
208-
});
209-
}
210-
211-
@action
212-
async copyToClipboard(text) {
213-
try {
214-
await navigator.clipboard.writeText(text);
215-
this.notifications.success('Copied to clipboard!');
216-
} catch {
217-
this.notifications.error('Copy to clipboard failed!');
218-
}
219-
}
220221
}

app/components/crate-sidebar/install-instructions.gjs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ import isClipboardSupported from 'crates-io/helpers/is-clipboard-supported';
1111
import sum from 'crates-io/helpers/sum';
1212

1313
export default class InstallInstructions extends Component {
14+
get cargoInstallCommand() {
15+
return this.args.exactVersion
16+
? `cargo install ${this.args.crate}@${this.args.version}`
17+
: `cargo install ${this.args.crate}`;
18+
}
19+
20+
get cargoAddCommand() {
21+
return this.args.exactVersion
22+
? `cargo add ${this.args.crate}@=${this.args.version}`
23+
: `cargo add ${this.args.crate}`;
24+
}
25+
26+
get tomlSnippet() {
27+
let version = this.args.version.split('+')[0];
28+
let exact = this.args.exactVersion ? '=' : '';
29+
return `${this.args.crate} = "${exact}${version}"`;
30+
}
31+
1432
<template>
1533
{{#if @binNames}}
1634
{{#if (isClipboardSupported)}}
@@ -85,21 +103,4 @@ export default class InstallInstructions extends Component {
85103
{{/if}}
86104
{{/if}}
87105
</template>
88-
get cargoInstallCommand() {
89-
return this.args.exactVersion
90-
? `cargo install ${this.args.crate}@${this.args.version}`
91-
: `cargo install ${this.args.crate}`;
92-
}
93-
94-
get cargoAddCommand() {
95-
return this.args.exactVersion
96-
? `cargo add ${this.args.crate}@=${this.args.version}`
97-
: `cargo add ${this.args.crate}`;
98-
}
99-
100-
get tomlSnippet() {
101-
let version = this.args.version.split('+')[0];
102-
let exact = this.args.exactVersion ? '=' : '';
103-
return `${this.args.crate} = "${exact}${version}"`;
104-
}
105106
}

app/components/crate-sidebar/link.gjs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import scopedClass from 'ember-scoped-css/helpers/scoped-class';
44
import svgJar from 'ember-svg-jar/helpers/svg-jar';
55

66
export default class CrateSidebarLink extends Component {
7+
get text() {
8+
let { url } = this.args;
9+
return simplifyUrl(url);
10+
}
11+
12+
get isDocsRs() {
13+
return this.text.startsWith('docs.rs/');
14+
}
15+
16+
get isGitHub() {
17+
return this.text.startsWith('github.com/');
18+
}
19+
720
<template>
821
<div ...attributes>
922
<h2 class='title' data-test-title>{{@title}}</h2>
@@ -22,18 +35,6 @@ export default class CrateSidebarLink extends Component {
2235
</div>
2336
</div>
2437
</template>
25-
get text() {
26-
let { url } = this.args;
27-
return simplifyUrl(url);
28-
}
29-
30-
get isDocsRs() {
31-
return this.text.startsWith('docs.rs/');
32-
}
33-
34-
get isGitHub() {
35-
return this.text.startsWith('github.com/');
36-
}
3738
}
3839

3940
export function simplifyUrl(url) {

app/components/dependency-list/row.gjs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@ import Tooltip from 'crates-io/components/tooltip';
1515
import formatReq from 'crates-io/helpers/format-req';
1616

1717
export default class VersionRow extends Component {
18+
@service store;
19+
20+
@tracked focused = false;
21+
22+
@action setFocused(value) {
23+
this.focused = value;
24+
}
25+
26+
constructor() {
27+
super(...arguments);
28+
29+
this.loadCrateTask.perform().catch(() => {
30+
// ignore all errors and just don't display a description if the request fails
31+
});
32+
}
33+
34+
get description() {
35+
return this.loadCrateTask.lastSuccessful?.value?.description;
36+
}
37+
38+
get featuresDescription() {
39+
let { default_features: defaultFeatures, features } = this.args.dependency;
40+
let numFeatures = features.length;
41+
42+
if (numFeatures !== 0) {
43+
return defaultFeatures
44+
? `${numFeatures} extra feature${numFeatures > 1 ? 's' : ''}`
45+
: `only ${numFeatures} feature${numFeatures > 1 ? 's' : ''}`;
46+
} else if (!defaultFeatures) {
47+
return 'no default features';
48+
}
49+
}
50+
51+
loadCrateTask = task(async () => {
52+
let { dependency } = this.args;
53+
return await this.store.findRecord('crate', dependency.crate_id);
54+
});
55+
1856
<template>
1957
<div
2058
data-test-dependency={{@dependency.crate_id}}
@@ -82,41 +120,4 @@ export default class VersionRow extends Component {
82120
</div>
83121
</div>
84122
</template>
85-
@service store;
86-
87-
@tracked focused = false;
88-
89-
@action setFocused(value) {
90-
this.focused = value;
91-
}
92-
93-
constructor() {
94-
super(...arguments);
95-
96-
this.loadCrateTask.perform().catch(() => {
97-
// ignore all errors and just don't display a description if the request fails
98-
});
99-
}
100-
101-
get description() {
102-
return this.loadCrateTask.lastSuccessful?.value?.description;
103-
}
104-
105-
get featuresDescription() {
106-
let { default_features: defaultFeatures, features } = this.args.dependency;
107-
let numFeatures = features.length;
108-
109-
if (numFeatures !== 0) {
110-
return defaultFeatures
111-
? `${numFeatures} extra feature${numFeatures > 1 ? 's' : ''}`
112-
: `only ${numFeatures} feature${numFeatures > 1 ? 's' : ''}`;
113-
} else if (!defaultFeatures) {
114-
return 'no default features';
115-
}
116-
}
117-
118-
loadCrateTask = task(async () => {
119-
let { dependency } = this.args;
120-
return await this.store.findRecord('crate', dependency.crate_id);
121-
});
122123
}

0 commit comments

Comments
 (0)