123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Blockly Generator Tests</title>
- <script src="../../blockly_uncompressed.js"></script>
- <script src="../../generators/javascript.js"></script>
- <script src="unittest_javascript.js"></script>
- <script src="../../generators/javascript/logic.js"></script>
- <script src="../../generators/javascript/loops.js"></script>
- <script src="../../generators/javascript/math.js"></script>
- <script src="../../generators/javascript/text.js"></script>
- <script src="../../generators/javascript/lists.js"></script>
- <script src="../../generators/javascript/colour.js"></script>
- <script src="../../generators/javascript/variables.js"></script>
- <script src="../../generators/javascript/procedures.js"></script>
- <script src="../../generators/python.js"></script>
- <script src="unittest_python.js"></script>
- <script src="../../generators/python/logic.js"></script>
- <script src="../../generators/python/loops.js"></script>
- <script src="../../generators/python/math.js"></script>
- <script src="../../generators/python/text.js"></script>
- <script src="../../generators/python/lists.js"></script>
- <script src="../../generators/python/colour.js"></script>
- <script src="../../generators/python/variables.js"></script>
- <script src="../../generators/python/procedures.js"></script>
- <script src="../../generators/php.js"></script>
- <script src="unittest_php.js"></script>
- <script src="../../generators/php/logic.js"></script>
- <script src="../../generators/php/loops.js"></script>
- <script src="../../generators/php/math.js"></script>
- <script src="../../generators/php/text.js"></script>
- <script src="../../generators/php/lists.js"></script>
- <script src="../../generators/php/colour.js"></script>
- <script src="../../generators/php/variables.js"></script>
- <script src="../../generators/php/procedures.js"></script>
- <script src="../../generators/lua.js"></script>
- <script src="unittest_lua.js"></script>
- <script src="../../generators/lua/logic.js"></script>
- <script src="../../generators/lua/loops.js"></script>
- <script src="../../generators/lua/math.js"></script>
- <script src="../../generators/lua/text.js"></script>
- <script src="../../generators/lua/lists.js"></script>
- <script src="../../generators/lua/colour.js"></script>
- <script src="../../generators/lua/variables.js"></script>
- <script src="../../generators/lua/procedures.js"></script>
- <script src="../../generators/dart.js"></script>
- <script src="unittest_dart.js"></script>
- <script src="../../generators/dart/logic.js"></script>
- <script src="../../generators/dart/loops.js"></script>
- <script src="../../generators/dart/math.js"></script>
- <script src="../../generators/dart/text.js"></script>
- <script src="../../generators/dart/lists.js"></script>
- <script src="../../generators/dart/colour.js"></script>
- <script src="../../generators/dart/variables.js"></script>
- <script src="../../generators/dart/procedures.js"></script>
- <script src="unittest.js"></script>
- <script src="../../msg/messages.js"></script>
- <script src="../../blocks/logic.js"></script>
- <script src="../../blocks/loops.js"></script>
- <script src="../../blocks/math.js"></script>
- <script src="../../blocks/text.js"></script>
- <script src="../../blocks/lists.js"></script>
- <script src="../../blocks/colour.js"></script>
- <script src="../../blocks/variables.js"></script>
- <script src="../../blocks/procedures.js"></script>
- <script>
- 'use strict';
- var workspace = null;
- function start() {
- workspace = Blockly.inject('blocklyDiv',
- {grid:
- {spacing: 25,
- length: 3,
- colour: '#ccc',
- snap: true},
- media: '../../media/',
- toolbox: document.getElementById('toolbox'),
- zoom: {controls: true, wheel: true}
- });
- changeIndex();
- }
- function loadXml() {
- var dropdown = document.getElementById('testUrl');
- var url = dropdown.options[dropdown.selectedIndex].value;
- if (!url) {
- url = window.prompt('Enter URL of test file.');
- if (!url) {
- return;
- }
- }
- var xmlText = fetchFile(url);
- if (xmlText !== null) {
- fromXml(xmlText);
- }
- }
- function fetchFile(xmlUrl) {
- try {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.open('GET', xmlUrl, false);
- xmlHttp.setRequestHeader('Content-Type', 'text/xml');
- xmlHttp.send('');
- } catch (e) {
- // Attempt to diagnose the problem.
- var msg = 'Error: Unable to load XML data.\n';
- if (window.location.protocol == 'file:') {
- msg += 'This may be due to a security restriction preventing\n' +
- 'access when using the file:// protocol.\n' +
- 'Use an http webserver, or a less paranoid browser.\n';
- }
- alert(msg + '\n' + e);
- return null;
- }
- return xmlHttp.responseText;
- }
- function fromXml(xmlText) {
- var output = document.getElementById('importExport');
- output.value = xmlText;
- output.scrollTop = 0;
- output.scrollLeft = 0;
- workspace.clear();
- try {
- var xmlDoc = Blockly.Xml.textToDom(xmlText);
- } catch (e) {
- alert('Error parsing XML:\n' + e);
- return;
- }
- Blockly.Xml.domToWorkspace(xmlDoc, workspace);
- }
- function setOutput(text) {
- var output = document.getElementById('importExport');
- output.value = text;
- output.focus();
- output.select();
- }
- function toXml() {
- var xmlDom = Blockly.Xml.workspaceToDom(workspace);
- var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
- xmlText = xmlText.replace(/ id="\d+"/g, '');
- setOutput(xmlText);
- }
- function toJavaScript() {
- var code = '\'use strict\';\n\n'
- code += Blockly.JavaScript.workspaceToCode(workspace);
- setOutput(code);
- }
- function toPython() {
- var code = Blockly.Python.workspaceToCode(workspace);
- setOutput(code);
- }
- function toPhp() {
- var code = Blockly.PHP.workspaceToCode(workspace);
- setOutput(code);
- }
- function toLua() {
- var code = Blockly.Lua.workspaceToCode(workspace);
- setOutput(code);
- }
- function toDart() {
- var code = Blockly.Dart.workspaceToCode(workspace);
- setOutput(code);
- }
- function changeIndex() {
- var oneBasedIndex = document.getElementById('indexing').checked;
- workspace.options.oneBasedIndex = oneBasedIndex;
- workspace.toolbox_.flyout_.workspace_.options.oneBasedIndex = oneBasedIndex;
- }
- </script>
- <style>
- html, body {
- height: 100%;
- overflow: hidden;
- }
- body {
- background-color: #fff;
- font-family: sans-serif;
- margin: 0 5px;
- }
- h1 {
- font-weight: normal;
- font-size: 140%;
- }
- #blocklyDiv {
- float: right;
- height: 95%;
- width: 69%;
- margin-top: 5px;
- }
- #importExport {
- height: 100%;
- width: 100%;
- }
- </style>
- </head>
- <body onload="start()">
- <div id="blocklyDiv"></div>
- <xml id="toolbox" style="display: none">
- <category name="Unit test" colour="65">
- <block type="unittest_main"></block>
- <block type="unittest_assertequals">
- <value name="MESSAGE">
- <block type="text">
- <field name="TEXT"></field>
- </block>
- </value>
- </block>
- <block type="unittest_assertvalue">
- <value name="MESSAGE">
- <block type="text">
- <field name="TEXT"></field>
- </block>
- </value>
- </block>
- <block type="unittest_fail"></block>
- <block type="unittest_adjustindex"></block>
- </category>
- <category name="Logic" colour="210">
- <block type="controls_if"></block>
- <block type="logic_compare"></block>
- <block type="logic_operation"></block>
- <block type="logic_negate"></block>
- <block type="logic_boolean"></block>
- <block type="logic_null"></block>
- <block type="logic_ternary"></block>
- </category>
- <category name="Loops" colour="120">
- <block type="controls_repeat_ext"></block>
- <block type="controls_whileUntil"></block>
- <block type="controls_for"></block>
- <block type="controls_forEach"></block>
- <block type="controls_flow_statements"></block>
- </category>
- <category name="Math" colour="230">
- <block type="math_number"></block>
- <block type="math_arithmetic"></block>
- <block type="math_single"></block>
- <block type="math_trig"></block>
- <block type="math_constant"></block>
- <block type="math_number_property"></block>
- <block type="math_round"></block>
- <block type="math_on_list"></block>
- <block type="math_modulo"></block>
- <block type="math_constrain"></block>
- <block type="math_random_int"></block>
- <block type="math_random_float"></block>
- </category>
- <category name="Text" colour="160">
- <block type="text"></block>
- <block type="text_join"></block>
- <block type="text_append"></block>
- <block type="text_length"></block>
- <block type="text_isEmpty"></block>
- <block type="text_indexOf"></block>
- <block type="text_charAt"></block>
- <block type="text_getSubstring"></block>
- <block type="text_changeCase"></block>
- <block type="text_trim"></block>
- <block type="text_print"></block>
- <block type="text_prompt_ext"></block>
- </category>
- <category name="Lists" colour="260">
- <block type="lists_create_empty"></block>
- <block type="lists_create_with"></block>
- <block type="lists_repeat"></block>
- <block type="lists_length"></block>
- <block type="lists_isEmpty"></block>
- <block type="lists_indexOf"></block>
- <block type="lists_getIndex"></block>
- <block type="lists_setIndex"></block>
- <block type="lists_getSublist"></block>
- <block type="lists_sort"></block>
- <block type="lists_split"></block>
- </category>
- <category name="Colour" colour="20">
- <block type="colour_picker"></block>
- <block type="colour_random"></block>
- <block type="colour_rgb"></block>
- <block type="colour_blend"></block>
- </category>
- <sep></sep>
- <category name="Variables" colour="330" custom="VARIABLE"></category>
- <category name="Functions" colour="290" custom="PROCEDURE"></category>
- </xml>
- <table height="95%" width="30%"><tr><td valign="top">
- <h1>Blockly Generator Tests</h1>
- <p>
- <select id="testUrl">
- <option value="logic.xml">Logic</option>
- <option value="loops1.xml">Loops 1 (repeat, while, foreach)</option>
- <option value="loops2.xml">Loops 2 (count)</option>
- <option value="loops3.xml">Loops 3 (continue, break)</option>
- <option value="math.xml">Math</option>
- <option value="text.xml">Text</option>
- <option value="lists.xml">Lists</option>
- <option value="colour.xml">Colour</option>
- <option value="variables.xml">Variables</option>
- <option value="functions.xml">Functions</option>
- <option value="">Other...</option>
- </select>
- <input type="button" value="Load" onclick="loadXml()">
- </p>
- <p>
- <input id="indexing" type="checkbox" onchange="changeIndex()" checked>
- <label for="indexing">Generate with one-based indexing</label>
- </p>
- <p>
- Generate:
- <input type="button" value="XML" onclick="toXml()">
- <input type="button" value="JavaScript" onclick="toJavaScript()">
- <input type="button" value="Python" onclick="toPython()">
- <input type="button" value="PHP" onclick="toPhp()">
- <input type="button" value="Lua" onclick="toLua()">
- <input type="button" value="Dart" onclick="toDart()">
- </p>
- </td></tr><tr><td height="99%">
- <textarea id="importExport" readonly="readonly" wrap="off"></textarea>
- </td></tr></table>
- </body>
- </html>
|