File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 171
171
</div >
172
172
{{ /if }}
173
173
</div >
174
+
175
+ {{ #if this.playgroundLink }}
176
+ <div >
177
+ <a
178
+ href ={{ this.playgroundLink }}
179
+ target =" _blank"
180
+ rel =" noopener noreferrer"
181
+ local-class =" playground-button"
182
+ >
183
+ Try on Rust Playground
184
+ </a >
185
+ </div >
186
+ {{ /if }}
174
187
</section >
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const NUM_VERSIONS = 5;
7
7
8
8
export default class DownloadGraph extends Component {
9
9
@service session ;
10
+ @service playground ;
10
11
11
12
@computed ( 'args.crate.owner_user' , 'session.currentUser.id' )
12
13
get isOwner ( ) {
@@ -21,4 +22,14 @@ export default class DownloadGraph extends Component {
21
22
}
22
23
23
24
@gt ( 'sortedVersions.length' , NUM_VERSIONS ) hasMoreVersions ;
25
+
26
+ get playgroundLink ( ) {
27
+ let playgroundCrates = this . playground . crates ;
28
+ if ( ! playgroundCrates ) return ;
29
+
30
+ let playgroundCrate = playgroundCrates . find ( it => it . name === this . crate . name ) ;
31
+ if ( ! playgroundCrate ) return ;
32
+
33
+ return `https://play.rust-lang.org/?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` ;
34
+ }
24
35
}
Original file line number Diff line number Diff line change @@ -118,3 +118,9 @@ ul.owners, ul.keywords {
118
118
.more-versions-link {
119
119
composes : small from '../styles/shared/typography.module.css' ;
120
120
}
121
+
122
+ .playground-button {
123
+ composes : yellow-button small from '../styles/shared/buttons.module.css' ;
124
+ justify-content : center;
125
+ margin-top : 20px ;
126
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { AjaxError } from '../../utils/ajax';
7
7
8
8
export default class VersionRoute extends Route {
9
9
@service notifications ;
10
+ @service playground ;
10
11
11
12
async model ( params ) {
12
13
let crate = this . modelFor ( 'crate' ) ;
@@ -49,6 +50,9 @@ export default class VersionRoute extends Route {
49
50
}
50
51
} ) ;
51
52
}
53
+
54
+ // load Rust Playground crates list
55
+ this . playground . loadCrates ( ) ;
52
56
}
53
57
54
58
serialize ( model ) {
You can’t perform that action at this time.
0 commit comments