-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve the way variables are used while maintaining backward compatibility #241
Comments
Feature usable now in cutting edge version - https://github.com/kelaberetiv/TagUI#set-up Update of readme & samples after this code enters packaged release, otherwise confusing. Hey @adegard @Aussiroth @lohvht I thought this is a cool feature and makes variables easier :) |
following additions can semi-work to throw error gracefully if the variable is not yet defined. but it has execution issues for example in 9_misc workflow. even though for loop only until 6, during execution it goes directly to 7 and throws error. dropping exploration of graceful exit in favor of maintaining automation robustness and compatibility of existing scripts. tagui_parse.php function parse_variables($script_line) { // `variable` --> '+variable+'
$quote_token = "'+check_variable('"; // token to alternate replacements for '+variable+'
for ($char_counter = 0; $char_counter < strlen($script_line); $char_counter++) {
if (substr($script_line,$char_counter,1) == "`") {
$script_line = substr_replace($script_line,$quote_token,$char_counter,1);
if ($quote_token == "'+check_variable('") $quote_token = "')+'"; else $quote_token = "'+check_variable('";
}
} return $script_line;} tagui_header.js // variable check for graceful exit when `variable` is used and undefined
function check_variable(variable_to_check) {if (check_variable_exit == true) return 'undefined';
try {return eval(variable_to_check);} catch(e) {check_variable_exit = true; // prevent 2X error messages
casper.echo('ERROR - variable ' + variable_to_check + ' is undefined, define it before using').exit();}} updated - issue happens with eval(), |
Hi @kensoh |
Hi Arnaud, I see... Ok got it, thanks for your feedback! |
In TagUI, whenever text is expected and user wants to use a variable in place of static text, the current way to do it is using
'+variable_name+'
. This works because the first ' essentially escapes the text mode to go into JavaScript programming language mode to reference the variable, followed by the second ' to go back to text mode. The + is JavaScript's way of concatenating strings. See below example -The old way above works, but is non-standard, hard to write and hard to read. By using backticks ` (the symbol besides the number 1 on keyboard), it can be made easier to type and read. Of course, backticks may have conflict with object repository or datatable definitions. But as long as there isn't such repository / datatable definition, TagUI can interpret the use of `variable` as '+variable+'
This issue is to make this improvement while keeping existing scripts backward compatible.
The text was updated successfully, but these errors were encountered: