From 55833944636869b1ad1bc0f7de129ded4291f76c Mon Sep 17 00:00:00 2001 From: cawoodm Date: Wed, 26 Dec 2012 00:39:47 +0100 Subject: [PATCH 1/2] Provide a filename-only placeholder for exec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Say we want to run unit-tests when the current file `foo.js` is saved. Our tests require that the following command is run: `node tests\test-foo.js` In order for this to work we need a `${filename}` placeholder which returns only `foo.js` and not the full path (as `${file}` currently does). ```javascript   "exec": {     "afterSave": {       "*.js": "node tests/test-${filename}.js"     }   } ``` --- client/scripts/scripted/exec/param-resolver.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/scripts/scripted/exec/param-resolver.js b/client/scripts/scripted/exec/param-resolver.js index a7c55ddc..e6b2d3a6 100644 --- a/client/scripts/scripted/exec/param-resolver.js +++ b/client/scripts/scripted/exec/param-resolver.js @@ -83,6 +83,11 @@ function forEditor(editor) { return editor.getFilePath(); }); + def("${filename}", function() { + var p = editor.getFilePath(); + return p.substring(p.lastIndexOf('/')+1); + }); + def("${dir}", getDir); def("${projectDir}", function () { From dfbbd33fbabe0fcc034c8dc67e4063efcfc8c98b Mon Sep 17 00:00:00 2001 From: cawoodm Date: Sun, 30 Dec 2012 11:09:10 +0100 Subject: [PATCH 2/2] Renamed ${fileName}. Added ${fileBase} ${filePath} Renamed ${filename} to ${fileName} Added ${fileBase} and ${filePath} --- client/scripts/scripted/exec/param-resolver.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client/scripts/scripted/exec/param-resolver.js b/client/scripts/scripted/exec/param-resolver.js index e6b2d3a6..1f0dfe34 100644 --- a/client/scripts/scripted/exec/param-resolver.js +++ b/client/scripts/scripted/exec/param-resolver.js @@ -83,11 +83,25 @@ function forEditor(editor) { return editor.getFilePath(); }); - def("${filename}", function() { + // Returns 'hello.js' from '/path/project/sub/helloworld.js' + def("${fileName}", function() { var p = editor.getFilePath(); return p.substring(p.lastIndexOf('/')+1); }); + // Returns 'sub/hello.js' from '/path/project/sub/helloworld.js' + def("${filePath}", function() { + var p = editor.getFilePath(); + return p.substring((window.fsroot || getDir()).length+1); + }); + + // Returns 'hello' from '/path/project/sub/helloworld.js' + def("${fileBase}", function() { + var p = editor.getFilePath(); + p = p.substring(p.lastIndexOf('/')+1); + return p.substring(0, p.lastIndexOf('.')); + }); + def("${dir}", getDir); def("${projectDir}", function () {