dict.js 708 B

1234567891011121314151617181920
  1. 'use strict';
  2. goog.provide('Blockly.Python.dict');
  3. goog.require('Blockly.Python');
  4. Blockly.Python.dicts_create_with = function(block) {
  5. var value_keys = Blockly.Python.valueToCode(block, 'keys', Blockly. Python.ORDER_ATOMIC);
  6. // TODO: Assemble Python into code variable.
  7. var code = new Array(block.itemCount_);
  8. for (var n = 1; n <= block.itemCount_; n++) {
  9. var key = Blockly.Python.quote_(block.getFieldValue('KEY' + n));
  10. var value = Blockly.Python.valueToCode(block, 'VALUE' + n,
  11. Blockly.Python.ORDER_NONE) || '___';
  12. code[n-1] = key +": "+ value;
  13. }
  14. code = '{' + code.join(', ') + '}';
  15. return [code, Blockly.Python.ORDER_ATOMIC];
  16. };