Skip to content

Commit 4c74a77

Browse files
committed
Add 'docs' well-known route for getting to a crate's documentation
Implements rust-lang#197.
1 parent 5c9b276 commit 4c74a77

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

app/router.js

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Router.map(function() {
1616
this.route('download');
1717
this.route('versions');
1818
this.route('reverse_dependencies');
19+
20+
// Well-known routes
21+
this.route('docs');
1922
});
2023
this.route('me', function() {
2124
this.route('crates');

app/routes/crate/docs.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Ember from 'ember';
2+
import Crate from 'cargo/models/crate';
3+
4+
export default Ember.Route.extend({
5+
afterModel: function(data) {
6+
var crate;
7+
8+
if (data instanceof Crate) {
9+
crate = data;
10+
} else {
11+
crate = data.crate;
12+
}
13+
14+
var documentation = crate.get('documentation');
15+
16+
if (documentation) {
17+
window.location = documentation;
18+
} else {
19+
// Redirect to the crate's main page if no documentation
20+
// URL is found.
21+
this.transitionTo('crate', crate);
22+
}
23+
}
24+
});

0 commit comments

Comments
 (0)