smalruby-editor 0.1.5-x86-mingw32 → 0.1.6-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +8 -0
  4. data/README.rdoc +3 -0
  5. data/app/assets/javascripts/application.js +0 -1
  6. data/app/assets/javascripts/models/source_code.js.coffee +5 -2
  7. data/app/assets/javascripts/smalruby.js.coffee +18 -11
  8. data/app/assets/javascripts/views/main_menu_view.js.coffee +139 -81
  9. data/app/controllers/source_codes_controller.rb +7 -0
  10. data/app/models/concerns/ruby_to_block.rb +391 -0
  11. data/app/models/source_code.rb +3 -2
  12. data/app/views/editor/demo.html.erb +1 -1
  13. data/app/views/editor/index.html.haml +2 -2
  14. data/config/routes.rb +1 -0
  15. data/{app/assets/demos → demos}/default.xml +0 -0
  16. data/{app/assets/demos → demos}/rgb_led_anode.xml +82 -82
  17. data/lib/smalruby_editor/version.rb +3 -3
  18. data/lib/tasks/release.rake +0 -4
  19. data/public/assets/{application-0047adbc0fb7a529ef7a41b5e0e7d097.js → application-8bfffad1222d4e198f3c7ccc1cbd774f.js} +179 -144
  20. data/public/assets/{application-0047adbc0fb7a529ef7a41b5e0e7d097.js.gz → application-8bfffad1222d4e198f3c7ccc1cbd774f.js.gz} +0 -0
  21. data/public/assets/manifest-332a5a1668194028b55103e0ea45c054.json +1 -1
  22. data/smalruby-editor.gemspec +0 -6
  23. data/spec/acceptance/base.feature +119 -0
  24. data/spec/acceptance/block_mode/translate.feature +14 -0
  25. data/spec/acceptance/ruby_mode/translate.feature +65 -0
  26. data/spec/acceptance/standalone/run.feature +14 -1
  27. data/spec/controllers/source_codes_controller_spec.rb +22 -0
  28. data/{public/assets/default-5d1886100d7c8961e9962bbc4bb0c714.xml → spec/fixtures/files/01.rb.xml} +0 -0
  29. data/spec/models/concerns/ruby_to_block_spec.rb +329 -0
  30. data/spec/steps/base_steps.rb +230 -0
  31. data/spec/steps/block_mode_steps.rb +9 -1
  32. data/spec/steps/fix_turnip.rb +28 -0
  33. data/spec/steps/text_editor_steps.rb +52 -193
  34. metadata +19 -97
  35. data/app/assets/javascripts/ruby_mode.js.coffee.erb +0 -12
  36. data/public/assets/rgb_led_anode-91225bef2a8b97f1cefee862a0619b91.xml +0 -83
  37. data/spec/acceptance/ruby_mode/base.feature +0 -33
  38. data/spec/steps/ace_steps.rb +0 -77
File without changes
@@ -1,83 +1,83 @@
1
- <xml xmlns="http://www.w3.org/1999/xhtml">
2
- <character name="frog1" x="261" y="191" angle="0" costumes="frog1.png" />
3
- <block type="hardware_init_hardware" x="40" y="6" />
4
- <block type="character_new" x="45" y="50">
5
- <field name="NAME">frog1</field>
6
- <statement name="DO">
7
- <block type="events_on_click">
8
- <statement name="DO">
9
- <block type="looks_say" inline="true">
10
- <value name="TEXT">
11
- <block type="text">
12
- <field name="TEXT">ライトをぴかっとさせるでよ♪</field>
13
- </block>
14
- </value>
15
- <next>
16
- <block type="hardware_rgb_led_on">
17
- <field name="AC">anode</field>
18
- <field name="PIN">D3</field>
19
- <field name="COLOUR">#3333ff</field>
20
- <next>
21
- <block type="control_sleep" inline="true">
22
- <value name="SEC">
23
- <block type="math_number">
24
- <field name="NUM">1</field>
25
- </block>
26
- </value>
27
- <next>
28
- <block type="hardware_rgb_led_on">
29
- <field name="AC">anode</field>
30
- <field name="PIN">D3</field>
31
- <field name="COLOUR">#ffff99</field>
32
- <next>
33
- <block type="control_sleep" inline="true">
34
- <value name="SEC">
35
- <block type="math_number">
36
- <field name="NUM">1</field>
37
- </block>
38
- </value>
39
- <next>
40
- <block type="hardware_rgb_led_on">
41
- <field name="AC">anode</field>
42
- <field name="PIN">D3</field>
43
- <field name="COLOUR">#ff0000</field>
44
- <next>
45
- <block type="control_sleep" inline="true">
46
- <value name="SEC">
47
- <block type="math_number">
48
- <field name="NUM">1</field>
49
- </block>
50
- </value>
51
- <next>
52
- <block type="hardware_rgb_led_off">
53
- <field name="AC">anode</field>
54
- <field name="PIN">D3</field>
55
- <next>
56
- <block type="looks_say" inline="true">
57
- <value name="TEXT">
58
- <block type="text">
59
- <field name="TEXT" />
60
- </block>
61
- </value>
62
- </block>
63
- </next>
64
- </block>
65
- </next>
66
- </block>
67
- </next>
68
- </block>
69
- </next>
70
- </block>
71
- </next>
72
- </block>
73
- </next>
74
- </block>
75
- </next>
76
- </block>
77
- </next>
78
- </block>
79
- </statement>
80
- </block>
81
- </statement>
82
- </block>
1
+ <xml xmlns="http://www.w3.org/1999/xhtml">
2
+ <character name="frog1" x="261" y="191" angle="0" costumes="frog1.png" />
3
+ <block type="hardware_init_hardware" x="40" y="6" />
4
+ <block type="character_new" x="45" y="50">
5
+ <field name="NAME">frog1</field>
6
+ <statement name="DO">
7
+ <block type="events_on_click">
8
+ <statement name="DO">
9
+ <block type="looks_say" inline="true">
10
+ <value name="TEXT">
11
+ <block type="text">
12
+ <field name="TEXT">ライトをぴかっとさせるでよ♪</field>
13
+ </block>
14
+ </value>
15
+ <next>
16
+ <block type="hardware_rgb_led_on">
17
+ <field name="AC">anode</field>
18
+ <field name="PIN">D3</field>
19
+ <field name="COLOUR">#3333ff</field>
20
+ <next>
21
+ <block type="control_sleep" inline="true">
22
+ <value name="SEC">
23
+ <block type="math_number">
24
+ <field name="NUM">1</field>
25
+ </block>
26
+ </value>
27
+ <next>
28
+ <block type="hardware_rgb_led_on">
29
+ <field name="AC">anode</field>
30
+ <field name="PIN">D3</field>
31
+ <field name="COLOUR">#ffff99</field>
32
+ <next>
33
+ <block type="control_sleep" inline="true">
34
+ <value name="SEC">
35
+ <block type="math_number">
36
+ <field name="NUM">1</field>
37
+ </block>
38
+ </value>
39
+ <next>
40
+ <block type="hardware_rgb_led_on">
41
+ <field name="AC">anode</field>
42
+ <field name="PIN">D3</field>
43
+ <field name="COLOUR">#ff0000</field>
44
+ <next>
45
+ <block type="control_sleep" inline="true">
46
+ <value name="SEC">
47
+ <block type="math_number">
48
+ <field name="NUM">1</field>
49
+ </block>
50
+ </value>
51
+ <next>
52
+ <block type="hardware_rgb_led_off">
53
+ <field name="AC">anode</field>
54
+ <field name="PIN">D3</field>
55
+ <next>
56
+ <block type="looks_say" inline="true">
57
+ <value name="TEXT">
58
+ <block type="text">
59
+ <field name="TEXT" />
60
+ </block>
61
+ </value>
62
+ </block>
63
+ </next>
64
+ </block>
65
+ </next>
66
+ </block>
67
+ </next>
68
+ </block>
69
+ </next>
70
+ </block>
71
+ </next>
72
+ </block>
73
+ </next>
74
+ </block>
75
+ </next>
76
+ </block>
77
+ </next>
78
+ </block>
79
+ </statement>
80
+ </block>
81
+ </statement>
82
+ </block>
83
83
  </xml>
@@ -1,3 +1,3 @@
1
- module SmalrubyEditor
2
- VERSION = '0.1.5'
3
- end
1
+ module SmalrubyEditor
2
+ VERSION = '0.1.6'
3
+ end
@@ -6,8 +6,6 @@ task :build do
6
6
 
7
7
  ENV['GEM_PLATFORM'] = 'x86-mingw32'
8
8
  Rake::Task['gem:build'].reenable
9
- Rake::Task['assets:clobber'].reenable
10
- Rake::Task['assets:precompile:standalone'].reenable
11
9
  Rake::Task['gem:build'].invoke
12
10
  end
13
11
 
@@ -18,8 +16,6 @@ task :release do
18
16
  ENV['GEM_PLATFORM'] = 'x86-mingw32'
19
17
  Rake::Task['gem:release'].reenable
20
18
  Rake::Task['gem:build'].reenable
21
- Rake::Task['assets:clobber'].reenable
22
- Rake::Task['assets:precompile:standalone'].reenable
23
19
  Rake::Task['gem:release'].invoke
24
20
 
25
21
  sh 'git mirror'
@@ -12513,7 +12513,7 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12513
12513
  }
12514
12514
  html = $('<div class="alert alert-success" style="display: none">').append("<h4><i class=\"icon-star\"></i>" + title + "</h4>").append(msg);
12515
12515
  $(selector).append(html);
12516
- return html.fadeIn('slow').delay(3000).fadeOut('slow');
12516
+ html.fadeIn('slow').delay(3000).fadeOut('slow');
12517
12517
  };
12518
12518
 
12519
12519
  window.errorMessage = function(msg, selector) {
@@ -12523,7 +12523,7 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12523
12523
  }
12524
12524
  html = $('<div class="alert alert-error" style="display: none">').append('<button type="button" class="close" data-dismiss="alert">×</button>').append('<h4><i class="icon-exclamation-sign"></i>エラー</h4>').append(msg);
12525
12525
  $(selector).append(html);
12526
- return html.fadeIn('slow');
12526
+ html.fadeIn('slow');
12527
12527
  };
12528
12528
 
12529
12529
  window.Smalruby = {
@@ -12532,7 +12532,8 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12532
12532
  Views: {},
12533
12533
  Routers: {},
12534
12534
  initialize: function() {
12535
- var _this = this;
12535
+ var session, textEditor,
12536
+ _this = this;
12536
12537
  _.extend(_.templateSettings, {
12537
12538
  escape: /{{-([\s\S]+?)}}/,
12538
12539
  evaluate: /{{([\s\S]+?)}}/,
@@ -12546,20 +12547,6 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12546
12547
  this.Views.CharacterModalView = new Smalruby.CharacterModalView({
12547
12548
  el: $('#character-modal')
12548
12549
  });
12549
- $('a[data-toggle="tab"]').on('shown', function(e) {
12550
- var data;
12551
- if ($(e.target).attr('href') === '#block-tab') {
12552
- return window.blockMode = true;
12553
- } else {
12554
- window.blockMode = false;
12555
- data = Blockly.Ruby.workspaceToCode();
12556
- if ($.trim(data).length > 0) {
12557
- window.textEditor.getSession().getDocument().setValue(data);
12558
- window.textEditor.moveCursorTo(0, 0);
12559
- }
12560
- return window.textEditor.focus();
12561
- }
12562
- });
12563
12550
  Smalruby.downloading = false;
12564
12551
  window.onbeforeunload = function(event) {
12565
12552
  if (!Smalruby.downloading && window.changed) {
@@ -12578,7 +12565,8 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12578
12565
  Blockly.Toolbox.tree_.expandAll();
12579
12566
  this.blocklyFirst = true;
12580
12567
  this.blocklyLoading = false;
12581
- return Blockly.addChangeListener(function() {
12568
+ Blockly.addChangeListener(function() {
12569
+ Smalruby.changedAfterTranslating = true;
12582
12570
  if (_this.blocklyFirst) {
12583
12571
  _this.blocklyFirst = false;
12584
12572
  return;
@@ -12589,6 +12577,20 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12589
12577
  }
12590
12578
  return window.changed = true;
12591
12579
  });
12580
+ window.textEditor = textEditor = ace.edit('text-editor');
12581
+ textEditor.setTheme('ace/theme/clouds');
12582
+ textEditor.setShowInvisibles(true);
12583
+ textEditor.gotoLine(0, 0);
12584
+ textEditor.on('change', function(e) {
12585
+ if (!_this.translating) {
12586
+ window.changed = true;
12587
+ return Smalruby.changedAfterTranslating = true;
12588
+ }
12589
+ });
12590
+ session = textEditor.getSession();
12591
+ session.setMode('ace/mode/ruby');
12592
+ session.setTabSize(2);
12593
+ return session.setUseSoftTabs(true);
12592
12594
  },
12593
12595
  loadXml: function(data, workspace) {
12594
12596
  var c, chars, i, xml, xmlChild;
@@ -12795,8 +12797,14 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12795
12797
  }
12796
12798
  return this.delete_(action);
12797
12799
  },
12798
- post_: function(action) {
12800
+ toBlocks: function() {
12801
+ return this.post_('to_blocks', 'html');
12802
+ },
12803
+ post_: function(action, dataType) {
12799
12804
  var dfr;
12805
+ if (dataType == null) {
12806
+ dataType = 'json';
12807
+ }
12800
12808
  dfr = $.Deferred();
12801
12809
  $.ajax({
12802
12810
  url: "/source_codes/" + action,
@@ -12807,7 +12815,7 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
12807
12815
  data: this.get('data')
12808
12816
  }
12809
12817
  },
12810
- dataType: 'json',
12818
+ dataType: dataType,
12811
12819
  success: function(data, textStatus, jqXHR) {
12812
12820
  return dfr.resolve(data);
12813
12821
  },
@@ -13184,6 +13192,8 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13184
13192
  Smalruby.MainMenuView = Backbone.View.extend({
13185
13193
  el: '#main-menu',
13186
13194
  events: {
13195
+ 'click #block-mode-button': 'onBlockMode',
13196
+ 'click #ruby-mode-button': 'onRubyMode',
13187
13197
  'click #run-button': 'onRun',
13188
13198
  'click #download-button': 'onDownload',
13189
13199
  'click #load-button': 'onLoad',
@@ -13214,6 +13224,7 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13214
13224
  filename = info.filename;
13215
13225
  if (filename.match(/\.xml$/)) {
13216
13226
  if (!window.blockMode) {
13227
+ window.blockMode = true;
13217
13228
  $('#tabs a[href="#block-tab"]').tab('show');
13218
13229
  }
13219
13230
  filename = filename.replace(/(\.rb)?\.xml$/, '.rb');
@@ -13224,6 +13235,7 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13224
13235
  Smalruby.Collections.CharacterSet.reset();
13225
13236
  Blockly.mainWorkspace.clear();
13226
13237
  if (window.blockMode) {
13238
+ window.blockMode = false;
13227
13239
  $('#tabs a[href="#ruby-tab"]').tab('show');
13228
13240
  window.textEditor.focus();
13229
13241
  }
@@ -13232,13 +13244,64 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13232
13244
  window.textEditor.getSession().getDocument().setValue(info.data);
13233
13245
  window.textEditor.moveCursorTo(0, 0);
13234
13246
  window.changed = false;
13247
+ Smalruby.changedAfterTranslating = true;
13235
13248
  return window.successMessage('ロードしました');
13236
13249
  }
13237
13250
  }
13238
13251
  });
13239
13252
  },
13253
+ onBlockMode: function(e) {
13254
+ var sourceCode;
13255
+ e.preventDefault();
13256
+ if (window.blockMode) {
13257
+ return;
13258
+ }
13259
+ if (!Smalruby.changedAfterTranslating) {
13260
+ window.blockMode = true;
13261
+ $('#tabs a[href="#block-tab"]').tab('show');
13262
+ return;
13263
+ }
13264
+ this.blockUI({
13265
+ title: "<i class=\"icon-filter\"></i>\nプログラムの変換中",
13266
+ message: 'プログラムをブロックに変換しています。'
13267
+ });
13268
+ sourceCode = new Smalruby.SourceCode();
13269
+ return sourceCode.toBlocks().then(function(data) {
13270
+ window.blockMode = true;
13271
+ $('#tabs a[href="#block-tab"]').tab('show');
13272
+ if (data.length > 0) {
13273
+ Smalruby.blocklyLoading = true;
13274
+ Smalruby.translating = true;
13275
+ Smalruby.loadXml(data);
13276
+ Smalruby.translating = false;
13277
+ return Smalruby.changedAfterTranslating = false;
13278
+ }
13279
+ }).then(this.unblockUI, this.unblockUI).fail(function() {
13280
+ return window.errorMessage('ブロックへの変換に失敗しました');
13281
+ });
13282
+ },
13283
+ onRubyMode: function(e) {
13284
+ var data;
13285
+ e.preventDefault();
13286
+ if (!window.blockMode) {
13287
+ return;
13288
+ }
13289
+ window.blockMode = false;
13290
+ $('#tabs a[href="#ruby-tab"]').tab('show');
13291
+ if (!Smalruby.changedAfterTranslating) {
13292
+ return;
13293
+ }
13294
+ data = Blockly.Ruby.workspaceToCode();
13295
+ Smalruby.translating = true;
13296
+ window.textEditor.getSession().getDocument().setValue(data);
13297
+ Smalruby.translating = false;
13298
+ Smalruby.changedAfterTranslating = false;
13299
+ window.textEditor.moveCursorTo(0, 0);
13300
+ return window.textEditor.focus();
13301
+ },
13240
13302
  onRun: function(e) {
13241
- var failedFunc, sourceCode;
13303
+ var errorMsg, sourceCode,
13304
+ _this = this;
13242
13305
  e.preventDefault();
13243
13306
  sourceCode = this.getSourceCode();
13244
13307
  this.blockUI({
@@ -13246,76 +13309,55 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13246
13309
  message: 'プログラムの画面に切り替えてください。',
13247
13310
  notice: "プログラムをセーブ・チェックしてから実行するよ♪<br>\nEscキーを押すとプログラムが終わります。"
13248
13311
  });
13249
- failedFunc = function() {
13250
- $.unblockUI();
13251
- return errorMessage('プログラムを実行できませんでした');
13252
- };
13253
- return sourceCode.save2().done(function(data) {
13254
- return sourceCode.write().done(function(data) {
13255
- var afterSave;
13256
- afterSave = function() {
13257
- Smalruby.savedFilename = sourceCode.get('filename');
13258
- window.changed = false;
13259
- return sourceCode.check().done(function(data) {
13260
- var errorInfo, _i, _len, _results;
13261
- if (data.length > 0) {
13262
- failedFunc();
13263
- _results = [];
13264
- for (_i = 0, _len = data.length; _i < _len; _i++) {
13265
- errorInfo = data[_i];
13266
- _results.push((function(errorInfo) {
13267
- var msg;
13268
- msg = "" + errorInfo.row + "行";
13269
- if (errorInfo.column > 0) {
13270
- msg += "、" + errorInfo.column + "文字";
13271
- }
13272
- return window.errorMessage(msg + (": " + errorInfo.message));
13273
- })(errorInfo));
13274
- }
13275
- return _results;
13276
- } else {
13277
- return sourceCode.run().done(function(data) {
13278
- var _j, _len1, _results1;
13279
- $.unblockUI();
13280
- if (data.length > 0) {
13281
- _results1 = [];
13282
- for (_j = 0, _len1 = data.length; _j < _len1; _j++) {
13283
- errorInfo = data[_j];
13284
- _results1.push((function(errorInfo) {
13285
- var msg;
13286
- msg = "" + errorInfo.row + "行";
13287
- if (errorInfo.column > 0) {
13288
- msg += "、" + errorInfo.column + "文字";
13289
- }
13290
- return errorMessage(msg + (": " + errorInfo.message));
13291
- })(errorInfo));
13292
- }
13293
- return _results1;
13294
- }
13295
- }).fail(function() {
13296
- return failedFunc();
13297
- });
13298
- }
13299
- }).fail(function() {
13300
- return failedFunc();
13301
- });
13312
+ errorMsg = 'プログラムを実行できませんでした';
13313
+ return sourceCode.save2().then(function(data) {
13314
+ return sourceCode.write();
13315
+ }).then(function(data) {
13316
+ return _this.confirmOverwrite_.call(_this, data, sourceCode, function() {
13317
+ return errorMsg = 'プログラムの実行をキャンセルしました';
13318
+ });
13319
+ }).then(function() {
13320
+ Smalruby.savedFilename = sourceCode.get('filename');
13321
+ window.changed = false;
13322
+ return sourceCode.check();
13323
+ }).then(function(data) {
13324
+ var errorInfo, _fn, _i, _len;
13325
+ if (data.length > 0) {
13326
+ _fn = function(errorInfo) {
13327
+ var msg;
13328
+ msg = "" + errorInfo.row + "行";
13329
+ if (errorInfo.column > 0) {
13330
+ msg += "、" + errorInfo.column + "文字";
13331
+ }
13332
+ return window.errorMessage(msg + (": " + errorInfo.message));
13302
13333
  };
13303
- if (data.source_code.error) {
13304
- if (sourceCode.get('filename') === Smalruby.savedFilename || confirm("前に" + (sourceCode.get('filename')) + "という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")) {
13305
- return sourceCode.write(true).done(function(data) {
13306
- return afterSave();
13307
- });
13308
- } else {
13309
- return failedFunc();
13334
+ for (_i = 0, _len = data.length; _i < _len; _i++) {
13335
+ errorInfo = data[_i];
13336
+ _fn(errorInfo);
13337
+ }
13338
+ return $.Deferred().reject().promise();
13339
+ }
13340
+ }).then(function() {
13341
+ return sourceCode.run();
13342
+ }).then(function(data) {
13343
+ var errorInfo, _fn, _i, _len;
13344
+ if (data.length > 0) {
13345
+ _fn = function(errorInfo) {
13346
+ var msg;
13347
+ msg = "" + errorInfo.row + "行";
13348
+ if (errorInfo.column > 0) {
13349
+ msg += "、" + errorInfo.column + "文字";
13310
13350
  }
13311
- } else {
13312
- return afterSave();
13351
+ return errorMessage(msg + (": " + errorInfo.message));
13352
+ };
13353
+ for (_i = 0, _len = data.length; _i < _len; _i++) {
13354
+ errorInfo = data[_i];
13355
+ _fn(errorInfo);
13313
13356
  }
13314
- }).fail(function() {
13315
- return failedFunc();
13316
- });
13317
- }).fail(function() {
13318
- return failedFunc();
13357
+ return $.Deferred().reject().promise();
13358
+ }
13359
+ }).then(this.unblockUI, this.unblockUI).fail(function() {
13360
+ return errorMessage(errorMsg);
13319
13361
  });
13320
13362
  },
13321
13363
  onDownload: function(e) {
@@ -13327,14 +13369,12 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13327
13369
  message: 'プログラムをダウンロードしています。',
13328
13370
  notice: "ダウンロードしたプログラムは、<br>\nWindowsだと「ruby " + (sourceCode.get('filename')) + "」、<br>\nMacだと「rsdl " + (sourceCode.get('filename')) + "」で実行できます。"
13329
13371
  });
13330
- return sourceCode.save2().done(function(data) {
13331
- $.unblockUI();
13372
+ return sourceCode.save2().then(function(data) {
13332
13373
  window.changed = false;
13333
13374
  window.successMessage('ダウンロードしました');
13334
13375
  Smalruby.downloading = true;
13335
13376
  return $('#download-link').click();
13336
- }).fail(function() {
13337
- $.unblockUI();
13377
+ }).then(this.unblockUI, this.unblockUI).fail(function() {
13338
13378
  return window.errorMessage('ダウンロードできませんでした');
13339
13379
  });
13340
13380
  },
@@ -13348,7 +13388,8 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13348
13388
  return $('input#load-file[name="source_code[file]"]').click();
13349
13389
  },
13350
13390
  onSave: function(e) {
13351
- var failedFunc, filename, sourceCode;
13391
+ var errorMsg, filename, sourceCode,
13392
+ _this = this;
13352
13393
  e.preventDefault();
13353
13394
  filename = $.trim($('#filename').val());
13354
13395
  if (filename.length <= 0) {
@@ -13371,36 +13412,19 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13371
13412
  message: 'プログラムをセーブしています。',
13372
13413
  notice: "プログラムの名前は「" + (sourceCode.get('filename')) + "」です。<br>\nプログラムはホームディレクトリにセーブします。<br>"
13373
13414
  });
13374
- failedFunc = function() {
13375
- $.unblockUI();
13376
- return window.errorMessage('セーブできませんでした');
13377
- };
13378
- return sourceCode.save2().done(function(data) {
13379
- return sourceCode.write().done(function(data) {
13380
- var afterSave;
13381
- afterSave = function() {
13382
- $.unblockUI();
13383
- Smalruby.savedFilename = sourceCode.get('filename');
13384
- window.changed = false;
13385
- return window.successMessage('セーブしました');
13386
- };
13387
- if (data.source_code.error) {
13388
- if (sourceCode.get('filename') === Smalruby.savedFilename || confirm("前に" + (sourceCode.get('filename')) + "という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")) {
13389
- return sourceCode.write(true).done(function(data) {
13390
- return afterSave();
13391
- });
13392
- } else {
13393
- $.unblockUI();
13394
- return window.successMessage('セーブをキャンセルしました');
13395
- }
13396
- } else {
13397
- return afterSave();
13398
- }
13399
- }).fail(function() {
13400
- return failedFunc();
13415
+ errorMsg = 'セーブできませんでした';
13416
+ return sourceCode.save2().then(function(data) {
13417
+ return sourceCode.write();
13418
+ }).then(function(data) {
13419
+ return _this.confirmOverwrite_.call(_this, data, sourceCode, function() {
13420
+ return errorMsg = 'セーブをキャンセルしました';
13401
13421
  });
13422
+ }).then(this.unblockUI, this.unblockUI).done(function() {
13423
+ Smalruby.savedFilename = sourceCode.get('filename');
13424
+ window.changed = false;
13425
+ return window.successMessage('セーブしました');
13402
13426
  }).fail(function() {
13403
- return failedFunc();
13427
+ return window.errorMessage(errorMsg);
13404
13428
  });
13405
13429
  },
13406
13430
  onCheck: function(e) {
@@ -13412,9 +13436,8 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13412
13436
  message: 'プログラムの文法をチェックしています。',
13413
13437
  notice: "このチェックは簡易的なものですので、<br>\nプログラムを動かすとエラーが見つかるかもしれません。"
13414
13438
  });
13415
- return sourceCode.check().done(function(data) {
13439
+ return sourceCode.check().then(function(data) {
13416
13440
  var errorInfo, _i, _len, _results;
13417
- $.unblockUI();
13418
13441
  if (data.length === 0) {
13419
13442
  return window.successMessage('チェックしました', 'ただし、プログラムを動かすとエラーが見つかるかもしれません。');
13420
13443
  } else {
@@ -13432,8 +13455,7 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13432
13455
  }
13433
13456
  return _results;
13434
13457
  }
13435
- }).fail(function() {
13436
- $.unblockUI();
13458
+ }).then(this.unblockUI, this.unblockUI).fail(function() {
13437
13459
  return errorMessage('チェックできませんでした');
13438
13460
  });
13439
13461
  },
@@ -13451,14 +13473,45 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE;
13451
13473
  return sourceCode;
13452
13474
  },
13453
13475
  blockUI: function(options) {
13476
+ var message, part;
13477
+ message = '';
13478
+ if (options.title) {
13479
+ message += "<h3>\n " + options.title + "\n</h3>";
13480
+ }
13481
+ if (options.message || options.notice) {
13482
+ part = '';
13483
+ if (options.message) {
13484
+ part += "<p>\n " + options.message + "\n</p>";
13485
+ }
13486
+ if (options.notice) {
13487
+ part += "<small>\n " + options.notice + "\n</small>";
13488
+ }
13489
+ message += "<blockquote>\n " + part + "\n</blockquote>";
13490
+ }
13454
13491
  return $.blockUI({
13455
- message: "<h3>\n " + options.title + "\n</h3>\n<blockquote>\n <p>\n " + options.message + "\n </p>\n <small>\n " + options.notice + "\n </small>\n</blockquote>",
13492
+ message: message,
13456
13493
  css: {
13457
13494
  border: 'none',
13458
13495
  'text-align': 'left',
13459
13496
  'padding-left': '2em'
13460
13497
  }
13461
13498
  });
13499
+ },
13500
+ unblockUI: function() {
13501
+ return $.unblockUI();
13502
+ },
13503
+ confirmOverwrite_: function(data, sourceCode, canceled) {
13504
+ if (canceled == null) {
13505
+ canceled = $.noop;
13506
+ }
13507
+ if (data.source_code.error) {
13508
+ if (sourceCode.get('filename') === Smalruby.savedFilename || confirm("前に" + (sourceCode.get('filename')) + "という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")) {
13509
+ return sourceCode.write(true);
13510
+ } else {
13511
+ canceled.call();
13512
+ return $.Deferred().reject().promise();
13513
+ }
13514
+ }
13462
13515
  }
13463
13516
  });
13464
13517
 
@@ -15912,23 +15965,6 @@ case end next return until\
15912
15965
  return ['volume', Blockly.Ruby.ORDER_ATOMIC];
15913
15966
  };
15914
15967
 
15915
- }).call(this);
15916
- (function() {
15917
- $(function() {
15918
- var session, textEditor;
15919
- window.textEditor = textEditor = ace.edit('text-editor');
15920
- textEditor.setTheme('ace/theme/clouds');
15921
- textEditor.setShowInvisibles(true);
15922
- textEditor.gotoLine(0, 0);
15923
- textEditor.on('change', function(e) {
15924
- return window.changed = true;
15925
- });
15926
- session = textEditor.getSession();
15927
- session.setMode('ace/mode/ruby');
15928
- session.setTabSize(2);
15929
- return session.setUseSoftTabs(true);
15930
- });
15931
-
15932
15968
  }).call(this);
15933
15969
  // This is a manifest file that'll be compiled into application.js, which will include all the files
15934
15970
  // listed below.
@@ -15965,7 +16001,6 @@ case end next return until\
15965
16001
 
15966
16002
 
15967
16003
 
15968
-
15969
16004
 
15970
16005
 
15971
16006
  ;