From a6b66358a9f2ef6c9c0d176362092286c3d10910 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 19 Nov 2017 01:00:12 +0300 Subject: [PATCH] added variables in action syntax... Signed-off-by: Alex A. Naanou --- actions.js | 15 +++++++++------ package.json | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/actions.js b/actions.js index d7af0dd..8c4d28a 100755 --- a/actions.js +++ b/actions.js @@ -343,11 +343,13 @@ function(func){ } +// NOTE: identifiers are resolved as attributes of the context... // XXX this is the same as ImageGrid's keyboard.parseActionCall(..), reuse // in a logical manner... var parseStringAction = module.parseStringAction = -function(txt){ +function(txt, context){ + context = context || this // split off the doc... var c = txt.split('--') var doc = (c[1] || '').trim() @@ -360,8 +362,7 @@ function(txt){ action = no_default ? action.slice(0, -1) : action // parse arguments... - var args = JSON.parse('['+( - ((c[1] || '') + var args = ((c[1] || '') .match(RegExp([ // strings... '"[^"]*"', @@ -380,14 +381,16 @@ function(txt){ '\\d+\\.\\d+|\\d+', // identifiers... - // XXX not JSON compatible... - //'[a-zA-Z$@#_][a-zA-Z0-9$@#_]*', + '[a-zA-Z$@#_][a-zA-Z0-9$@#_]*', // null... 'null' ].join('|'), 'gm')) || []) - .join(','))+']') + .map(function(e){ + return /^[a-zA-Z$@#_][a-zA-Z0-9$@#_]*$/.test(e) ? + context[e] + : JSON.parse(e) }) return { action: action, diff --git a/package.json b/package.json index 48fb350..8d11c3e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-actions", - "version": "3.9.0", + "version": "3.10.0", "description": "", "main": "actions.js", "scripts": {