Changeset 1963126
- Timestamp:
- 10/25/2018 07:32:24 PM (7 years ago)
- Location:
- easycoder/trunk
- Files:
-
- 1 added
- 1 deleted
- 6 edited
-
easycoder-temp.js (deleted)
-
easycoder-template.js (added)
-
easycoder.js (modified) (1 diff)
-
easycoder.php (modified) (4 diffs)
-
plugin-browser.js (modified) (3 diffs)
-
plugin-json.js (modified) (4 diffs)
-
readme.txt (modified) (1 diff)
-
rest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
easycoder/trunk/easycoder.js
r1960099 r1963126 2620 2620 return c + EasyCoder_Tokenise.findStrings({ original, line: tail, inComment, inQuote: false }); 2621 2621 } 2622 if (!inComment && !inQuote && !c.match(/[A-z0-9_\-\ ]/)) {2622 if (!inComment && !inQuote && !c.match(/[A-z0-9_\-\+\*\/\-\ ]/)) { 2623 2623 if (c == "'" || c == '"') { 2624 2624 throw new Error(`Bad syntax in "${original}":\nStrings in EasyCoder must be enclosed in backticks.`); -
easycoder/trunk/easycoder.php
r1960099 r1963126 4 4 * Plugin URI: https://easycoder.software 5 5 * Description: Control the appearance and behavior of your posts and pages by embedding simple English-like scripts, without the need to learn JavaScript. 6 * Version: 2.1. 06 * Version: 2.1.1 7 7 * Author: EasyCoder Software 8 * Author URI: https://easycoder.software 8 9 */ 9 10 … … 25 26 $current = getcwd(); 26 27 while (true) { 27 // Get the last item -the name of the current directory28 // Get the last item; the name of the current directory 28 29 $slash = strrpos($current, '/'); 29 30 // Something went wrong, so abandon this … … 38 39 $current = substr($current, 0, $slash); 39 40 } 40 // Get the EC template file - usesrelative addressing41 $text = file_get_contents($backup . '../wp-content/plugins/easycoder/easycoder-temp .js');41 // Get the EC template file using relative addressing 42 $text = file_get_contents($backup . '../wp-content/plugins/easycoder/easycoder-template.js'); 42 43 // Replace the "/rest/" template variables 43 44 $text = str_replace('/rest/', $restURI, $text); … … 60 61 // The EasyCoder library 61 62 function easycoder_enqueue_script() { 62 wp_enqueue_script('easycoder_script', plugin_dir_url( __FILE__ ) . 'easycoder-min.js', array(), '2.1.0'); 63 wp_enqueue_script('easycoder_script', 64 plugin_dir_url( __FILE__ ) . 'easycoder-min.js', array(), '2.1.1'); 63 65 } 64 66 -
easycoder/trunk/plugin-browser.js
r1960099 r1963126 88 88 const command = program[program.pc]; 89 89 const cssId = program.value.evaluate(program, command.cssId).content; 90 const element = document.getElementById(cssId); 91 if (!element) { 92 program.error.runtimeError(command.lino, 'No such element: ' + cssId); 90 try { 91 const element = document.getElementById(cssId); 92 if (!element) { 93 throw Error('No such element: ' + cssId); 94 } 95 } catch (err) { 96 console.log(err.message); 97 program.error.runtimeError(command.lino, err.message); 93 98 } 94 99 const target = program.getSymbolRecord(command.symbol); … … 812 817 compiler.next(); 813 818 const styleName = compiler.getValue(); 819 var type = 'setStyle' 820 var symbolName = ''; 814 821 if (compiler.tokenIs('of')) { 815 822 compiler.next(); 816 if (compiler.isSymbol()) { 817 const symbolName = compiler.getToken(); 823 if (compiler.getToken() === 'body') { 824 type = 'setBodyStyle'; 825 } else if (compiler.isSymbol()) { 826 symbolName = compiler.getToken(); 827 } 828 compiler.next(); 829 if (compiler.tokenIs('to')) { 818 830 compiler.next(); 819 if (compiler.tokenIs('to')) { 820 compiler.next(); 821 const styleValue = compiler.getValue(); 822 if (styleValue) { 823 compiler.addCommand({ 824 domain: 'browser', 825 keyword: 'set', 826 lino, 827 type: 'setStyle', 828 symbolName, 829 styleName, 830 styleValue 831 }); 832 return true; 833 } 831 const styleValue = compiler.getValue(); 832 if (styleValue) { 833 compiler.addCommand({ 834 domain: 'browser', 835 keyword: 'set', 836 lino, 837 type, 838 symbolName, 839 styleName, 840 styleValue 841 }); 842 return true; 834 843 } 835 844 } … … 927 936 styles[command.styleName.content] = styleValue.content; 928 937 Object.assign(styleTarget.style, styles); 938 break; 939 case 'setBodyStyle': 940 const bodyStyleValue = program.value.evaluate(program, command.styleValue); 941 document.body.style[command.styleName.content] = bodyStyleValue.content; 929 942 break; 930 943 case 'setTitle': -
easycoder/trunk/plugin-json.js
r1960099 r1963126 74 74 case 'set': 75 75 compiler.next(); 76 if (compiler.tokenIs('item')) { 77 compiler.next(); 78 const name = compiler.getValue(); 79 if (compiler.tokenIs('of')) { 80 compiler.next(); 81 if (compiler.isSymbol()) { 82 const targetRecord = compiler.getSymbolRecord(); 83 if (targetRecord.keyword === 'variable') { 84 compiler.next(); 85 if (compiler.tokenIs('to')) { 86 compiler.next(); 87 const value = compiler.getValue(); 88 compiler.addCommand({ 89 domain: 'json', 90 keyword: 'json', 91 lino, 92 request: 'setItem', 93 target: targetRecord.name, 94 name, 95 value 96 }); 97 return true; 98 } 99 } 100 } 101 } 102 return null; 103 } 76 104 if (compiler.isSymbol()) { 77 105 const targetRecord = compiler.getSymbolRecord(); 78 if (targetRecord.keyword === 'select') { 106 if (targetRecord.keyword === 'variable') { 107 compiler.next(); 108 if (compiler.tokenIs('to')) { 109 compiler.next(); 110 const type = compiler.getToken(); 111 if ('["array","object"]'.includes(type)) { 112 compiler.next(); 113 compiler.addCommand({ 114 domain: 'json', 115 keyword: 'json', 116 lino, 117 request: 'setVariable', 118 target: targetRecord.name, 119 type 120 }); 121 return true; 122 } 123 } 124 } else if (targetRecord.keyword === 'select') { 79 125 compiler.next(); 80 126 if (compiler.tokenIs('from')) { … … 158 204 }; 159 205 break; 206 case 'setVariable': 207 targetRecord = program.getSymbolRecord(command.target); 208 const content = (command.type === 'array') ? '[]' : '{}'; 209 targetRecord.value[targetRecord.index] = { 210 type: 'constant', 211 numeric: false, 212 content 213 }; 214 break; 215 case 'setItem': 216 targetRecord = program.getSymbolRecord(command.target); 217 const targetValue = targetRecord.value[targetRecord.index]; 218 const targetItem = JSON.parse(program.getValue(targetValue)); 219 const itemName = program.getValue(command.name); 220 const itemValue = program.getValue(command.value); 221 targetItem[itemName] = itemValue; 222 targetRecord.value[targetRecord.index] = { 223 type: 'constant', 224 numeric: false, 225 content: JSON.stringify(targetItem) 226 }; 227 break; 160 228 case 'setList': 161 229 // The source is assumed to be a JSON array … … 226 294 } 227 295 } 228 } 229 compiler.addWarning('Unrecognised syntax in \'rest\''); 296 break; 297 case 'post': 298 compiler.next(); 299 var name = null; 300 var value = null; 301 if (compiler.tokenIs('to')) { 302 compiler.next(); 303 } else { 304 value = compiler.getValue(); 305 if (compiler.tokenIs('to')) { 306 compiler.next(); 307 } else { 308 break; 309 } 310 name = compiler.getValue(); 311 if (compiler.tokenIs('at')) { 312 compiler.next(); 313 } else { 314 break; 315 } 316 } 317 const url = compiler.getValue(); 318 compiler.addCommand({ 319 domain: 'json', 320 keyword: 'rest', 321 lino, 322 request: 'post', 323 value, 324 name, 325 url 326 }); 327 return true; 328 } 230 329 return false; 231 330 }, … … 233 332 run: (program) => { 234 333 const command = program[program.pc]; 334 program.ajaxCommand = command; 335 const url = program.getValue(command.url); 336 const xhttp = new XMLHttpRequest(); 337 xhttp.onreadystatechange = function () { 338 // console.log(`readyState:${xhttp.readyState}, status:${xhttp.status}`); 339 if (xhttp.readyState === 4) { 340 const command = program.ajaxCommand; 341 switch (this.status) { 342 case 200: 343 case 201: 344 if (command.request === 'get') { 345 const targetRecord = program.getSymbolRecord(command.target); 346 targetRecord.value[targetRecord.index] = { 347 type: 'constant', 348 numeric: false, 349 content: this.responseText 350 }; 351 } 352 program.run(command.pc + 1); 353 break; 354 case 0: 355 break; 356 default: 357 const lino = command.lino + 1; 358 const error = JSON.parse(this.responseText ? this.responseText : '{}'); 359 alert(`HTTP error ${this.status} at line ${lino}:\n${error.message}`); 360 break; 361 } 362 } 363 }; 235 364 switch (command.request) { 236 365 case 'get': 237 program.ajaxCommand = command;238 const xhttp = new XMLHttpRequest();239 xhttp.onreadystatechange = function () {240 if (this.readyState === 4 && this.status === 200) {241 const command = program.ajaxCommand;242 const targetRecord = program.getSymbolRecord(command.target);243 targetRecord.value[targetRecord.index] = {244 type: 'constant',245 numeric: false,246 content: this.responseText247 };248 program.run(command.pc + 1);249 }250 };251 const url = program.getValue(command.url);252 366 xhttp.open('GET', url, true); 253 367 xhttp.send(); 368 break; 369 case 'post': 370 const name = encodeURI(program.getValue(command.name)); 371 const value = encodeURI(program.getValue(command.value)); 372 xhttp.open('POST', url, true); 373 xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); 374 // console.log(`Send 'name=${name}&value=${value}' to\n${url}`); 375 xhttp.send(`name=${name}&value=${value}`); 376 break; 254 377 } 255 378 return 0; -
easycoder/trunk/readme.txt
r1960099 r1963126 47 47 == Changelog == 48 48 49 = 2.1.1 25-oct-2018 = 50 * Added some more REST functions and a REST server. 51 49 52 = 2.1.0 21-oct-2018 = 50 53 * Change from curly braces to backticks. -
easycoder/trunk/rest.php
r1958621 r1963126 1 1 <?php 2 // REST server2 // REST server 3 3 4 4 // Set the error and exception handlers.
Note: See TracChangeset
for help on using the changeset viewer.