smalruby-editor 0.2.6 → 0.2.7

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/Guardfile +2 -0
  4. data/app/assets/javascripts/blocks/hardware.js.coffee.erb +1 -1
  5. data/app/assets/javascripts/fix_blockly.js.erb +0 -50
  6. data/app/assets/javascripts/generators/ruby.js.coffee.erb +18 -4
  7. data/app/assets/javascripts/models/source_code.js +1 -1
  8. data/app/assets/javascripts/msg/en_us.js +1 -0
  9. data/app/assets/javascripts/msg/ja.js +4 -0
  10. data/app/assets/javascripts/smalruby.js.coffee.erb +50 -6
  11. data/app/assets/javascripts/views/main_menu_view.js.coffee.erb +14 -4
  12. data/app/assets/javascripts/views/preference_modal_view.js.coffee.erb +71 -0
  13. data/app/assets/javascripts/views/signin_modal_view.js.coffee.erb +5 -4
  14. data/app/assets/stylesheets/application.css +1 -0
  15. data/app/assets/stylesheets/preference-modal.css.scss +22 -0
  16. data/app/assets/stylesheets/toolbox.css.scss.erb +36 -0
  17. data/app/controllers/application_controller.rb +20 -4
  18. data/app/controllers/editor_controller.rb +4 -0
  19. data/app/controllers/sessions_controller.rb +7 -4
  20. data/app/controllers/source_codes_controller.rb +2 -2
  21. data/app/controllers/users_controller.rb +22 -0
  22. data/app/helpers/application_helper.rb +4 -4
  23. data/app/helpers/sessions_helper.rb +0 -0
  24. data/app/helpers/users_helper.rb +10 -0
  25. data/app/models/concerns/ruby_to_block/block/hardware_init_hardware.rb +0 -6
  26. data/app/models/concerns/ruby_to_block/block/hardware_operation.rb +0 -0
  27. data/app/models/preference.rb +71 -0
  28. data/app/models/source_code.rb +4 -0
  29. data/app/models/user.rb +26 -0
  30. data/app/views/editor/_block_tab.html.haml +5 -6
  31. data/app/views/editor/_load_modal.html.haml +2 -2
  32. data/app/views/editor/_preference_modal.html.haml +16 -0
  33. data/app/views/editor/_signin_modal.html.haml +1 -1
  34. data/app/views/editor/_toolbox_default.html.haml +86 -79
  35. data/app/views/editor/{_toolbox_raspberrypi.html.haml → _toolbox_smalrubot.html.haml} +72 -105
  36. data/app/views/editor/_toolbox_smalrubot_s1.html.haml +1 -196
  37. data/app/views/editor/_toolbox_smalrubot_v3.html.haml +1 -196
  38. data/app/views/editor/index.html.haml +11 -4
  39. data/app/views/editor/toolbox.html.haml +1 -0
  40. data/app/views/layouts/application.html.erb +1 -1
  41. data/app/views/users/preferences.html.haml +34 -0
  42. data/config/application.rb +1 -1
  43. data/config/locales/en.yml +30 -0
  44. data/config/locales/ja.yml +30 -0
  45. data/config/routes.rb +4 -57
  46. data/db/migrate/20150513061200_create_users.rb +10 -0
  47. data/db/migrate/20150513061250_add_index_name_on_users.rb +9 -0
  48. data/db/schema.rb +10 -1
  49. data/lib/smalruby_editor.rb +22 -24
  50. data/lib/smalruby_editor/version.rb +1 -1
  51. data/smalruby-editor.gemspec +0 -0
  52. data/spec/acceptance/block_mode/blocks/hardware/button_pressed_or_released.feature +2 -0
  53. data/spec/acceptance/block_mode/blocks/hardware/init_hardware.feature +1 -0
  54. data/spec/acceptance/block_mode/blocks/hardware/led_turn_off.feature +11 -1
  55. data/spec/acceptance/block_mode/blocks/hardware/led_turn_on.feature +11 -1
  56. data/spec/acceptance/block_mode/blocks/hardware/motor_driver.feature +7 -1
  57. data/spec/acceptance/block_mode/blocks/hardware/motor_driver_speed.feature +2 -0
  58. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_set_color.feature +9 -12
  59. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_turn_off.feature +9 -12
  60. data/spec/acceptance/block_mode/blocks/hardware/sensor_value.feature +59 -60
  61. data/spec/acceptance/block_mode/blocks/hardware/servo_set_position.feature +76 -67
  62. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action.feature +9 -12
  63. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action_with_sec.feature +9 -11
  64. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_dc_motor_power_ratio.feature +11 -12
  65. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_led_turn_on_or_off.feature +9 -10
  66. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_action.feature +9 -12
  67. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_action_with_sec.feature +9 -11
  68. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_dc_motor_power_ratio.feature +11 -12
  69. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_led_turn_on_or_off.feature +9 -12
  70. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_sensor_value.feature +11 -12
  71. data/spec/acceptance/block_mode/blocks/hardware/two_wheel_drive_car.feature +7 -1
  72. data/spec/acceptance/block_mode/blocks/hardware/two_wheel_drive_car_speed.feature +2 -0
  73. data/spec/acceptance/standalone/preference.feature +92 -0
  74. data/{demos → spec/fixtures/files}/hardware_led.rb.xml +0 -0
  75. data/spec/javascripts/models/source_code_spec.coffee +0 -0
  76. data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_spec.rb +1 -1
  77. data/spec/models/concerns/ruby_to_block/block/hardware_spec.rb +4 -4
  78. data/spec/models/concerns/ruby_to_block_spec.rb +1 -1
  79. data/spec/models/source_code_spec.rb +1 -11
  80. data/spec/spec_helper.rb +8 -0
  81. data/spec/steps/base_steps.rb +68 -16
  82. data/spec/steps/standalone_steps.rb +21 -0
  83. data/spec/steps/text_editor_steps.rb +8 -8
  84. data/spec/support/feature_helper.rb +13 -0
  85. data/vendor/assets/javascripts/blockly/blockly_compressed.js +500 -454
  86. data/vendor/assets/javascripts/blockly/blocks_compressed.js +29 -28
  87. data/vendor/assets/javascripts/blockly/msg/js/ja.js +2 -1
  88. metadata +33 -35
  89. data/app/assets/stylesheets/toolbox_default.css.scss.erb +0 -34
  90. data/app/assets/stylesheets/toolbox_raspberrypi.css.scss.erb +0 -32
  91. data/app/assets/stylesheets/toolbox_smalrubot_s1.css.scss.erb +0 -32
  92. data/app/assets/stylesheets/toolbox_smalrubot_v3.css.scss.erb +0 -32
  93. data/demos/adjust_2wd_car.rb.xml +0 -179
  94. data/lib/smalruby_editor/config.rb +0 -24
  95. data/spec/controllers/editor_controller_spec.rb +0 -12
  96. data/spec/controllers/sessions_controller_spec.rb +0 -74
  97. data/spec/helpers/sessions_helper_spec.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5dc5fd46f72f8d91777651c0d1bab6a18f0924a
4
- data.tar.gz: e972a58159028440ddc4709ee8a0380c0a7b1c5c
3
+ metadata.gz: 7475705f672af7bdf0ae1d5d7fae0d60e5c6ffe4
4
+ data.tar.gz: 1a94cb91a5f3261a4ccf5b5d2876383383741663
5
5
  SHA512:
6
- metadata.gz: fc5e7ffce2c09adc51ed375bdf699698c6343515b1eab4d9d693edf5a92d76e218632a63033107def592ff403a323b69cf4dba4b82bc89b3f8fbe2b63ead7e12
7
- data.tar.gz: edaf6636f4f190927e88692ae0101dbe3a31961d98bf69331fae0503fe6eefc0dcf9d9a4c55014b313c46bc88a3414a31aa6432b61d35d5ec3caba0b99b3ca8a
6
+ metadata.gz: 76404a2cf32c9d830171f5fb6c0abe7c8ae709b89002657f394ea4e65cd742611ec8dd266f7306c2210496d5f77ba6380296580826c39aace1b68df762121cfe
7
+ data.tar.gz: 38fc58bf421edc7dc4f68f839f11e7abd9fba5f2d8f1a7bb3fe600bc8a038221f081913e23c4566d7a940314c1d6f3378c08e5ab22dc795adeba92c37c42922a
data/.rubocop.yml CHANGED
@@ -5,6 +5,7 @@ AllCops:
5
5
  - spec/fixtures/**
6
6
  - vendor/*
7
7
  - work/*
8
+ RunRailsCops: true
8
9
 
9
10
  # 日本語でのコメントを許可する
10
11
  AsciiComments:
@@ -45,3 +46,7 @@ IfUnlessModifier:
45
46
  # this is not important for me.
46
47
  StringLiterals:
47
48
  Enabled: false
49
+
50
+ # I think 'unless' is too bad.
51
+ FavorUnlessOverNegatedIf:
52
+ Enabled: false
data/Guardfile CHANGED
@@ -13,6 +13,8 @@ ignore(TEMPFILE_BY_EMACS)
13
13
 
14
14
  group :red_green_refactor, halt_on_fail: true do
15
15
  guard :rubocop, all_on_start: false do
16
+ ignore(%r{^db/(?:schema|seeds)\.rb$})
17
+
16
18
  watch(%r{.+\.rb$})
17
19
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
18
20
  end
@@ -66,7 +66,7 @@ Blockly.Blocks['<%= n %>'] =
66
66
  @setTooltip('')
67
67
 
68
68
  Blockly.Ruby['<%= n %>'] = (block) ->
69
- Blockly.Ruby.definitions_['init_hardware'] = 'init_hardware'
69
+ Blockly.Ruby.definitions_['prepare__init_hardware'] = 'init_hardware'
70
70
  ''
71
71
 
72
72
  # 「LED」サブジャンル
@@ -36,56 +36,6 @@ Blockly.Toolbox.TreeNode.prototype.onMouseDown = function(e) {
36
36
  Blockly.Blocks.math.HUE = <%= SmalrubyEditor::COLORS[:operators] %>;
37
37
  Blockly.Blocks.texts.HUE = <%= SmalrubyEditor::COLORS[:operators] %>;
38
38
 
39
- // blockly/core/field_textinput.js
40
- Blockly.FieldTextInput.prototype.showEditorOrig_ =
41
- Blockly.FieldTextInput.prototype.showEditor_;
42
- Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
43
- Blockly.FieldTextInput.prototype.showEditorOrig_.apply(this, arguments);
44
- var htmlInput = Blockly.FieldTextInput.htmlInput_;
45
- htmlInput.onKeyDownWrapper_ =
46
- Blockly.bindEvent_(htmlInput, 'keydown', this, this.onHtmlInputChange2_);
47
- };
48
-
49
- Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(e) {
50
- var htmlInput = Blockly.FieldTextInput.htmlInput_;
51
- if (e.keyCode != 27) {
52
- // Update source block.
53
- var text = htmlInput.value;
54
- if (text !== htmlInput.oldValue_) {
55
- htmlInput.oldValue_ = text;
56
- this.setText(text);
57
- this.validate_();
58
- } else if (goog.userAgent.WEBKIT) {
59
- // Cursor key. Render the source block to show the caret moving.
60
- // Chrome only (version 26, OS X).
61
- this.sourceBlock_.render();
62
- }
63
- }
64
- };
65
-
66
- Blockly.FieldTextInput.prototype.onHtmlInputChange2_ = function(e) {
67
- var htmlInput = Blockly.FieldTextInput.htmlInput_;
68
- if (e.keyCode == 13) {
69
- // Enter
70
- Blockly.WidgetDiv.hide();
71
- } else if (e.keyCode == 27) {
72
- // Esc
73
- this.setText(htmlInput.defaultValue);
74
- Blockly.WidgetDiv.hide();
75
- }
76
- };
77
-
78
- Blockly.FieldTextInput.prototype.widgetDisposeOrig_ =
79
- Blockly.FieldTextInput.prototype.widgetDispose_;
80
- Blockly.FieldTextInput.prototype.widgetDispose_ = function() {
81
- var thisField = this;
82
- return function() {
83
- Blockly.FieldTextInput.prototype.widgetDisposeOrig_.call(thisField);
84
- var htmlInput = Blockly.FieldTextInput.htmlInput_;
85
- Blockly.unbindEvent_(htmlInput.onKeyDownWrapper_);
86
- };
87
- };
88
-
89
39
  // blockly/core/names.js
90
40
  Blockly.Names.prototype.safeName_ = function(name) {
91
41
  if (!name) {
@@ -47,11 +47,11 @@ Blockly.Ruby.init = ->
47
47
  else
48
48
  @variableDB_.reset()
49
49
 
50
- @definitions_['require_smalruby'] = 'require "smalruby"'
50
+ @definitions_['require__smalruby'] = 'require "smalruby"'
51
51
  @definitions_['receiver_stack'] = ['main']
52
52
  @definitions_['character_stack'] = []
53
53
 
54
- if Smalruby.isEnabled('auto_init_hardware')
54
+ if Smalruby.isEnabled('enabled_auto_init_hardware')
55
55
  @definitions_['init_hardware'] = 'init_hardware'
56
56
 
57
57
  Blockly.Ruby.defineCharacter = (c) ->
@@ -154,23 +154,31 @@ Blockly.Ruby.characterEvent_ = (block, bodyName, name, arg = null) ->
154
154
 
155
155
  Blockly.Ruby.finish = (code) ->
156
156
  requires = []
157
+ prepares = []
157
158
  definitions = []
158
159
  for name of Blockly.Ruby.definitions_
159
160
  do (name) ->
160
161
  def = Blockly.Ruby.definitions_[name]
161
162
  if _.isString(def)
162
- if def.match(/^require\s*('\S+'|"\S+")/)
163
+ if name.match(/^require__/)
163
164
  requires.push(def)
165
+ else if name.match(/^prepare__/)
166
+ prepares.push(def)
164
167
  else
165
168
  definitions.push(def)
166
169
 
167
- if definitions.length == 0 && code.length == 0
170
+ if prepares.length == 0 && definitions.length == 0 && code.length == 0
168
171
  return ''
169
172
 
170
173
  allDefs = requires.join('\n') + '\n\n'
174
+
175
+ if prepares.length > 0
176
+ allDefs += prepares.join('\n') + '\n\n'
177
+
171
178
  if definitions.length > 0
172
179
  allDefs += definitions.join('\n')
173
180
  .replace(/\n\n+/g, '\n\n').replace(/\n*$/, '\n')
181
+
174
182
  allDefs + code
175
183
 
176
184
  Blockly.Ruby.scrubNakedValue = (line) ->
@@ -213,3 +221,9 @@ Blockly.Ruby.scrub_ = (block, code) ->
213
221
  nextBlock = block.nextConnection && block.nextConnection.targetBlock()
214
222
  nextCode = this.blockToCode(nextBlock)
215
223
  commentCode + code + nextCode
224
+
225
+ Blockly.Ruby.blockToCode_ = Blockly.Ruby.blockToCode
226
+ Blockly.Ruby.blockToCode = (block) ->
227
+ if block && !block.disabled && block.type.match(/^hardware_/)
228
+ @definitions_['prepare__init_hardware'] = 'init_hardware'
229
+ @blockToCode_(block)
@@ -22,7 +22,7 @@ Smalruby.SourceCode = Backbone.Model.extend({
22
22
  }
23
23
  else {
24
24
  if (window.blockMode) {
25
- var data = Blockly.Ruby.workspaceToCode();
25
+ var data = Blockly.Ruby.workspaceToCode(Blockly.getMainWorkspace());
26
26
  }
27
27
  else {
28
28
  var data = window.textEditor.getSession().getDocument().getValue();
@@ -17,6 +17,7 @@ Blockly.Msg.COMMON_TURN_LEFT = 'turn left';
17
17
  Blockly.Msg.COMMON_TURN_RIGHT = 'turn right';
18
18
  Blockly.Msg.COMMON_STOP = 'stop';
19
19
  Blockly.Msg.COMMON_ERROR = 'Error';
20
+ Blockly.Msg.COMMON_PROCESSING = 'Processing...';
20
21
 
21
22
 
22
23
  // colour name
@@ -8,6 +8,9 @@ goog.require('Blockly.Msg');
8
8
  * to message files.
9
9
  */
10
10
 
11
+ // fixed original messages
12
+ Blockly.Msg.DUPLICATE_BLOCK = "コピー";
13
+
11
14
  // common
12
15
  Blockly.Msg.COMMON_TURN_ON = 'オンにする';
13
16
  Blockly.Msg.COMMON_TURN_OFF = 'オフにする';
@@ -17,6 +20,7 @@ Blockly.Msg.COMMON_TURN_LEFT = '左に曲げる';
17
20
  Blockly.Msg.COMMON_TURN_RIGHT = '右に曲げる';
18
21
  Blockly.Msg.COMMON_STOP = '止める';
19
22
  Blockly.Msg.COMMON_ERROR = 'エラー';
23
+ Blockly.Msg.COMMON_PROCESSING = '処理中...';
20
24
 
21
25
 
22
26
  // colour name
@@ -35,7 +35,7 @@ window.Smalruby =
35
35
  Collections: {}
36
36
  Views: {}
37
37
  Routers: {}
38
- Features: []
38
+ Preferences: {}
39
39
 
40
40
  username: null
41
41
 
@@ -66,6 +66,8 @@ window.Smalruby =
66
66
  el: $('#load-modal')
67
67
  @Views.ResetModalView = new Smalruby.ResetModalView
68
68
  el: $('#reset-modal')
69
+ @Views.PreferenceModalView = new Smalruby.PreferenceModalView
70
+ el: $('#preference-modal')
69
71
 
70
72
  Smalruby.downloading = false
71
73
  window.onbeforeunload = (event) ->
@@ -82,10 +84,13 @@ window.Smalruby =
82
84
  path: '/blockly/'
83
85
  toolbox: document.getElementById('toolbox')
84
86
  trashcan: true
87
+ comments: false
88
+
89
+ @hideEmptyCategory()
85
90
 
86
91
  @blocklyFirst = true
87
92
  @blocklyLoading = false
88
- Blockly.addChangeListener =>
93
+ Blockly.getMainWorkspace().addChangeListener =>
89
94
  Smalruby.changedAfterTranslating = true
90
95
 
91
96
  # HACK: Blocklyを初期化後に一回だけChangeListenerが呼び出させれ
@@ -106,7 +111,6 @@ window.Smalruby =
106
111
  textEditor.setTheme('ace/theme/clouds')
107
112
  textEditor.setShowInvisibles(true)
108
113
  textEditor.gotoLine(0, 0)
109
- textEditor.setReadOnly(@isEnabled('readonly_ruby_mode'))
110
114
  textEditor.on 'change', (e) =>
111
115
  unless @translating
112
116
  window.changed = true
@@ -195,11 +199,51 @@ window.Smalruby =
195
199
  @Views.CharacterSelectorView.addBlock_(c)
196
200
  window.changed = false
197
201
 
198
- isEnabled: (feature) ->
199
- @Features.indexOf(feature) != -1
202
+ setPreferences: (preferences) ->
203
+ @Preferences = preferences
204
+ window.textEditor.setReadOnly(@isEnabled('enabled_readonly_ruby_mode'))
205
+ if @isEnabled('disabled_new_character')
206
+ $('#add-character-item').hide()
207
+ else
208
+ $('#add-character-item').show()
209
+ @changedAfterTranslating = true
210
+ @reloadToolbox()
211
+
212
+ isEnabled: (name) ->
213
+ @Preferences[name] == true || @Preferences[name] == 'true' || @Preferences[name] == '1'
214
+
215
+ reloadToolbox: ->
216
+ $('body').block
217
+ message: <%= bm('common.processing') %>
218
+
219
+ unblock = =>
220
+ $('body').unblock()
221
+ null # HACK: if return unblock(), does not call fail().
222
+ dfr = $.Deferred()
223
+ $.ajax
224
+ url: '/toolbox'
225
+ type: 'GET'
226
+ success: (data, textStatus, jqXHR) -> dfr.resolve(data)
227
+ error: dfr.reject
228
+ dfr.promise()
229
+ .then (data) =>
230
+ Blockly.updateToolbox(data)
231
+ @hideEmptyCategory()
232
+ .then(unblock, unblock)
233
+ .fail =>
234
+ errorMessage(<%= bm('.error') %>)
235
+
236
+ hideEmptyCategory: ->
237
+ i = 1
238
+ for node in Blockly.getMainWorkspace().options.languageTree.childNodes
239
+ do (node) =>
240
+ if node.tagName
241
+ if node.getElementsByTagName('block').length == 0 && node.getAttribute('custom') == null
242
+ $("div.blocklyTreeRoot > div:nth-child(2) > div:nth-child(#{i})[aria-level=\"1\"]").hide()
243
+ i++
200
244
 
201
245
  $(document).ready ->
202
246
  Smalruby.initialize()
203
247
 
204
- if Smalruby.username == null && Smalruby.isEnabled('must_signin')
248
+ if Smalruby.username == null && Smalruby.isEnabled('enabled_must_signin')
205
249
  Smalruby.Views.SigninModalView.render()
@@ -17,6 +17,7 @@ Smalruby.MainMenuView = Backbone.View.extend
17
17
  'click #save-button': 'onSave'
18
18
  'click #check-button': 'onCheck'
19
19
  'click #reset-button': 'onReset'
20
+ 'click #preference-button': 'onPreference'
20
21
  'click #signin-button': 'onSignin'
21
22
  'click #signout-button': 'onSignout'
22
23
  'click #username-button': 'onUsername'
@@ -35,6 +36,9 @@ Smalruby.MainMenuView = Backbone.View.extend
35
36
  done: (e, data) =>
36
37
  @load(data.result.source_code)
37
38
 
39
+ # HACK: if don't do below, can't open submenu on Chromium on Raspberry Pi
40
+ $('.dropdown-toggle').dropdown()
41
+
38
42
  onBlockMode: (e) ->
39
43
  e.preventDefault()
40
44
 
@@ -78,7 +82,7 @@ Smalruby.MainMenuView = Backbone.View.extend
78
82
 
79
83
  return unless Smalruby.changedAfterTranslating
80
84
 
81
- data = Blockly.Ruby.workspaceToCode()
85
+ data = Blockly.Ruby.workspaceToCode(Blockly.getMainWorkspace())
82
86
  Smalruby.translating = true
83
87
  window.textEditor.getSession().getDocument().setValue(data)
84
88
  Smalruby.translating = false
@@ -256,6 +260,11 @@ Smalruby.MainMenuView = Backbone.View.extend
256
260
  Smalruby.reset()
257
261
  true
258
262
 
263
+ onPreference: (e) ->
264
+ e.preventDefault()
265
+
266
+ Smalruby.Views.PreferenceModalView.render()
267
+
259
268
  onSignin: (e) ->
260
269
  e.preventDefault()
261
270
 
@@ -270,14 +279,15 @@ Smalruby.MainMenuView = Backbone.View.extend
270
279
  })
271
280
  .then(
272
281
  (data) ->
282
+ Smalruby.setPreferences(data)
273
283
  Smalruby.username = null
274
284
  $('#signin-button').show()
275
- $('#signout-button').hide()
285
+ $('.signed-in-menu').hide()
276
286
  $('#username-label').text('')
277
287
  $('#username-button').hide()
278
288
  successMessage(<%= bm('.signout_succeeded') %>)
279
289
 
280
- if Smalruby.isEnabled('must_signin')
290
+ if Smalruby.isEnabled('enabled_must_signin')
281
291
  Smalruby.Views.SigninModalView.render()
282
292
  ->
283
293
  errorMessage(<%= bm('.signout_error') %>)
@@ -364,7 +374,7 @@ Smalruby.MainMenuView = Backbone.View.extend
364
374
  filename = filename.replace(/(\.rb)?\.xml$/, '.rb')
365
375
  Smalruby.blocklyLoading = true
366
376
  Smalruby.loadXml(info.data)
367
- info.data = Blockly.Ruby.workspaceToCode()
377
+ info.data = Blockly.Ruby.workspaceToCode(Blockly.getMainWorkspace())
368
378
  else
369
379
  Smalruby.Collections.CharacterSet.reset()
370
380
  Blockly.mainWorkspace.clear()
@@ -0,0 +1,71 @@
1
+ <%
2
+ require 'smalruby_editor'
3
+ require 'smalruby_editor/blockly_message_helper'
4
+ %>
5
+
6
+ # preference dialog view
7
+ Smalruby.PreferenceModalView = Backbone.View.extend
8
+ events:
9
+ 'click #preference-modal-ok-button': 'onOk'
10
+ 'change #user_preferences_toolbox_name': 'renderToolboxPreferences'
11
+
12
+ #initialize: ->
13
+ # # no-op
14
+
15
+ render: ->
16
+ @$el.find('.modal-body').block
17
+ message: null
18
+
19
+ unblock = =>
20
+ @$el.find('.modal-body').unblock()
21
+ null # HACK: if return unblock(), does not call fail().
22
+
23
+ @$el.modal
24
+ backdrop: 'static'
25
+ @$el.modal('show')
26
+
27
+ dfr = $.Deferred()
28
+ $.ajax
29
+ url: 'preferences'
30
+ type: 'GET'
31
+ cache: false
32
+ success: (data, textStatus, jqXHR) -> dfr.resolve(data)
33
+ error: dfr.reject
34
+ dfr.promise()
35
+ .then (data) =>
36
+ $('#preference-modal-content').replaceWith(data)
37
+ @renderToolboxPreferences()
38
+ .then(unblock, unblock)
39
+ .fail =>
40
+ @$el.modal('hide')
41
+ errorMessage(<%= bm('.error') %>)
42
+
43
+ onOk: ->
44
+ @$el.block
45
+ message: <%= bm('common.processing') %>
46
+
47
+ unblock = =>
48
+ @$el.unblock()
49
+ null # HACK: if return unblock(), does not call fail().
50
+
51
+ form = @$el.find('form')
52
+ dfr = $.Deferred()
53
+ $.ajax
54
+ url: form.attr('action')
55
+ data: form.serialize()
56
+ type: 'POST'
57
+ success: (data, textStatus, jqXHR) -> dfr.resolve(data)
58
+ error: dfr.reject
59
+ dfr.promise()
60
+ .then (data) =>
61
+ Smalruby.setPreferences(data)
62
+ .then(unblock, unblock)
63
+ .done =>
64
+ @$el.modal('hide')
65
+ .fail =>
66
+ errorMessage(<%= bm('.error') %>)
67
+
68
+ renderToolboxPreferences: ->
69
+ @$el.find('.toolbox_preferences').hide()
70
+ toolboxName = $('#user_preferences_toolbox_name').val() || 'default'
71
+ @$el.find(".toolbox_preferences.#{toolboxName}").show()
@@ -27,10 +27,11 @@ Smalruby.SigninModalView = Backbone.View.extend
27
27
  $.post('/sessions/', { username: username })
28
28
  .then(
29
29
  (data) ->
30
- Smalruby.username = data
30
+ Smalruby.setPreferences(data)
31
+ Smalruby.username = username
31
32
  $('#signin-button').hide()
32
- $('#signout-button').show()
33
- $('#username-label').text(data)
33
+ $('.signed-in-menu').show()
34
+ $('#username-label').text(username)
34
35
  $('#username-button').show()
35
36
  successMessage(<%= bm('.signed_in') %>)
36
37
  new $.Deferred().resolve().promise()
@@ -39,5 +40,5 @@ Smalruby.SigninModalView = Backbone.View.extend
39
40
  new $.Deferred().resolve().promise()
40
41
  )
41
42
  .done =>
42
- if Smalruby.username != null || !Smalruby.isEnabled('must_signin')
43
+ if Smalruby.username != null || !Smalruby.isEnabled('enabled_must_signin')
43
44
  @$el.modal('hide')