smalruby-editor 0.2.2 → 0.2.3
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Guardfile +2 -6
- data/LEGAL +6 -0
- data/README.rdoc +2 -0
- data/app/assets/javascripts/application.js +1 -0
- data/app/assets/javascripts/blocks/hardware.js.coffee.erb +37 -0
- data/app/assets/javascripts/models/source_code.js +123 -0
- data/app/assets/javascripts/msg/en_us.js +2 -0
- data/app/assets/javascripts/msg/ja.js +2 -0
- data/app/assets/javascripts/smalruby.js.coffee.erb +1 -1
- data/app/assets/javascripts/views/character_modal_view.js.coffee +2 -0
- data/app/assets/javascripts/views/character_selector_view.js.coffee +2 -2
- data/app/assets/javascripts/views/load_modal_view.js.coffee.erb +2 -0
- data/app/assets/javascripts/views/reset_modal_view.js.coffee +2 -0
- data/app/assets/stylesheets/application.css +0 -0
- data/app/assets/stylesheets/editor.css.scss +0 -0
- data/app/assets/stylesheets/toolbox_raspberrypi.css.scss.erb +32 -0
- data/app/assets/stylesheets/toolbox_smalrubot_s1.css.scss.erb +1 -0
- data/app/controllers/editor_controller.rb +0 -0
- data/app/helpers/application_helper.rb +5 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_dc_motor_power_ratio.rb +26 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_dc_motor_set_power_ratio.rb +21 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_motor_set_speed.rb +21 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_motor_speed.rb +26 -0
- data/app/models/source_code.rb +0 -0
- data/app/views/editor/_toolbox_default.html.haml +7 -3
- data/app/views/editor/_toolbox_raspberrypi.html.haml +233 -0
- data/app/views/editor/_toolbox_smalrubot_s1.html.haml +75 -51
- data/app/views/editor/_toolbox_smalrubot_v3.html.haml +70 -55
- data/app/views/editor/index.html.haml +0 -6
- data/app/views/layouts/application.html.erb +1 -0
- data/db/schema.rb +23 -23
- data/lib/smalruby_editor.rb +5 -1
- data/lib/smalruby_editor/config.rb +2 -0
- data/lib/smalruby_editor/version.rb +1 -1
- data/smalruby-editor.gemspec +1 -1
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_dc_motor_power_ratio.feature +116 -0
- data/spec/javascripts/models/source_code_spec.coffee +5 -0
- data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_s1_spec.rb +89 -1
- data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_v3_spec.rb +433 -0
- data/spec/models/concerns/ruby_to_block/block/hardware_spec.rb +0 -338
- data/vendor/assets/javascripts/strftime-min.js +8 -0
- metadata +27 -14
- data/app/assets/javascripts/models/source_code.js.coffee +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 645036cf0ed6ff50503c110004694f94d2dc2450
|
4
|
+
data.tar.gz: cfc14cbb697365ad0486edd13332908dbed36bd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 058b82bff868a8607dc1ca95231b211a8f8051be0fba58b7bdf150f4ab7002d462415f1c654699b04b318093aaec043ad8ac16ec9de4303655ae864b2e74a779
|
7
|
+
data.tar.gz: 5c634a86474b307b7ea46c76f9f013e006fbb74ead929e800ced8c3b6f2ec5df5b751cc1c0fcb29600d047da9014574b9e746899aee7b5a532df02042fe88ff8
|
data/.rubocop.yml
CHANGED
data/Guardfile
CHANGED
@@ -9,17 +9,15 @@
|
|
9
9
|
|
10
10
|
TEMPFILE_BY_EMACS = %r{/\.?\#[^\/]+$}
|
11
11
|
|
12
|
+
ignore(TEMPFILE_BY_EMACS)
|
13
|
+
|
12
14
|
group :red_green_refactor, halt_on_fail: true do
|
13
15
|
guard :rubocop, all_on_start: false do
|
14
|
-
ignore(TEMPFILE_BY_EMACS)
|
15
|
-
|
16
16
|
watch(%r{.+\.rb$})
|
17
17
|
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
18
18
|
end
|
19
19
|
|
20
20
|
guard :rspec, cmd: 'bundle exec bin/rspec' do
|
21
|
-
ignore(TEMPFILE_BY_EMACS)
|
22
|
-
|
23
21
|
watch(%r{^spec/.+_spec\.rb$})
|
24
22
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
25
23
|
watch('spec/spec_helper.rb') { "spec" }
|
@@ -42,8 +40,6 @@ group :red_green_refactor, halt_on_fail: true do
|
|
42
40
|
end
|
43
41
|
|
44
42
|
guard 'livereload' do
|
45
|
-
ignore(TEMPFILE_BY_EMACS)
|
46
|
-
|
47
43
|
watch(%r{app/views/.+\.(erb|haml|slim)$})
|
48
44
|
watch(%r{app/helpers/.+\.rb})
|
49
45
|
watch(%r{public/.+\.(css|js|html)})
|
data/LEGAL
CHANGED
@@ -44,3 +44,9 @@ public/square.png, public/tiny.png, public/wide.png:
|
|
44
44
|
Smalruby) 2013. このイメージキャラクター、もしくはその派生版は、Ru
|
45
45
|
byプログラミング少年団とスモウルビー:Smalrubyに関連する文脈で誰で
|
46
46
|
も自由に利用できるが、それらは荒川ひかりによる保証を示すものではない。
|
47
|
+
|
48
|
+
vendor/assets/javascripts/strftime-min.js:
|
49
|
+
|
50
|
+
Copyright 2010 - 2013 Sami Samhuri sami@samhuri.net
|
51
|
+
|
52
|
+
MIT license (http://sjs.mit-license.org/)
|
data/README.rdoc
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
== smalruby-editor
|
2
2
|
|
3
|
+
{<img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/smalruby/smalruby-editor">}[https://gitter.im/smalruby/smalruby-editor?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge]
|
4
|
+
|
3
5
|
{<img src="https://badge.fury.io/rb/smalruby-editor.png" alt="Gem Version" />}[http://badge.fury.io/rb/smalruby-editor]
|
4
6
|
{<img src="https://travis-ci.org/smalruby/smalruby-editor.png?branch=master" alt="Build Status" />}[https://travis-ci.org/smalruby/smalruby-editor]
|
5
7
|
{<img src="https://coveralls.io/repos/smalruby/smalruby-editor/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/smalruby/smalruby-editor?branch=master]
|
@@ -679,3 +679,40 @@ Blockly.Blocks['<%= n %>'] =
|
|
679
679
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
680
680
|
lor = @getFieldValue('LOR')
|
681
681
|
Blockly.Ruby.characterMethodCallInput_("<%= subcategory %>.#{lor}_ir_photoreflector_value")
|
682
|
+
|
683
|
+
# Smalrubot s1 left/right dc motor power ratio
|
684
|
+
<% n = "#{category}_#{subcategory}_dc_motor_power_ratio" %>
|
685
|
+
Blockly.Blocks['<%= n %>'] =
|
686
|
+
init: ()->
|
687
|
+
@setHelpUrl('')
|
688
|
+
@setColour(<%= colors[:sensing] %>)
|
689
|
+
@interpolateMsg(<%= bm(".#{subcategory}_dc_motor_power_ratio") %>,
|
690
|
+
['LOR', new Blockly.FieldDropdown(lorDropdown)],
|
691
|
+
Blockly.ALIGN_RIGHT)
|
692
|
+
@setOutput(true, 'Number')
|
693
|
+
@setTooltip('')
|
694
|
+
|
695
|
+
Blockly.Ruby['<%= n %>'] = (block) ->
|
696
|
+
lor = @getFieldValue('LOR')
|
697
|
+
Blockly.Ruby.characterMethodCallInput_("<%= subcategory %>.#{lor}_dc_motor_power_ratio")
|
698
|
+
|
699
|
+
# set Smalrubot s1 left/right dc motor power ratio
|
700
|
+
<% n = "#{category}_#{subcategory}_dc_motor_set_power_ratio" %>
|
701
|
+
Blockly.Blocks['<%= n %>'] =
|
702
|
+
init: ()->
|
703
|
+
@setHelpUrl('')
|
704
|
+
@setColour(<%= colors[:motion] %>)
|
705
|
+
@interpolateMsg(<%= bm(".#{subcategory}_dc_motor_set_power_ratio") %>,
|
706
|
+
['LOR', new Blockly.FieldDropdown(lorDropdown)],
|
707
|
+
['SPEED', ['Number'], Blockly.ALIGN_RIGHT],
|
708
|
+
Blockly.ALIGN_RIGHT)
|
709
|
+
@setInputsInline(true)
|
710
|
+
@setPreviousStatement(true)
|
711
|
+
@setNextStatement(true)
|
712
|
+
@setTooltip('')
|
713
|
+
|
714
|
+
Blockly.Ruby['<%= n %>'] = (block) ->
|
715
|
+
lor = @getFieldValue('LOR')
|
716
|
+
speed = Blockly.Ruby.valueToCode(@, 'SPEED', Blockly.Ruby.ORDER_NONE) || '100'
|
717
|
+
Blockly.Ruby.characterSetVariable_("<%= subcategory %>.#{lor}_dc_motor_power_ratio",
|
718
|
+
speed)
|
@@ -0,0 +1,123 @@
|
|
1
|
+
/**
|
2
|
+
* ソースコードを表現するモデル
|
3
|
+
*/
|
4
|
+
Smalruby.SourceCode = Backbone.Model.extend({
|
5
|
+
defaults: {
|
6
|
+
filename: null,
|
7
|
+
data: null
|
8
|
+
},
|
9
|
+
|
10
|
+
initialize: function() {
|
11
|
+
if (!this.get('filename')) {
|
12
|
+
var filename = Smalruby.Views.MainMenuView.getFilename();
|
13
|
+
if (filename.length == 0) {
|
14
|
+
filename = Smalruby.SourceCode.defaultFilename();
|
15
|
+
}
|
16
|
+
this.set('filename', filename);
|
17
|
+
}
|
18
|
+
|
19
|
+
if (!this.get('data')) {
|
20
|
+
if (this.get('filename').match(/\.xml$/)) {
|
21
|
+
var data = Smalruby.dumpXml();
|
22
|
+
}
|
23
|
+
else {
|
24
|
+
if (window.blockMode) {
|
25
|
+
var data = Blockly.Ruby.workspaceToCode();
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
var data = window.textEditor.getSession().getDocument().getValue();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
this.set('data', data);
|
32
|
+
}
|
33
|
+
},
|
34
|
+
|
35
|
+
getRbxmlFilename: function() {
|
36
|
+
var filename = this.get('filename');
|
37
|
+
if (filename.match(/\.rb\.xml$/)) {
|
38
|
+
return filename;
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
if (filename.match(/\.rb$/)) {
|
42
|
+
return filename + '.xml';
|
43
|
+
}
|
44
|
+
else if (filename.match(/\.xml$/)) {
|
45
|
+
return filename.replace(/\.xml$/, '.rb.xml');
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
return filename + '.rb.xml';
|
49
|
+
}
|
50
|
+
}
|
51
|
+
},
|
52
|
+
|
53
|
+
run: function() {
|
54
|
+
return this.post_('run');
|
55
|
+
},
|
56
|
+
|
57
|
+
check: function() {
|
58
|
+
return this.post_('check');
|
59
|
+
},
|
60
|
+
|
61
|
+
save2: function() {
|
62
|
+
return this.post_('');
|
63
|
+
},
|
64
|
+
|
65
|
+
write: function(force) {
|
66
|
+
if (force == null) {
|
67
|
+
force = false;
|
68
|
+
}
|
69
|
+
var action = 'write';
|
70
|
+
if (force) {
|
71
|
+
action += '?force=1';
|
72
|
+
}
|
73
|
+
return this.delete_(action);
|
74
|
+
},
|
75
|
+
|
76
|
+
toBlocks: function() {
|
77
|
+
return this.post_('to_blocks', 'html');
|
78
|
+
},
|
79
|
+
|
80
|
+
post_: function(action, dataType) {
|
81
|
+
if (dataType == null) {
|
82
|
+
dataType = 'json';
|
83
|
+
}
|
84
|
+
dfr = $.Deferred();
|
85
|
+
$.ajax({
|
86
|
+
url: '/source_codes/' + action,
|
87
|
+
type: 'POST',
|
88
|
+
data: {
|
89
|
+
source_code: {
|
90
|
+
filename: this.get('filename'),
|
91
|
+
data: this.get('data')
|
92
|
+
}
|
93
|
+
},
|
94
|
+
dataType: dataType,
|
95
|
+
success: function(data, textStatus, jqXHR) {
|
96
|
+
return dfr.resolve(data);
|
97
|
+
},
|
98
|
+
error: dfr.reject
|
99
|
+
});
|
100
|
+
return dfr.promise();
|
101
|
+
},
|
102
|
+
|
103
|
+
delete_: function(action) {
|
104
|
+
dfr = $.Deferred();
|
105
|
+
$.ajax({
|
106
|
+
url: '/source_codes/' + action,
|
107
|
+
type: 'DELETE',
|
108
|
+
dataType: 'json',
|
109
|
+
success: function(data, textStatus, jqXHR) {
|
110
|
+
return dfr.resolve(data);
|
111
|
+
},
|
112
|
+
error: dfr.reject
|
113
|
+
});
|
114
|
+
return dfr.promise();
|
115
|
+
}
|
116
|
+
}, {
|
117
|
+
defaultFilename: function(now) {
|
118
|
+
if (now == null) {
|
119
|
+
now = new Date();
|
120
|
+
}
|
121
|
+
return strftime('program_%y%m%d_%H%M%S.rb', now);
|
122
|
+
}
|
123
|
+
});
|
@@ -263,6 +263,8 @@ Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_LED_TURN_ON_OR_OFF = '%2 Smalrubot s1 %
|
|
263
263
|
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_ACTION = '%1 Smalrubot s1';
|
264
264
|
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_ACTION_WITH_SEC = '%1 Smalrubot s1 for %2 secs';
|
265
265
|
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_IR_PHOTOREFLECTOR_VALUE = 'Smalrubot s1 %1 IR Photoreflector';
|
266
|
+
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_DC_MOTOR_POWER_RATIO = 'Smalrubot s1 %1 dc motor power ratio';
|
267
|
+
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_DC_MOTOR_SET_POWER_RATIO = 'set Smalrubot s1 %1 dc motor power ratio to %2 %';
|
266
268
|
|
267
269
|
|
268
270
|
// blocks/operators.js.coffee.erb
|
@@ -263,6 +263,8 @@ Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_LED_TURN_ON_OR_OFF = '★スモウル
|
|
263
263
|
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_ACTION = '■スモウルボットS1を %1';
|
264
264
|
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_ACTION_WITH_SEC = '■スモウルボットS1を %2 秒 %1';
|
265
265
|
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_IR_PHOTOREFLECTOR_VALUE = '◎スモウルボットS1の %1 のセンサー';
|
266
|
+
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_DC_MOTOR_POWER_RATIO = '◎スモウルボットS1の %1 DCモーターの速度(%)';
|
267
|
+
Blockly.Msg.BLOCKS_HARDWARE_SMALRUBOT_S1_DC_MOTOR_SET_POWER_RATIO = '■スモウルボットS1の %1 DCモーターの速度を %2 (%) にする';
|
266
268
|
|
267
269
|
|
268
270
|
// blocks/operators.js.coffee.erb
|
@@ -183,7 +183,7 @@ window.Smalruby =
|
|
183
183
|
name
|
184
184
|
|
185
185
|
addCharacterFromBeginning: ->
|
186
|
-
if
|
186
|
+
if !@isEnabled('disabled_add_character_from_beginning')
|
187
187
|
constume = 'cat1.png'
|
188
188
|
c = new Smalruby.Character
|
189
189
|
name: @Collections.CharacterSet.uniqueName(constume)
|
@@ -46,7 +46,7 @@ Smalruby.CharacterSelectorView = Backbone.View.extend({
|
|
46
46
|
removeButton.click (e) =>
|
47
47
|
e.preventDefault()
|
48
48
|
@removeCharacter_(character)
|
49
|
-
if character.get('using')
|
49
|
+
if Smalruby.isEnabled('disabled_new_character') || character.get('using')
|
50
50
|
removeButton.hide()
|
51
51
|
|
52
52
|
img = html.find('img')
|
@@ -105,7 +105,7 @@ Smalruby.CharacterSelectorView = Backbone.View.extend({
|
|
105
105
|
@prevXY = newBlock.getRelativeToSurfaceXY()
|
106
106
|
|
107
107
|
removeCharacter_: (character) ->
|
108
|
-
|
108
|
+
if !Smalruby.isEnabled('disabled_new_character') && !character.get('using')
|
109
109
|
Smalruby.Collections.CharacterSet.remove(character)
|
110
110
|
|
111
111
|
}, {
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%
|
2
|
+
require 'smalruby_editor'
|
3
|
+
colors = SmalrubyEditor::COLORS
|
4
|
+
|
5
|
+
hues = [
|
6
|
+
colors[:motion],
|
7
|
+
colors[:looks],
|
8
|
+
colors[:sound],
|
9
|
+
colors[:data],
|
10
|
+
colors[:events],
|
11
|
+
colors[:control],
|
12
|
+
colors[:sensing],
|
13
|
+
colors[:operators],
|
14
|
+
]
|
15
|
+
|
16
|
+
colors = hues.map { |h|
|
17
|
+
[SmalrubyEditor.hsv_to_rgb(h, 100, 80),
|
18
|
+
SmalrubyEditor.hsv_to_rgb(h, 100, 100)]
|
19
|
+
}
|
20
|
+
|
21
|
+
colors.each.with_index(1) do |(color, active_color), index|
|
22
|
+
%>
|
23
|
+
div[aria-level="1"][aria-posinset="<%= index %>"] {
|
24
|
+
.blocklyTreeRow {
|
25
|
+
background-color: #<%= color %> !important;
|
26
|
+
}
|
27
|
+
|
28
|
+
.blocklyTreeRow.blocklyTreeSelected {
|
29
|
+
background-color: #<%= active_color %> !important;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
<% end %>
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RubyToBlock
|
2
|
+
module Block
|
3
|
+
class HardwareSmalrubotS1DcMotorPowerRatio < Value
|
4
|
+
include CharacterOperation
|
5
|
+
include HardwareOperation
|
6
|
+
|
7
|
+
blocknize '^\s*' + CHAR_RE +
|
8
|
+
'smalrubot_s1\.' +
|
9
|
+
LOR_RE + '_dc_motor_power_ratio\s*$',
|
10
|
+
value: true
|
11
|
+
|
12
|
+
def self.process_match_data(md, context)
|
13
|
+
md2 = regexp.match(md[type])
|
14
|
+
|
15
|
+
character = get_character(context, md2[1])
|
16
|
+
return false if context.receiver && context.receiver != character
|
17
|
+
|
18
|
+
block = new(fields: { LOR: md2[2] })
|
19
|
+
context.add_value(block)
|
20
|
+
block.character = character
|
21
|
+
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_dc_motor_set_power_ratio.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module RubyToBlock
|
3
|
+
module Block
|
4
|
+
class HardwareSmalrubotS1DcMotorSetPowerRatio < CharacterMethodCall
|
5
|
+
include HardwareOperation
|
6
|
+
|
7
|
+
blocknize '^\s*' + CHAR_RE +
|
8
|
+
'smalrubot_s1\.' +
|
9
|
+
LOR_RE + '_dc_motor_power_ratio\s*=\s*(\S+)\s*$',
|
10
|
+
statement: true, inline: true
|
11
|
+
|
12
|
+
def self.process_match_data(md, context)
|
13
|
+
md2 = regexp.match(md[type])
|
14
|
+
add_character_method_call_block(context, md2[1],
|
15
|
+
new(fields: { LOR: md2[2] }),
|
16
|
+
SPEED: md2[3])
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module RubyToBlock
|
3
|
+
module Block
|
4
|
+
class HardwareSmalrubotV3MotorSetSpeed < CharacterMethodCall
|
5
|
+
include HardwareOperation
|
6
|
+
|
7
|
+
blocknize '^\s*' + CHAR_RE +
|
8
|
+
'smalrubot_v3\.' +
|
9
|
+
LOR_RE + '_motor_speed\s*=\s*(\S+)\s*$',
|
10
|
+
statement: true, inline: true
|
11
|
+
|
12
|
+
def self.process_match_data(md, context)
|
13
|
+
md2 = regexp.match(md[type])
|
14
|
+
add_character_method_call_block(context, md2[1],
|
15
|
+
new(fields: { LOR: md2[2] }),
|
16
|
+
SPEED: md2[3])
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|