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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 541270ea861d18cc79f609be0ab035b2509ae55a
4
- data.tar.gz: 22ec8448c52b4c22b6d6cf1fa02d78a95da75a47
3
+ metadata.gz: 53e0d4cc07184d7d779bce31a30099140c72d191
4
+ data.tar.gz: ee93d3bd4b1a53590e2d0fb0af8d95851de81736
5
5
  SHA512:
6
- metadata.gz: f25ca7ea2a48da978c223198e7780471e6a06f1c48af12924d7105e0d63f7debdc521bd5232d16ac7ffeaaa623d90f8eff7987f349f9a8be9c55f29944332de6
7
- data.tar.gz: ee108b11160c979eedede301dcf2c25ec8083ad8bf6e390c59c8f7ccb041bc141f59b85216f5dced272c891129b87280fa5ada955c9891b0fd64c955e89b29e7
6
+ metadata.gz: 998812bd17c0f42e82fac22a223219082807267f674e06158c50365ae88d1d325efd7f6a0a8364d6ca80ac4839708d7892201e2a94201cb46ad2016097b9a869
7
+ data.tar.gz: 540eb8e5125b96e2ae2ae8f2500dc2b76a9ef6d541e0a51efc7d63ce9c8b73abdbbbcb9575da2d0d69c47a4fdb8f5907023c0099388ff02febfbf32bbfe8eaff
data/.gitignore CHANGED
@@ -22,4 +22,5 @@
22
22
  /.env
23
23
  /coverage
24
24
  /pkg
25
- /features
25
+ /features
26
+ /demos/*.xml
data/.rubocop.yml CHANGED
@@ -22,3 +22,11 @@ EndOfLine:
22
22
  # diffが少なくなるためハッシュや配列の最後のカンマは許可する
23
23
  TrailingComma:
24
24
  Enabled: false
25
+
26
+ # デフォルトの10は短すぎる。80x25を基準として1画面に収まる長さとした。
27
+ MethodLength:
28
+ Max: 25
29
+
30
+ # デフォルトの100は短すぎる。なんとなく250行とした。
31
+ ClassLength:
32
+ Max: 250
data/README.rdoc CHANGED
@@ -8,6 +8,9 @@
8
8
 
9
9
  The smalruby-editor is a visual programming editor that can create a Ruby script by combining individual blocks similar to Scratch. It can also enter the program as better than Scratch.
10
10
 
11
+ * DEMO: http://smalruby.herokuapp.com/demo/
12
+ * DEMO(Arduino): http://smalruby.herokuapp.com/demo/rgb_led_anode/
13
+
11
14
  The smalruby-editor is a part of the Smalruby Project.
12
15
 
13
16
  The Smalruby(smɔ́ːrúːbi) Project will provide a Ruby learning environment for middle school students from the upper grades of elementary school. The goal of this project is to achieve software and community sites such as the {Scratch}[http://scratch.mit.edu/] in Ruby. The Scratch has experience as educational programming environment can be used in elementary school. This project consists of the following elements.
@@ -35,4 +35,3 @@
35
35
  //= require_tree ./generators
36
36
  //= require ./blocks/field_character
37
37
  //= require_tree ./blocks
38
- //= require ./ruby_mode
@@ -39,7 +39,10 @@ Smalruby.SourceCode = Backbone.Model.extend
39
39
  action += '?force=1' if force
40
40
  @delete_(action)
41
41
 
42
- post_: (action) ->
42
+ toBlocks: ->
43
+ @post_('to_blocks', 'html')
44
+
45
+ post_: (action, dataType = 'json') ->
43
46
  dfr = $.Deferred()
44
47
  $.ajax
45
48
  url: "/source_codes/#{action}"
@@ -48,7 +51,7 @@ Smalruby.SourceCode = Backbone.Model.extend
48
51
  source_code:
49
52
  filename: @get('filename')
50
53
  data: @get('data')
51
- dataType: 'json'
54
+ dataType: dataType
52
55
  success: (data, textStatus, jqXHR) -> dfr.resolve(data)
53
56
  error: dfr.reject
54
57
  dfr.promise()
@@ -11,6 +11,7 @@ window.successMessage = (title, msg = '', selector = '#messages') ->
11
11
  html.fadeIn('slow')
12
12
  .delay(3000)
13
13
  .fadeOut('slow')
14
+ return
14
15
 
15
16
  window.errorMessage = (msg, selector = '#messages') ->
16
17
  html = $('<div class="alert alert-error" style="display: none">')
@@ -19,6 +20,7 @@ window.errorMessage = (msg, selector = '#messages') ->
19
20
  .append(msg)
20
21
  $(selector).append(html)
21
22
  html.fadeIn('slow')
23
+ return
22
24
 
23
25
  window.Smalruby =
24
26
  Models: {}
@@ -43,17 +45,6 @@ window.Smalruby =
43
45
  @Views.CharacterModalView = new Smalruby.CharacterModalView
44
46
  el: $('#character-modal')
45
47
 
46
- $('a[data-toggle="tab"]').on 'shown', (e) ->
47
- if $(e.target).attr('href') == '#block-tab'
48
- window.blockMode = true
49
- else
50
- window.blockMode = false
51
- data = Blockly.Ruby.workspaceToCode()
52
- if $.trim(data).length > 0
53
- window.textEditor.getSession().getDocument().setValue(data)
54
- window.textEditor.moveCursorTo(0, 0)
55
- window.textEditor.focus()
56
-
57
48
  Smalruby.downloading = false
58
49
  window.onbeforeunload = (event) ->
59
50
  if !Smalruby.downloading && window.changed
@@ -75,6 +66,8 @@ window.Smalruby =
75
66
  @blocklyFirst = true
76
67
  @blocklyLoading = false
77
68
  Blockly.addChangeListener =>
69
+ Smalruby.changedAfterTranslating = true
70
+
78
71
  # HACK: Blocklyを初期化後に一回だけChangeListenerが呼び出させれ
79
72
  # る。ここではそれを無視している。
80
73
  if @blocklyFirst
@@ -89,6 +82,20 @@ window.Smalruby =
89
82
 
90
83
  window.changed = true
91
84
 
85
+ window.textEditor = textEditor = ace.edit('text-editor')
86
+ textEditor.setTheme('ace/theme/clouds')
87
+ textEditor.setShowInvisibles(true)
88
+ textEditor.gotoLine(0, 0)
89
+ textEditor.on 'change', (e) =>
90
+ unless @translating
91
+ window.changed = true
92
+ Smalruby.changedAfterTranslating = true
93
+
94
+ session = textEditor.getSession()
95
+ session.setMode('ace/mode/ruby')
96
+ session.setTabSize(2)
97
+ session.setUseSoftTabs(true)
98
+
92
99
  loadXml: (data, workspace = Blockly.mainWorkspace) ->
93
100
  xml = Blockly.Xml.textToDom(data)
94
101
  workspace.clear()
@@ -3,6 +3,8 @@ Smalruby.MainMenuView = Backbone.View.extend
3
3
  el: '#main-menu'
4
4
 
5
5
  events:
6
+ 'click #block-mode-button': 'onBlockMode'
7
+ 'click #ruby-mode-button': 'onRubyMode'
6
8
  'click #run-button': 'onRun'
7
9
  'click #download-button': 'onDownload'
8
10
  'click #load-button': 'onLoad'
@@ -29,6 +31,7 @@ Smalruby.MainMenuView = Backbone.View.extend
29
31
  filename = info.filename
30
32
  if filename.match(/\.xml$/)
31
33
  unless window.blockMode
34
+ window.blockMode = true
32
35
  $('#tabs a[href="#block-tab"]').tab('show')
33
36
 
34
37
  filename = filename.replace(/(\.rb)?\.xml$/, '.rb')
@@ -40,6 +43,7 @@ Smalruby.MainMenuView = Backbone.View.extend
40
43
  Blockly.mainWorkspace.clear()
41
44
 
42
45
  if window.blockMode
46
+ window.blockMode = false
43
47
  $('#tabs a[href="#ruby-tab"]').tab('show')
44
48
  window.textEditor.focus()
45
49
 
@@ -48,8 +52,60 @@ Smalruby.MainMenuView = Backbone.View.extend
48
52
  window.textEditor.moveCursorTo(0, 0)
49
53
  # TODO: window.changed -> Smalruby.Models.SourceCode.changed
50
54
  window.changed = false
55
+ Smalruby.changedAfterTranslating = true
51
56
  window.successMessage('ロードしました')
52
57
 
58
+ onBlockMode: (e) ->
59
+ e.preventDefault()
60
+
61
+ return if window.blockMode
62
+
63
+ unless Smalruby.changedAfterTranslating
64
+ window.blockMode = true
65
+ $('#tabs a[href="#block-tab"]').tab('show')
66
+ return
67
+
68
+ @blockUI
69
+ title:
70
+ """
71
+ <i class="icon-filter"></i>
72
+ プログラムの変換中
73
+ """
74
+ message: 'プログラムをブロックに変換しています。'
75
+
76
+ sourceCode = new Smalruby.SourceCode()
77
+ sourceCode.toBlocks()
78
+ .then (data) ->
79
+ window.blockMode = true
80
+ $('#tabs a[href="#block-tab"]').tab('show')
81
+ if data.length > 0
82
+ Smalruby.blocklyLoading = true
83
+ Smalruby.translating = true
84
+ Smalruby.loadXml(data)
85
+ Smalruby.translating = false
86
+ Smalruby.changedAfterTranslating = false
87
+ .then(@unblockUI, @unblockUI)
88
+ .fail ->
89
+ window.errorMessage('ブロックへの変換に失敗しました')
90
+
91
+ onRubyMode: (e) ->
92
+ e.preventDefault()
93
+
94
+ return unless window.blockMode
95
+
96
+ window.blockMode = false
97
+ $('#tabs a[href="#ruby-tab"]').tab('show')
98
+
99
+ return unless Smalruby.changedAfterTranslating
100
+
101
+ data = Blockly.Ruby.workspaceToCode()
102
+ Smalruby.translating = true
103
+ window.textEditor.getSession().getDocument().setValue(data)
104
+ Smalruby.translating = false
105
+ Smalruby.changedAfterTranslating = false
106
+ window.textEditor.moveCursorTo(0, 0)
107
+ window.textEditor.focus()
108
+
53
109
  onRun: (e) ->
54
110
  e.preventDefault()
55
111
 
@@ -68,55 +124,40 @@ Smalruby.MainMenuView = Backbone.View.extend
68
124
  Escキーを押すとプログラムが終わります。
69
125
  """
70
126
 
71
- failedFunc = ->
72
- $.unblockUI()
73
- errorMessage('プログラムを実行できませんでした')
74
-
127
+ errorMsg = 'プログラムを実行できませんでした'
75
128
  sourceCode.save2()
76
- .done (data) ->
129
+ .then (data) ->
77
130
  sourceCode.write()
78
- .done (data) ->
79
- afterSave = ->
80
- Smalruby.savedFilename = sourceCode.get('filename')
81
- window.changed = false
82
- sourceCode.check()
83
- .done (data) ->
84
- if data.length > 0
85
- failedFunc()
86
- for errorInfo in data
87
- do (errorInfo) ->
88
- msg = "#{errorInfo.row}行"
89
- if errorInfo.column > 0
90
- msg += "、#{errorInfo.column}文字"
91
- window.errorMessage(msg + ": #{errorInfo.message}")
92
- else
93
- sourceCode.run()
94
- .done (data) ->
95
- $.unblockUI()
96
- if data.length > 0
97
- for errorInfo in data
98
- do (errorInfo) ->
99
- msg = "#{errorInfo.row}行"
100
- if errorInfo.column > 0
101
- msg += "、#{errorInfo.column}文字"
102
- errorMessage(msg + ": #{errorInfo.message}")
103
-
104
- .fail -> failedFunc()
105
-
106
- .fail -> failedFunc()
107
-
108
- if data.source_code.error
109
- if sourceCode.get('filename') == Smalruby.savedFilename ||
110
- confirm("前に#{sourceCode.get('filename')}という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")
111
- sourceCode.write(true)
112
- .done (data) ->
113
- afterSave()
114
- else
115
- failedFunc()
116
- else
117
- afterSave()
118
- .fail -> failedFunc()
119
- .fail -> failedFunc()
131
+ .then (data) =>
132
+ @confirmOverwrite_.call @, data, sourceCode, ->
133
+ errorMsg = 'プログラムの実行をキャンセルしました'
134
+ .then ->
135
+ Smalruby.savedFilename = sourceCode.get('filename')
136
+ window.changed = false
137
+ sourceCode.check()
138
+ .then (data) ->
139
+ if data.length > 0
140
+ for errorInfo in data
141
+ do (errorInfo) ->
142
+ msg = "#{errorInfo.row}行"
143
+ if errorInfo.column > 0
144
+ msg += "、#{errorInfo.column}文字"
145
+ window.errorMessage(msg + ": #{errorInfo.message}")
146
+ $.Deferred().reject().promise()
147
+ .then ->
148
+ sourceCode.run()
149
+ .then (data) ->
150
+ if data.length > 0
151
+ for errorInfo in data
152
+ do (errorInfo) ->
153
+ msg = "#{errorInfo.row}行"
154
+ if errorInfo.column > 0
155
+ msg += "、#{errorInfo.column}文字"
156
+ errorMessage(msg + ": #{errorInfo.message}")
157
+ $.Deferred().reject().promise()
158
+ .then(@unblockUI, @unblockUI)
159
+ .fail ->
160
+ errorMessage(errorMsg)
120
161
 
121
162
  onDownload: (e) ->
122
163
  e.preventDefault()
@@ -137,14 +178,13 @@ Smalruby.MainMenuView = Backbone.View.extend
137
178
  """
138
179
 
139
180
  sourceCode.save2()
140
- .done (data) ->
141
- $.unblockUI()
181
+ .then (data) ->
142
182
  window.changed = false
143
183
  window.successMessage('ダウンロードしました')
144
184
  Smalruby.downloading = true
145
185
  $('#download-link').click()
186
+ .then(@unblockUI, @unblockUI)
146
187
  .fail ->
147
- $.unblockUI()
148
188
  window.errorMessage('ダウンロードできませんでした')
149
189
 
150
190
  onLoad: (e) ->
@@ -182,33 +222,20 @@ Smalruby.MainMenuView = Backbone.View.extend
182
222
  プログラムはホームディレクトリにセーブします。<br>
183
223
  """
184
224
 
185
- failedFunc = ->
186
- $.unblockUI()
187
- window.errorMessage('セーブできませんでした')
188
-
225
+ errorMsg = 'セーブできませんでした'
189
226
  sourceCode.save2()
190
- .done (data) ->
227
+ .then (data) ->
191
228
  sourceCode.write()
192
- .done (data) ->
193
- afterSave = ->
194
- $.unblockUI()
195
- Smalruby.savedFilename = sourceCode.get('filename')
196
- window.changed = false
197
- window.successMessage('セーブしました')
198
-
199
- if data.source_code.error
200
- if sourceCode.get('filename') == Smalruby.savedFilename ||
201
- confirm("前に#{sourceCode.get('filename')}という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")
202
- sourceCode.write(true)
203
- .done (data) ->
204
- afterSave()
205
- else
206
- $.unblockUI()
207
- window.successMessage('セーブをキャンセルしました')
208
- else
209
- afterSave()
210
- .fail -> failedFunc()
211
- .fail -> failedFunc()
229
+ .then (data) =>
230
+ @confirmOverwrite_.call @, data, sourceCode, ->
231
+ errorMsg = 'セーブをキャンセルしました'
232
+ .then(@unblockUI, @unblockUI)
233
+ .done ->
234
+ Smalruby.savedFilename = sourceCode.get('filename')
235
+ window.changed = false
236
+ window.successMessage('セーブしました')
237
+ .fail ->
238
+ window.errorMessage(errorMsg)
212
239
 
213
240
  onCheck: (e) ->
214
241
  e.preventDefault()
@@ -230,8 +257,7 @@ Smalruby.MainMenuView = Backbone.View.extend
230
257
  """
231
258
 
232
259
  sourceCode.check()
233
- .done (data) ->
234
- $.unblockUI()
260
+ .then (data) ->
235
261
  if data.length == 0
236
262
  window.successMessage('チェックしました', 'ただし、プログラムを動かすとエラーが見つかるかもしれません。')
237
263
  else
@@ -241,8 +267,8 @@ Smalruby.MainMenuView = Backbone.View.extend
241
267
  if errorInfo.column > 0
242
268
  msg += "、#{errorInfo.column}文字"
243
269
  window.errorMessage(msg + ": #{errorInfo.message}")
270
+ .then(@unblockUI, @unblockUI)
244
271
  .fail ->
245
- $.unblockUI()
246
272
  errorMessage('チェックできませんでした')
247
273
 
248
274
  onReset: (e) ->
@@ -259,22 +285,54 @@ Smalruby.MainMenuView = Backbone.View.extend
259
285
  sourceCode
260
286
 
261
287
  blockUI: (options) ->
262
- $.blockUI
263
- message:
288
+ message = ''
289
+ if options.title
290
+ message +=
264
291
  """
265
292
  <h3>
266
293
  #{options.title}
267
294
  </h3>
268
- <blockquote>
295
+ """
296
+
297
+ if options.message || options.notice
298
+ part = ''
299
+ if options.message
300
+ part +=
301
+ """
269
302
  <p>
270
303
  #{options.message}
271
304
  </p>
305
+ """
306
+ if options.notice
307
+ part +=
308
+ """
272
309
  <small>
273
310
  #{options.notice}
274
311
  </small>
312
+ """
313
+
314
+ message +=
315
+ """
316
+ <blockquote>
317
+ #{part}
275
318
  </blockquote>
276
319
  """
320
+
321
+ $.blockUI
322
+ message: message
277
323
  css:
278
324
  border: 'none'
279
325
  'text-align': 'left'
280
326
  'padding-left': '2em'
327
+
328
+ unblockUI: ->
329
+ $.unblockUI()
330
+
331
+ confirmOverwrite_: (data, sourceCode, canceled = $.noop) ->
332
+ if data.source_code.error
333
+ if sourceCode.get('filename') == Smalruby.savedFilename ||
334
+ confirm("前に#{sourceCode.get('filename')}という名前でセーブしているけど本当にセーブしますか?\nセーブすると前に作成したプログラムは消えてしまうよ!")
335
+ sourceCode.write(true)
336
+ else
337
+ canceled.call()
338
+ $.Deferred().reject().promise()
@@ -57,6 +57,13 @@ class SourceCodesController < ApplicationController
57
57
  render json: source_code.run(path)
58
58
  end
59
59
 
60
+ def to_blocks
61
+ source_code = SourceCode.new(source_code_params)
62
+ render text: source_code.to_blocks
63
+ rescue
64
+ head :bad_request
65
+ end
66
+
60
67
  private
61
68
 
62
69
  def check_whether_standalone