From d2bc10e4b3db75275ec99d91a6a270b19eabdbdb Mon Sep 17 00:00:00 2001 From: Thomas Aylott Date: Sun, 15 Feb 2009 03:03:18 -0500 Subject: [PATCH] =?UTF-8?q?new=20command:=20run=20javascript.=20runs=20you?= =?UTF-8?q?r=20current=20selection=20or=20document=20in=20an=20html=20outp?= =?UTF-8?q?ut=20window.=20You=20can=20do=20console=20messages=20and=20chec?= =?UTF-8?q?k=20the=20html=20output=20window's=20console.=20includes=20supp?= =?UTF-8?q?ort=20for=20window.alert=20and=20window.confirm=20from=20Hans-J?= =?UTF-8?q?=C3=B6rg=20Bibiko=20properly=20corrects=20for=20line=20numbers?= =?UTF-8?q?=20in=20error=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Commands/Run Javascript.tmCommand | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Commands/Run Javascript.tmCommand diff --git a/Commands/Run Javascript.tmCommand b/Commands/Run Javascript.tmCommand new file mode 100644 index 0000000..65690d9 --- /dev/null +++ b/Commands/Run Javascript.tmCommand @@ -0,0 +1,70 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env bash +. "$TM_SUPPORT_PATH/lib/webpreview.sh" +html_header "Javascript Runner" "Open Web Inspector for log" + +YOURCODE=`cat` + +cat <<HTML +<script> +(function(){try{ + + function e_sh(s){ + return s + .toString() + .replace(/\x27/g,"’") + .replace(/\"/g,'\\\"') + ; + }; + + window.alert = function(s){ + TextMate.system('"$DIALOG" -e -p \'{messageTitle="JavaScript";informativeText="'+e_sh(s)+'";}\'', null); + }; + + var __TM_confirm_Status; + window.confirm = function(s){ + TextMate.system('"$DIALOG" -e -p \'{messageTitle="JavaScript";informativeText="'+e_sh(s)+'";buttonTitles=("OK","Cancel");}\'', null) + .onreadoutput = function(s){ __TM_confirm_Status = s != 1; }; + return(__TM_confirm_Status); + }; + +}catch(e){ console.log(e.message); }; })(); +</script> +<pre id="log"> +$YOURCODE +<script> +try{throw {}}catch(e){ window.__line=(e.line||0) + 3 }; +try{ +/*---- YOUR CODE ----*/ +$YOURCODE +/*---- /YOUR CODE ----*/ +}catch(e){ + console.log(e); + var __line_offset = ${TM_INPUT_START_LINE:-1}; + alert("$TM_FILEPATH:" + ((e.line||1) - __line + __line_offset) +"\n"+ e.message||'') +}; +</script></pre> +HTML + +html_footer + + input + selection + keyEquivalent + @r + name + Run Javascript + output + showAsHTML + scope + source.js + uuid + EA26235D-2A24-4ED4-8BC2-5424B9E80CFF + +