@@ -2,7 +2,6 @@ import bindAll from 'lodash.bindall';
22import PropTypes from 'prop-types' ;
33import React from 'react' ;
44import { connect } from 'react-redux' ;
5- import JSZip from 'jszip' ;
65import { projectTitleInitialState } from '../reducers/project-title' ;
76
87class RubyDownloader extends React . Component {
@@ -13,43 +12,29 @@ class RubyDownloader extends React.Component {
1312 ] ) ;
1413 }
1514 saveRuby ( ) {
16- const projectRuby = `require "smalruby"\n${ this . props . rubyCode } ` ;
17- // TODO want to eventually move zip creation out of here, and perhaps
18- // into scratch-storage
19- const zip = new JSZip ( ) ;
20-
21- // Put everything in a zip file
22- zip . file ( 'project.rb' , projectRuby ) ;
23-
24- return zip . generateAsync ( {
25- type : 'blob' ,
26- compression : 'DEFLATE' ,
27- compressionOptions : {
28- level : 6 // Tradeoff between best speed (1) and best compression (9)
29- }
30- } ) ;
15+ const projectRuby = `require "smalruby3"\n\n${ this . props . rubyCode } ` ;
16+ return new Blob ( [ projectRuby ] , { type : 'text/plain' } ) ;
3117 }
3218 downloadProject ( ) {
3319 const downloadLink = document . createElement ( 'a' ) ;
3420 document . body . appendChild ( downloadLink ) ;
3521
36- this . saveRuby ( ) . then ( content => {
37- if ( this . props . onSaveFinished ) {
38- this . props . onSaveFinished ( ) ;
39- }
40- // Use special ms version if available to get it working on Edge.
41- if ( navigator . msSaveOrOpenBlob ) {
42- navigator . msSaveOrOpenBlob ( content , this . props . projectFilename ) ;
43- return ;
44- }
22+ const content = this . saveRuby ( ) ;
23+ if ( this . props . onSaveFinished ) {
24+ this . props . onSaveFinished ( ) ;
25+ }
26+ // Use special ms version if available to get it working on Edge.
27+ if ( navigator . msSaveOrOpenBlob ) {
28+ navigator . msSaveOrOpenBlob ( content , this . props . projectFilename ) ;
29+ return ;
30+ }
4531
46- const url = window . URL . createObjectURL ( content ) ;
47- downloadLink . href = url ;
48- downloadLink . download = this . props . projectFilename ;
49- downloadLink . click ( ) ;
50- window . URL . revokeObjectURL ( url ) ;
51- document . body . removeChild ( downloadLink ) ;
52- } ) ;
32+ const url = window . URL . createObjectURL ( content ) ;
33+ downloadLink . href = url ;
34+ downloadLink . download = this . props . projectFilename ;
35+ downloadLink . click ( ) ;
36+ window . URL . revokeObjectURL ( url ) ;
37+ document . body . removeChild ( downloadLink ) ;
5338 }
5439 render ( ) {
5540 const {
@@ -66,7 +51,7 @@ const getProjectFilename = (curTitle, defaultTitle) => {
6651 if ( ! filenameTitle || filenameTitle . length === 0 ) {
6752 filenameTitle = defaultTitle ;
6853 }
69- return `${ filenameTitle . substring ( 0 , 100 ) } .zip ` ;
54+ return `${ filenameTitle . substring ( 0 , 100 ) } .rb ` ;
7055} ;
7156
7257RubyDownloader . propTypes = {
0 commit comments