Skip to content

Commit 2217dd5

Browse files
Merge pull request #676 from kureuil/docs-rs-integration
Add docs.rs integration
2 parents aeec0b5 + c025fbb commit 2217dd5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

app/routes/crate/version.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default Ember.Route.extend({
88

99
model(params) {
1010
const requestedVersion = params.version_num === 'all' ? '' : params.version_num;
11-
1211
const crate = this.modelFor('crate');
1312
const controller = this.controllerFor(this.routeName);
1413
const maxVersion = crate.get('max_version');
@@ -35,6 +34,20 @@ export default Ember.Route.extend({
3534
return result;
3635
};
3736

37+
const fetchCrateDocumentation = () => {
38+
if (!crate.get('documentation') ||
39+
crate.get('documentation').substr(0, 16) === 'https://docs.rs/') {
40+
let crateName = crate.get('name');
41+
let crateVersion = params.version_num;
42+
ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`)
43+
.then((r) => {
44+
if (r.length > 0 && r[0].build_status === true) {
45+
crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/`);
46+
}
47+
});
48+
}
49+
};
50+
3851
// Fallback to the crate's last stable version
3952
// If `max_version` is `0.0.0` then all versions have been yanked
4053
if (!requestedVersion && maxVersion !== '0.0.0') {
@@ -52,10 +65,13 @@ export default Ember.Route.extend({
5265
} else {
5366
params.version_num = latestStableVersion.get('num');
5467
}
55-
});
68+
}).then(fetchCrateDocumentation);
5669
} else {
5770
params.version_num = maxVersion;
71+
fetchCrateDocumentation();
5872
}
73+
} else {
74+
fetchCrateDocumentation();
5975
}
6076

6177
controller.set('crate', crate);

0 commit comments

Comments
 (0)