New blocks text_count, text_replace, and text_reverse (#830)

Includes generators for all languages and units tests on those generators.
This commit is contained in:
Tim Dawborn
2017-01-21 11:08:27 +11:00
committed by Andrew n marshall
parent fb0f1b05dd
commit 34750bccd8
12 changed files with 935 additions and 9 deletions

View File

@@ -251,3 +251,30 @@ Blockly.Python['text_prompt_ext'] = function(block) {
};
Blockly.Python['text_prompt'] = Blockly.Python['text_prompt_ext'];
Blockly.Python['text_count'] = function(block) {
var text = Blockly.Python.valueToCode(block, 'TEXT',
Blockly.Python.ORDER_MEMBER) || '\'\'';
var sub = Blockly.Python.valueToCode(block, 'SUB',
Blockly.Python.ORDER_NONE) || '\'\'';
var code = text + '.count(' + sub + ')';
return [code, Blockly.Python.ORDER_MEMBER];
};
Blockly.Python['text_replace'] = function(block) {
var text = Blockly.Python.valueToCode(block, 'TEXT',
Blockly.Python.ORDER_MEMBER) || '\'\'';
var from = Blockly.Python.valueToCode(block, 'FROM',
Blockly.Python.ORDER_NONE) || '\'\'';
var to = Blockly.Python.valueToCode(block, 'TO',
Blockly.Python.ORDER_NONE) || '\'\'';
var code = text + '.replace(' + from + ', ' + to + ')';
return [code, Blockly.Python.ORDER_MEMBER];
};
Blockly.Python['text_reverse'] = function(block) {
var text = Blockly.Python.valueToCode(block, 'TEXT',
Blockly.Python.ORDER_MEMBER) || '\'\'';
var code = text + '[::-1]';
return [code, Blockly.Python.ORDER_MEMBER];
};