smalruby-editor 0.2.1 → 0.2.2
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/LEGAL +4 -3
- data/app/assets/javascripts/blocks/character.js.coffee.erb +7 -3
- data/app/assets/javascripts/blocks/events.js.coffee.erb +7 -10
- data/app/assets/javascripts/blocks/hardware.js.coffee.erb +119 -31
- data/app/assets/javascripts/blocks/motion.js.coffee.erb +16 -20
- data/app/assets/javascripts/blocks/operators.js.coffee.erb +1 -1
- data/app/assets/javascripts/blocks/pen.js.coffee.erb +2 -1
- data/app/assets/javascripts/blocks/ruby.js.coffee.erb +3 -3
- data/app/assets/javascripts/blocks/sensing.js.coffee.erb +8 -8
- data/app/assets/javascripts/blocks/sound.js.coffee.erb +3 -1
- data/app/assets/javascripts/fix_blockly.js.erb +105 -0
- data/app/assets/javascripts/generators/ruby.js.coffee.erb +3 -0
- data/app/assets/javascripts/msg/en_us.js +67 -17
- data/app/assets/javascripts/msg/ja.js +151 -95
- data/app/assets/javascripts/{smalruby.js.coffee → smalruby.js.coffee.erb} +35 -16
- data/app/assets/javascripts/views/character_selector_view.js.coffee +2 -2
- data/app/assets/javascripts/views/{load_modal_view.js.coffee → load_modal_view.js.coffee.erb} +8 -2
- data/app/assets/javascripts/views/main_menu_view.js.coffee.erb +33 -48
- data/app/assets/javascripts/views/signin_modal_view.js.coffee.erb +43 -0
- data/app/assets/stylesheets/application.css +3 -1
- data/app/assets/stylesheets/toolbox.css.scss.erb +2 -56
- data/app/assets/stylesheets/toolbox_default.css.scss.erb +34 -0
- data/app/assets/stylesheets/toolbox_smalrubot_s1.css.scss.erb +31 -0
- data/app/assets/stylesheets/toolbox_smalrubot_v3.css.scss.erb +32 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/source_codes_controller.rb +6 -3
- data/app/helpers/application_helper.rb +12 -0
- data/app/helpers/editor_helper.rb +25 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action.rb +13 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action_with_sec.rb +14 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_ir_photoreflector_value.rb +29 -0
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_led_turn_on_or_off.rb +22 -0
- data/app/views/editor/_block_tab.html.haml +7 -6
- data/app/views/editor/_reset_modal.html.haml +4 -4
- data/app/views/editor/_signin_modal.html.haml +8 -9
- data/app/views/editor/_toolbox_default.html.haml +504 -0
- data/app/views/editor/_toolbox_smalrubot_s1.html.haml +171 -0
- data/app/views/editor/_toolbox_smalrubot_v3.html.haml +177 -0
- data/app/views/editor/index.html.haml +12 -2
- data/app/views/layouts/application.html.erb +1 -0
- data/config/environments/production.rb +1 -0
- data/config/locales/en.yml +19 -16
- data/config/locales/ja.yml +28 -25
- data/demos/hardware_led.rb.xml +79 -79
- data/lib/smalruby_editor.rb +58 -0
- data/lib/smalruby_editor/config.rb +22 -0
- data/lib/smalruby_editor/version.rb +1 -1
- data/public/blockly/media/anon.jpeg +0 -0
- data/public/blockly/media/handclosed.cur +0 -0
- data/public/blockly/media/handdelete.cur +0 -0
- data/public/blockly/media/progress.gif +0 -0
- data/public/blockly/media/sprites.png +0 -0
- data/smalruby-editor.gemspec +2 -1
- data/spec/acceptance/base.feature +3 -3
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action.feature +107 -0
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action_with_sec.feature +151 -0
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_ir_photoreflector_value.feature +100 -0
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_led_turn_on_or_off.feature +73 -0
- data/spec/acceptance/ruby_mode/translate.feature +6 -6
- data/spec/acceptance/standalone/save.feature +3 -3
- data/spec/acceptance/standalone/signin.feature +1 -2
- data/spec/lib/smalruby_editor_spec.rb +21 -11
- data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_s1_spec.rb +279 -0
- data/vendor/assets/javascripts/blockly/blockly_compressed.js +995 -668
- data/vendor/assets/javascripts/blockly/blocks_compressed.js +138 -114
- data/vendor/assets/javascripts/blockly/msg/js/en_us.js +6 -6
- data/vendor/assets/javascripts/blockly/msg/js/ja.js +42 -28
- metadata +66 -25
- data/app/assets/javascripts/fix_blockly.js +0 -128
- data/app/assets/javascripts/views/signin_modal_view.js.coffee +0 -33
- data/app/views/editor/_toolbox.html.haml +0 -496
- data/public/blockly/media/trashbody.png +0 -0
- data/public/blockly/media/trashlid.png +0 -0
- data/public/blockly/media/tree.png +0 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# language: en
|
3
|
+
@javascript
|
4
|
+
Feature: hardware_smalrubot_s1_action_with_sec block
|
5
|
+
Background:
|
6
|
+
Given "ブロック" タブを表示する
|
7
|
+
And キャラクターcar1を追加する
|
8
|
+
|
9
|
+
Scenario: ブロックのみ配置する
|
10
|
+
When 次のブロックを配置する:
|
11
|
+
"""
|
12
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
13
|
+
%field{:name => "ACTION"}<
|
14
|
+
backward
|
15
|
+
%value{:name => "SEC"}
|
16
|
+
%block{:type => "math_number"}
|
17
|
+
%field{:name => "NUM"}<
|
18
|
+
0.5
|
19
|
+
"""
|
20
|
+
And ブロックからソースコードを生成する
|
21
|
+
|
22
|
+
Then テキストエディタのプログラムは "" であること
|
23
|
+
|
24
|
+
Scenario: キャラクターとブロックを配置する
|
25
|
+
When 次のブロックを配置する:
|
26
|
+
"""
|
27
|
+
%block{:type => "character_new", :x => "21", :y => "15"}
|
28
|
+
%field{:name => "NAME"}<
|
29
|
+
car1
|
30
|
+
%statement{:name => "DO"}
|
31
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
32
|
+
%field{:name => "ACTION"}<
|
33
|
+
forward
|
34
|
+
%value{:name => "SEC"}
|
35
|
+
%block{:type => "math_number"}
|
36
|
+
%field{:name => "NUM"}<
|
37
|
+
0.5
|
38
|
+
%next
|
39
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
40
|
+
%field{:name => "ACTION"}<
|
41
|
+
backward
|
42
|
+
%value{:name => "SEC"}
|
43
|
+
%block{:type => "math_number"}
|
44
|
+
%field{:name => "NUM"}<
|
45
|
+
0.5
|
46
|
+
%next
|
47
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
48
|
+
%field{:name => "ACTION"}<
|
49
|
+
turn_left
|
50
|
+
%value{:name => "SEC"}
|
51
|
+
%block{:type => "math_number"}
|
52
|
+
%field{:name => "NUM"}<
|
53
|
+
0.5
|
54
|
+
%next
|
55
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
56
|
+
%field{:name => "ACTION"}<
|
57
|
+
turn_right
|
58
|
+
%value{:name => "SEC"}
|
59
|
+
%block{:type => "math_number"}
|
60
|
+
%field{:name => "NUM"}<
|
61
|
+
0.5
|
62
|
+
%next
|
63
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
64
|
+
%field{:name => "ACTION"}<
|
65
|
+
stop
|
66
|
+
%value{:name => "SEC"}
|
67
|
+
%block{:type => "math_number"}
|
68
|
+
%field{:name => "NUM"}<
|
69
|
+
0.5
|
70
|
+
"""
|
71
|
+
And ブロックからソースコードを生成する
|
72
|
+
|
73
|
+
Then テキストエディタのプログラムは以下であること:
|
74
|
+
"""
|
75
|
+
require "smalruby"
|
76
|
+
|
77
|
+
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
78
|
+
car1.smalrubot_s1.forward(sec: 0.5)
|
79
|
+
car1.smalrubot_s1.backward(sec: 0.5)
|
80
|
+
car1.smalrubot_s1.turn_left(sec: 0.5)
|
81
|
+
car1.smalrubot_s1.turn_right(sec: 0.5)
|
82
|
+
car1.smalrubot_s1.stop(sec: 0.5)
|
83
|
+
|
84
|
+
"""
|
85
|
+
|
86
|
+
Scenario: キャラクターとイベントとブロックを配置する
|
87
|
+
When 次のブロックを配置する:
|
88
|
+
"""
|
89
|
+
%block{:type => "character_new", :x => "21", :y => "15"}
|
90
|
+
%field{:name => "NAME"}<
|
91
|
+
car1
|
92
|
+
%statement{:name => "DO"}
|
93
|
+
%block{:type => "events_on_start"}
|
94
|
+
%statement{:name => "DO"}
|
95
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
96
|
+
%field{:name => "ACTION"}<
|
97
|
+
forward
|
98
|
+
%value{:name => "SEC"}
|
99
|
+
%block{:type => "math_number"}
|
100
|
+
%field{:name => "NUM"}<
|
101
|
+
0.5
|
102
|
+
%next
|
103
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
104
|
+
%field{:name => "ACTION"}<
|
105
|
+
backward
|
106
|
+
%value{:name => "SEC"}
|
107
|
+
%block{:type => "math_number"}
|
108
|
+
%field{:name => "NUM"}<
|
109
|
+
0.5
|
110
|
+
%next
|
111
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
112
|
+
%field{:name => "ACTION"}<
|
113
|
+
turn_left
|
114
|
+
%value{:name => "SEC"}
|
115
|
+
%block{:type => "math_number"}
|
116
|
+
%field{:name => "NUM"}<
|
117
|
+
0.5
|
118
|
+
%next
|
119
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
120
|
+
%field{:name => "ACTION"}<
|
121
|
+
turn_right
|
122
|
+
%value{:name => "SEC"}
|
123
|
+
%block{:type => "math_number"}
|
124
|
+
%field{:name => "NUM"}<
|
125
|
+
0.5
|
126
|
+
%next
|
127
|
+
%block{:type => "hardware_smalrubot_s1_action_with_sec", :x => "0", :y => "0"}
|
128
|
+
%field{:name => "ACTION"}<
|
129
|
+
stop
|
130
|
+
%value{:name => "SEC"}
|
131
|
+
%block{:type => "math_number"}
|
132
|
+
%field{:name => "NUM"}<
|
133
|
+
0.5
|
134
|
+
"""
|
135
|
+
And ブロックからソースコードを生成する
|
136
|
+
|
137
|
+
Then テキストエディタのプログラムは以下であること:
|
138
|
+
"""
|
139
|
+
require "smalruby"
|
140
|
+
|
141
|
+
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
142
|
+
|
143
|
+
car1.on(:start) do
|
144
|
+
smalrubot_s1.forward(sec: 0.5)
|
145
|
+
smalrubot_s1.backward(sec: 0.5)
|
146
|
+
smalrubot_s1.turn_left(sec: 0.5)
|
147
|
+
smalrubot_s1.turn_right(sec: 0.5)
|
148
|
+
smalrubot_s1.stop(sec: 0.5)
|
149
|
+
end
|
150
|
+
|
151
|
+
"""
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# language: en
|
3
|
+
@javascript
|
4
|
+
Feature: hardware_smalrubot_s1_ir_photoreflector_value block
|
5
|
+
Scenario: ブロックのみ配置する
|
6
|
+
Given "ブロック" タブを表示する
|
7
|
+
|
8
|
+
When 次のブロックを配置する:
|
9
|
+
"""
|
10
|
+
%block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
|
11
|
+
%field{:name => "LOR"}<
|
12
|
+
right
|
13
|
+
"""
|
14
|
+
And ブロックからソースコードを生成する
|
15
|
+
|
16
|
+
Then テキストエディタのプログラムは "" であること
|
17
|
+
|
18
|
+
Scenario: 文とブロックを配置する
|
19
|
+
Given "ブロック" タブを表示する
|
20
|
+
|
21
|
+
When 次のブロックを配置する:
|
22
|
+
"""
|
23
|
+
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
24
|
+
%value{:name => "ARG"}
|
25
|
+
%block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
|
26
|
+
%field{:name => "LOR"}<
|
27
|
+
right
|
28
|
+
"""
|
29
|
+
And ブロックからソースコードを生成する
|
30
|
+
|
31
|
+
Then テキストエディタのプログラムは以下であること:
|
32
|
+
"""
|
33
|
+
require "smalruby"
|
34
|
+
|
35
|
+
p("")
|
36
|
+
|
37
|
+
"""
|
38
|
+
|
39
|
+
Scenario: キャラクターとブロックを配置する
|
40
|
+
Given "ブロック" タブを表示する
|
41
|
+
And 次のキャラクターを追加する:
|
42
|
+
| name | costumes | x | y | angle |
|
43
|
+
| car1 | car1.png | 0 | 0 | 0 |
|
44
|
+
|
45
|
+
When 次のブロックを配置する:
|
46
|
+
"""
|
47
|
+
%block{:type => "character_new", :x => "21", :y => "15"}
|
48
|
+
%field{:name => "NAME"}<
|
49
|
+
car1
|
50
|
+
%statement{:name => "DO"}
|
51
|
+
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
52
|
+
%value{:name => "ARG"}
|
53
|
+
%block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
|
54
|
+
%field{:name => "LOR"}<
|
55
|
+
right
|
56
|
+
"""
|
57
|
+
And ブロックからソースコードを生成する
|
58
|
+
|
59
|
+
Then テキストエディタのプログラムは以下であること:
|
60
|
+
"""
|
61
|
+
require "smalruby"
|
62
|
+
|
63
|
+
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
64
|
+
p(car1.smalrubot_s1.right_ir_photoreflector_value)
|
65
|
+
|
66
|
+
"""
|
67
|
+
|
68
|
+
Scenario: キャラクターとイベントとブロックを配置する
|
69
|
+
Given "ブロック" タブを表示する
|
70
|
+
And 次のキャラクターを追加する:
|
71
|
+
| name | costumes | x | y | angle |
|
72
|
+
| car1 | car1.png | 0 | 0 | 0 |
|
73
|
+
|
74
|
+
When 次のブロックを配置する:
|
75
|
+
"""
|
76
|
+
%block{:type => "character_new", :x => "21", :y => "15"}
|
77
|
+
%field{:name => "NAME"}<
|
78
|
+
car1
|
79
|
+
%statement{:name => "DO"}
|
80
|
+
%block{:type => "events_on_start"}
|
81
|
+
%statement{:name => "DO"}
|
82
|
+
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
83
|
+
%value{:name => "ARG"}
|
84
|
+
%block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
|
85
|
+
%field{:name => "LOR"}<
|
86
|
+
left
|
87
|
+
"""
|
88
|
+
And ブロックからソースコードを生成する
|
89
|
+
|
90
|
+
Then テキストエディタのプログラムは以下であること:
|
91
|
+
"""
|
92
|
+
require "smalruby"
|
93
|
+
|
94
|
+
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
95
|
+
|
96
|
+
car1.on(:start) do
|
97
|
+
p(smalrubot_s1.left_ir_photoreflector_value)
|
98
|
+
end
|
99
|
+
|
100
|
+
"""
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# language: en
|
3
|
+
@javascript
|
4
|
+
Feature: hardware_smalrubot_s1_led_turn_on_or_off block
|
5
|
+
Background:
|
6
|
+
Given "ブロック" タブを表示する
|
7
|
+
And キャラクターcar1を追加する
|
8
|
+
|
9
|
+
Scenario: ブロックのみ配置する
|
10
|
+
When 次のブロックを配置する:
|
11
|
+
"""
|
12
|
+
%block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
|
13
|
+
%field{:name => "COLOUR"}<
|
14
|
+
white
|
15
|
+
%field{:name => "OOO"}<
|
16
|
+
turn_off
|
17
|
+
"""
|
18
|
+
And ブロックからソースコードを生成する
|
19
|
+
|
20
|
+
Then テキストエディタのプログラムは "" であること
|
21
|
+
|
22
|
+
Scenario: キャラクターとブロックを配置する
|
23
|
+
When 次のブロックを配置する:
|
24
|
+
"""
|
25
|
+
%block{:type => "character_new", :x => "21", :y => "15"}
|
26
|
+
%field{:name => "NAME"}<
|
27
|
+
car1
|
28
|
+
%statement{:name => "DO"}
|
29
|
+
%block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
|
30
|
+
%field{:name => "COLOUR"}<
|
31
|
+
white
|
32
|
+
%field{:name => "OOO"}<
|
33
|
+
turn_off
|
34
|
+
"""
|
35
|
+
And ブロックからソースコードを生成する
|
36
|
+
|
37
|
+
Then テキストエディタのプログラムは以下であること:
|
38
|
+
"""
|
39
|
+
require "smalruby"
|
40
|
+
|
41
|
+
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
42
|
+
car1.smalrubot_s1.turn_off_white_led
|
43
|
+
|
44
|
+
"""
|
45
|
+
|
46
|
+
Scenario: キャラクターとイベントとブロックを配置する
|
47
|
+
When 次のブロックを配置する:
|
48
|
+
"""
|
49
|
+
%block{:type => "character_new", :x => "21", :y => "15"}
|
50
|
+
%field{:name => "NAME"}<
|
51
|
+
car1
|
52
|
+
%statement{:name => "DO"}
|
53
|
+
%block{:type => "events_on_start"}
|
54
|
+
%statement{:name => "DO"}
|
55
|
+
%block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
|
56
|
+
%field{:name => "COLOUR"}<
|
57
|
+
blue
|
58
|
+
%field{:name => "OOO"}<
|
59
|
+
turn_on
|
60
|
+
"""
|
61
|
+
And ブロックからソースコードを生成する
|
62
|
+
|
63
|
+
Then テキストエディタのプログラムは以下であること:
|
64
|
+
"""
|
65
|
+
require "smalruby"
|
66
|
+
|
67
|
+
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
68
|
+
|
69
|
+
car1.on(:start) do
|
70
|
+
smalrubot_s1.turn_on_blue_led
|
71
|
+
end
|
72
|
+
|
73
|
+
"""
|
@@ -29,21 +29,21 @@
|
|
29
29
|
"""
|
30
30
|
<xml>
|
31
31
|
<character x="0" y="0" name="car1" costumes="car1.png" angle="0"></character>
|
32
|
-
<block type="character_new" x="0" y="0">
|
32
|
+
<block type="character_new" id="1" x="0" y="0">
|
33
33
|
<field name="NAME">car1</field>
|
34
34
|
<statement name="DO">
|
35
|
-
<block type="events_on_start">
|
35
|
+
<block type="events_on_start" id="2">
|
36
36
|
<statement name="DO">
|
37
|
-
<block type="control_loop">
|
37
|
+
<block type="control_loop" id="3">
|
38
38
|
<statement name="DO">
|
39
|
-
<block type="motion_move" inline="true">
|
39
|
+
<block type="motion_move" id="4" inline="true">
|
40
40
|
<value name="STEP">
|
41
|
-
<block type="math_number">
|
41
|
+
<block type="math_number" id="5">
|
42
42
|
<field name="NUM">10</field>
|
43
43
|
</block>
|
44
44
|
</value>
|
45
45
|
<next>
|
46
|
-
<block type="motion_turn_if_reach_wall"></block>
|
46
|
+
<block type="motion_turn_if_reach_wall" id="6"></block>
|
47
47
|
</next>
|
48
48
|
</block>
|
49
49
|
</statement>
|
@@ -72,12 +72,12 @@
|
|
72
72
|
"""
|
73
73
|
<xml>
|
74
74
|
<character x="300" y="200" name="car1" costumes="car4.png" angle="90"></character>
|
75
|
-
<block type="character_new" x="0" y="0">
|
75
|
+
<block type="character_new" id="1" x="0" y="0">
|
76
76
|
<field name="NAME">car1</field>
|
77
77
|
<statement name="DO">
|
78
|
-
<block type="motion_move" inline="true">
|
78
|
+
<block type="motion_move" id="2" inline="true">
|
79
79
|
<value name="STEP">
|
80
|
-
<block type="math_number">
|
80
|
+
<block type="math_number" id="3">
|
81
81
|
<field name="NUM">10</field>
|
82
82
|
</block>
|
83
83
|
</value>
|
@@ -26,20 +26,30 @@ describe SmalrubyEditor do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe 'configディレクトリ' do
|
29
|
-
|
29
|
+
describe 'config.yml' do
|
30
|
+
let(:path) { @home_dir.join('config', 'config.yml') }
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
it 'config.ymlを作成する' do
|
33
|
+
expect(path).to be_exist
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
describe 'database.yml' do
|
38
|
+
let(:path) { @home_dir.join('config', 'database.yml') }
|
39
|
+
|
40
|
+
it 'database.ymlを作成する' do
|
41
|
+
expect(path).to be_exist
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'database.ymlの内容が正しい' do
|
45
|
+
expect(path.read).to eq(<<-EOS.strip_heredoc)
|
46
|
+
standalone:
|
47
|
+
adapter: sqlite3
|
48
|
+
database: #{@home_dir.join('db', 'standalone.sqlite3')}
|
49
|
+
pool: 5
|
50
|
+
timeout: 5000
|
51
|
+
EOS
|
52
|
+
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require_relative 'shared/block_examples'
|
4
|
+
|
5
|
+
# rubocop:disable EmptyLines, LineLength
|
6
|
+
|
7
|
+
describe RubyToBlock::Block, 'Smalrubot S1 blocks', to_blocks: true do
|
8
|
+
parts = <<-EOS
|
9
|
+
require "smalruby"
|
10
|
+
|
11
|
+
init_hardware
|
12
|
+
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
13
|
+
|
14
|
+
car1.on(:start) do
|
15
|
+
smalrubot_s1.forward
|
16
|
+
smalrubot_s1.backward
|
17
|
+
smalrubot_s1.turn_left
|
18
|
+
smalrubot_s1.turn_right
|
19
|
+
smalrubot_s1.stop
|
20
|
+
|
21
|
+
smalrubot_s1.forward(sec: 0.5)
|
22
|
+
smalrubot_s1.backward(sec: 0.4)
|
23
|
+
smalrubot_s1.turn_left(sec: 0.3)
|
24
|
+
smalrubot_s1.turn_right(sec: 0.2)
|
25
|
+
smalrubot_s1.stop(sec: 0.1)
|
26
|
+
|
27
|
+
p(smalrubot_s1.left_ir_photoreflector_value)
|
28
|
+
p(smalrubot_s1.right_ir_photoreflector_value)
|
29
|
+
|
30
|
+
smalrubot_s1.turn_on_white_led
|
31
|
+
smalrubot_s1.turn_off_blue_led
|
32
|
+
end
|
33
|
+
car1.smalrubot_s1.forward
|
34
|
+
car1.smalrubot_s1.backward
|
35
|
+
car1.smalrubot_s1.turn_left
|
36
|
+
car1.smalrubot_s1.turn_right
|
37
|
+
car1.smalrubot_s1.stop
|
38
|
+
|
39
|
+
car1.smalrubot_s1.forward(sec: 0.5)
|
40
|
+
car1.smalrubot_s1.backward(sec: 0.4)
|
41
|
+
car1.smalrubot_s1.turn_left(sec: 0.3)
|
42
|
+
car1.smalrubot_s1.turn_right(sec: 0.2)
|
43
|
+
car1.smalrubot_s1.stop(sec: 0.1)
|
44
|
+
|
45
|
+
p(car1.smalrubot_s1.left_ir_photoreflector_value)
|
46
|
+
p(car1.smalrubot_s1.right_ir_photoreflector_value)
|
47
|
+
|
48
|
+
car1.smalrubot_s1.turn_on_white_led
|
49
|
+
car1.smalrubot_s1.turn_off_blue_led
|
50
|
+
EOS
|
51
|
+
describe compact_source_code(parts) do
|
52
|
+
_parts = parts
|
53
|
+
let(:data) { _parts }
|
54
|
+
|
55
|
+
it '結果が正しいこと' do
|
56
|
+
should eq_block_xml(<<-XML)
|
57
|
+
<character name="car1" x="0" y="0" angle="0" costumes="car1.png" />
|
58
|
+
<block type="hardware_init_hardware" />
|
59
|
+
<block type="character_new">
|
60
|
+
<field name="NAME">car1</field>
|
61
|
+
<statement name="DO">
|
62
|
+
<block type="events_on_start">
|
63
|
+
<statement name="DO">
|
64
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
65
|
+
<field name="ACTION">forward</field>
|
66
|
+
<next>
|
67
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
68
|
+
<field name="ACTION">backward</field>
|
69
|
+
<next>
|
70
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
71
|
+
<field name="ACTION">turn_left</field>
|
72
|
+
<next>
|
73
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
74
|
+
<field name="ACTION">turn_right</field>
|
75
|
+
<next>
|
76
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
77
|
+
<field name="ACTION">stop</field>
|
78
|
+
<next>
|
79
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
80
|
+
<field name="ACTION">forward</field>
|
81
|
+
<value name="SEC">
|
82
|
+
<block type="math_number">
|
83
|
+
<field name="NUM">0.5</field>
|
84
|
+
</block>
|
85
|
+
</value>
|
86
|
+
<next>
|
87
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
88
|
+
<field name="ACTION">backward</field>
|
89
|
+
<value name="SEC">
|
90
|
+
<block type="math_number">
|
91
|
+
<field name="NUM">0.4</field>
|
92
|
+
</block>
|
93
|
+
</value>
|
94
|
+
<next>
|
95
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
96
|
+
<field name="ACTION">turn_left</field>
|
97
|
+
<value name="SEC">
|
98
|
+
<block type="math_number">
|
99
|
+
<field name="NUM">0.3</field>
|
100
|
+
</block>
|
101
|
+
</value>
|
102
|
+
<next>
|
103
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
104
|
+
<field name="ACTION">turn_right</field>
|
105
|
+
<value name="SEC">
|
106
|
+
<block type="math_number">
|
107
|
+
<field name="NUM">0.2</field>
|
108
|
+
</block>
|
109
|
+
</value>
|
110
|
+
<next>
|
111
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
112
|
+
<field name="ACTION">stop</field>
|
113
|
+
<value name="SEC">
|
114
|
+
<block type="math_number">
|
115
|
+
<field name="NUM">0.1</field>
|
116
|
+
</block>
|
117
|
+
</value>
|
118
|
+
<next>
|
119
|
+
<block type="ruby_p" inline="true">
|
120
|
+
<value name="ARG">
|
121
|
+
<block type="hardware_smalrubot_s1_ir_photoreflector_value">
|
122
|
+
<field name="LOR">left</field>
|
123
|
+
</block>
|
124
|
+
</value>
|
125
|
+
<next>
|
126
|
+
<block type="ruby_p" inline="true">
|
127
|
+
<value name="ARG">
|
128
|
+
<block type="hardware_smalrubot_s1_ir_photoreflector_value">
|
129
|
+
<field name="LOR">right</field>
|
130
|
+
</block>
|
131
|
+
</value>
|
132
|
+
<next>
|
133
|
+
<block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
|
134
|
+
<field name="COLOUR">white</field>
|
135
|
+
<field name="OOO">turn_on</field>
|
136
|
+
<next>
|
137
|
+
<block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
|
138
|
+
<field name="COLOUR">blue</field>
|
139
|
+
<field name="OOO">turn_off</field>
|
140
|
+
</block>
|
141
|
+
</next>
|
142
|
+
</block>
|
143
|
+
</next>
|
144
|
+
</block>
|
145
|
+
</next>
|
146
|
+
</block>
|
147
|
+
</next>
|
148
|
+
</block>
|
149
|
+
</next>
|
150
|
+
</block>
|
151
|
+
</next>
|
152
|
+
</block>
|
153
|
+
</next>
|
154
|
+
</block>
|
155
|
+
</next>
|
156
|
+
</block>
|
157
|
+
</next>
|
158
|
+
</block>
|
159
|
+
</next>
|
160
|
+
</block>
|
161
|
+
</next>
|
162
|
+
</block>
|
163
|
+
</next>
|
164
|
+
</block>
|
165
|
+
</next>
|
166
|
+
</block>
|
167
|
+
</statement>
|
168
|
+
<next>
|
169
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
170
|
+
<field name="ACTION">forward</field>
|
171
|
+
<next>
|
172
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
173
|
+
<field name="ACTION">backward</field>
|
174
|
+
<next>
|
175
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
176
|
+
<field name="ACTION">turn_left</field>
|
177
|
+
<next>
|
178
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
179
|
+
<field name="ACTION">turn_right</field>
|
180
|
+
<next>
|
181
|
+
<block type="hardware_smalrubot_s1_action" inline="true">
|
182
|
+
<field name="ACTION">stop</field>
|
183
|
+
<next>
|
184
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
185
|
+
<field name="ACTION">forward</field>
|
186
|
+
<value name="SEC">
|
187
|
+
<block type="math_number">
|
188
|
+
<field name="NUM">0.5</field>
|
189
|
+
</block>
|
190
|
+
</value>
|
191
|
+
<next>
|
192
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
193
|
+
<field name="ACTION">backward</field>
|
194
|
+
<value name="SEC">
|
195
|
+
<block type="math_number">
|
196
|
+
<field name="NUM">0.4</field>
|
197
|
+
</block>
|
198
|
+
</value>
|
199
|
+
<next>
|
200
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
201
|
+
<field name="ACTION">turn_left</field>
|
202
|
+
<value name="SEC">
|
203
|
+
<block type="math_number">
|
204
|
+
<field name="NUM">0.3</field>
|
205
|
+
</block>
|
206
|
+
</value>
|
207
|
+
<next>
|
208
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
209
|
+
<field name="ACTION">turn_right</field>
|
210
|
+
<value name="SEC">
|
211
|
+
<block type="math_number">
|
212
|
+
<field name="NUM">0.2</field>
|
213
|
+
</block>
|
214
|
+
</value>
|
215
|
+
<next>
|
216
|
+
<block type="hardware_smalrubot_s1_action_with_sec" inline="true">
|
217
|
+
<field name="ACTION">stop</field>
|
218
|
+
<value name="SEC">
|
219
|
+
<block type="math_number">
|
220
|
+
<field name="NUM">0.1</field>
|
221
|
+
</block>
|
222
|
+
</value>
|
223
|
+
<next>
|
224
|
+
<block type="ruby_p" inline="true">
|
225
|
+
<value name="ARG">
|
226
|
+
<block type="hardware_smalrubot_s1_ir_photoreflector_value">
|
227
|
+
<field name="LOR">left</field>
|
228
|
+
</block>
|
229
|
+
</value>
|
230
|
+
<next>
|
231
|
+
<block type="ruby_p" inline="true">
|
232
|
+
<value name="ARG">
|
233
|
+
<block type="hardware_smalrubot_s1_ir_photoreflector_value">
|
234
|
+
<field name="LOR">right</field>
|
235
|
+
</block>
|
236
|
+
</value>
|
237
|
+
<next>
|
238
|
+
<block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
|
239
|
+
<field name="COLOUR">white</field>
|
240
|
+
<field name="OOO">turn_on</field>
|
241
|
+
<next>
|
242
|
+
<block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
|
243
|
+
<field name="COLOUR">blue</field>
|
244
|
+
<field name="OOO">turn_off</field>
|
245
|
+
</block>
|
246
|
+
</next>
|
247
|
+
</block>
|
248
|
+
</next>
|
249
|
+
</block>
|
250
|
+
</next>
|
251
|
+
</block>
|
252
|
+
</next>
|
253
|
+
</block>
|
254
|
+
</next>
|
255
|
+
</block>
|
256
|
+
</next>
|
257
|
+
</block>
|
258
|
+
</next>
|
259
|
+
</block>
|
260
|
+
</next>
|
261
|
+
</block>
|
262
|
+
</next>
|
263
|
+
</block>
|
264
|
+
</next>
|
265
|
+
</block>
|
266
|
+
</next>
|
267
|
+
</block>
|
268
|
+
</next>
|
269
|
+
</block>
|
270
|
+
</next>
|
271
|
+
</block>
|
272
|
+
</next>
|
273
|
+
</block>
|
274
|
+
</statement>
|
275
|
+
</block>
|
276
|
+
XML
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|