Skip to content

Commit 2eea0c4

Browse files
author
t-kazu
committed
rbファイルでダウンロードできるようにしました
1 parent 7cc48e0 commit 2eea0c4

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"immutable": "3.8.2",
6363
"intl": "1.2.5",
6464
"jest": "^21.0.0",
65-
"jszip": "3.1.5",
6665
"keymirror": "0.1.1",
6766
"lodash.bindall": "4.4.0",
6867
"lodash.debounce": "4.0.8",

src/containers/ruby-downloader.jsx

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import bindAll from 'lodash.bindall';
22
import PropTypes from 'prop-types';
33
import React from 'react';
44
import {connect} from 'react-redux';
5-
import JSZip from 'jszip';
65
import {projectTitleInitialState} from '../reducers/project-title';
76

87
class 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

7257
RubyDownloader.propTypes = {

0 commit comments

Comments
 (0)