Skip to content

Commit d01c5f1

Browse files
committed
controllers/crate.version: Move documentationLink property to version model
1 parent 5767800 commit d01c5f1

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

app/controllers/crate/version.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,4 @@ export default class CrateVersionController extends Controller {
123123
return readme;
124124
})
125125
loadReadmeTask;
126-
127-
@computed('crate.{documentation,name}', 'currentVersion.{num,loadDocsBuildsTask.lastSuccessful.value}')
128-
get documentationLink() {
129-
// if this is *not* a docs.rs link we'll return it directly
130-
if (this.crate.documentation && !this.crate.documentation.startsWith('https://docs.rs/')) {
131-
return this.crate.documentation;
132-
}
133-
134-
// if we know about a successful docs.rs build, we'll return a link to that
135-
if (this.currentVersion.loadDocsBuildsTask.lastSuccessful) {
136-
let docsBuilds = this.currentVersion.loadDocsBuildsTask.lastSuccessful.value;
137-
if (docsBuilds.length !== 0 && docsBuilds[0].build_status === true) {
138-
return `https://docs.rs/${this.crate.name}/${this.currentVersion.num}`;
139-
}
140-
}
141-
142-
// finally, we'll return the specified documentation link, whatever it is
143-
if (this.crate.documentation) {
144-
return this.crate.documentation;
145-
}
146-
147-
return null;
148-
}
149126
}

app/models/version.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ export default class Version extends Model {
7070
})
7171
loadDocsBuildsTask;
7272

73+
@computed('crate.{documentation,name}', 'num', 'loadDocsBuildsTask.lastSuccessful.value')
74+
get documentationLink() {
75+
// if this is *not* a docs.rs link we'll return it directly
76+
if (this.crate.documentation && !this.crate.documentation.startsWith('https://docs.rs/')) {
77+
return this.crate.documentation;
78+
}
79+
80+
// if we know about a successful docs.rs build, we'll return a link to that
81+
if (this.loadDocsBuildsTask.lastSuccessful) {
82+
let docsBuilds = this.loadDocsBuildsTask.lastSuccessful.value;
83+
if (docsBuilds.length !== 0 && docsBuilds[0].build_status === true) {
84+
return `https://docs.rs/${this.crateName}/${this.num}`;
85+
}
86+
}
87+
88+
// finally, we'll return the specified documentation link, whatever it is
89+
if (this.crate.documentation) {
90+
return this.crate.documentation;
91+
}
92+
93+
return null;
94+
}
95+
7396
@(task(function* () {
7497
let response = yield fetch(`/api/v1/crates/${this.crate.id}/${this.num}/yank`, { method: 'DELETE' });
7598
if (!response.ok) {

app/templates/crate/version.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
{{#if this.crate.mailing_list}}
2727
<li><a href="{{this.crate.mailing_list}}">Mailing list</a></li>
2828
{{/if}}
29-
{{#if this.documentationLink}}
30-
<li><a href="{{this.documentationLink}}" data-test-docs-link>Documentation</a></li>
29+
{{#if this.currentVersion.documentationLink}}
30+
<li><a href="{{this.currentVersion.documentationLink}}" data-test-docs-link>Documentation</a></li>
3131
{{/if}}
3232
{{#if this.crate.repository}}
3333
<li><a href="{{this.crate.repository}}">Repository</a></li>

0 commit comments

Comments
 (0)