Skip to content

Commit bfbf467

Browse files
committed
Merge branch 'adamcarheden-write_line'
2 parents ba8cef2 + c6afb2d commit bfbf467

15 files changed

+125
-38
lines changed

src/blocks/simple/blocks.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ Blockly.Blocks['simple_text_write'] = {
3838
};
3939

4040

41+
/**
42+
* Write line.
43+
*/
44+
Blockly.Blocks['simple_text_write_line'] = {
45+
init: function() {
46+
this.setHelpUrl('');
47+
this.setColour(290);
48+
this.appendValueInput('text')
49+
.setCheck('String')
50+
.appendField(i18t('writeLine('));
51+
this.appendDummyInput()
52+
.appendField(')');
53+
this.setPreviousStatement(true, ['Number', 'String']);
54+
this.setNextStatement(true, ['Number', 'String']);
55+
this.setTooltip(i18t('Writes the text on its own line on the screen.'));
56+
},
57+
};
58+
59+
4160
/**
4261
* Draw circle.
4362
*/

src/blocks/simple/javascript.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ Blockly.JavaScript['simple_text_write'] = function(block) {
3131
};
3232

3333

34+
/**
35+
* Write line.
36+
* @param {!Blockly.block} block
37+
* @return {string}
38+
*/
39+
Blockly.JavaScript['simple_text_write_line'] = function(block) {
40+
let text = Blockly.JavaScript.valueToCode(block, 'text',
41+
Blockly.JavaScript.ORDER_ATOMIC);
42+
return 'command.writeLine(' + text + ');\n';
43+
};
44+
45+
3446
/**
3547
* Draw circle.
3648
* @param {!Blockly.block} block

src/blocks/simple/toolbox.soy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
<block type="text"><field name="TEXT"></field></block>
3333
</value>
3434
</block>
35+
<block type="simple_text_write_line">
36+
<value name="text">
37+
<block type="text"><field name="TEXT"></field></block>
38+
</value>
39+
</block>
3540
</category>
3641

3742
<category name="Draw" colour="260">

src/config/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ cwc.config.Sample = {
119119
/**
120120
* @return {string}
121121
*/
122-
cwc.config.Version = '5.7.28';
122+
cwc.config.Version = '5.7.29';

src/frameworks/simple/command.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ cwc.framework.simple.Command.prototype.write = function(text) {
5959
this.addNode_(goog.dom.createTextNode(text));
6060
};
6161

62+
/**
63+
* Writes a text and line break on screen.
64+
* @param {string} text
65+
* @export
66+
*/
67+
cwc.framework.simple.Command.prototype.writeLine = function(text) {
68+
this.addNode_(goog.dom.createTextNode(text));
69+
this.addNode_(goog.dom.createElement('br'));
70+
};
6271

6372
/**
6473
* @param {string} title
@@ -105,6 +114,7 @@ cwc.framework.simple.Command.prototype.mapGlobal = function() {
105114
}
106115
window['command'] = {
107116
'write': this.write.bind(this),
117+
'writeLine': this.writeLine.bind(this),
108118
'showAlert': this.showAlert.bind(this),
109119
'showPrompt': this.showPrompt.bind(this),
110120
'showActionCancel': this.showActionCancel.bind(this),

test/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'describe': true,
88
'expect': true,
99
'getTestBlockCode': true,
10+
'getTestBlockWorkspace': true,
1011
'getTestBuffer': true,
1112
'it': true,
1213
'loadExampleFile': true,

test/block_tests/general_block_test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020

2121

2222
describe('General Blocks', function() {
23-
document.body.insertAdjacentHTML('afterbegin',
24-
'<div id="test-workspace"></div>');
25-
window['i18t'] = function(msg) {
26-
return msg;
27-
};
28-
23+
getTestBlockWorkspace();
2924
let blockPrefix = 'general_';
3025
let blocks = [];
3126
for (let block in Blockly.Blocks) {

test/block_tests/ev3_block_test.js renamed to test/block_tests/lego_ev3_block_test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020

2121

2222
describe('EV3 Blocks', function() {
23-
document.body.insertAdjacentHTML('afterbegin',
24-
'<div id="test-workspace"></div>');
25-
window['i18t'] = function(msg) {
26-
return msg;
27-
};
28-
23+
getTestBlockWorkspace();
2924
let blockPrefix = 'ev3_';
3025
let blocks = [];
3126
for (let block in Blockly.Blocks) {

test/block_tests/mbot_block_test.js renamed to test/block_tests/makeblock_mbot_block_test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020

2121

2222
describe('mBot Blocks', function() {
23-
document.body.insertAdjacentHTML('afterbegin',
24-
'<div id="test-workspace"></div>');
25-
window['i18t'] = function(msg) {
26-
return msg;
27-
};
28-
23+
getTestBlockWorkspace();
2924
let blockPrefix = 'mbot_';
3025
let blocks = [];
3126
for (let block in Blockly.Blocks) {

test/block_tests/phaser_block_test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020

2121

2222
describe('Phaser Blocks', function() {
23-
document.body.insertAdjacentHTML('afterbegin',
24-
'<div id="test-workspace"></div>');
25-
window['i18t'] = function(msg) {
26-
return msg;
27-
};
28-
23+
getTestBlockWorkspace();
2924
let blockPrefix = 'phaser_';
3025
let blocks = [];
3126
for (let block in Blockly.Blocks) {

0 commit comments

Comments
 (0)