Files
kJS.tmbundle/Commands/Run Javascript.tmCommand
T
Thomas Aylott d2bc10e4b3 new command: run javascript.
runs your current selection or document in an html output window. You can do console messages and check the html output window's console.
includes support for window.alert and window.confirm from Hans-Jörg Bibiko
properly corrects for line numbers in error messages
2009-02-15 08:14:36 +00:00

71 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env bash
. "$TM_SUPPORT_PATH/lib/webpreview.sh"
html_header "Javascript Runner" "Open Web Inspector for log"
YOURCODE=`cat`
cat &lt;&lt;HTML
&lt;script&gt;
(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); }; })();
&lt;/script&gt;
&lt;pre id="log"&gt;
$YOURCODE
&lt;script&gt;
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||'')
};
&lt;/script&gt;&lt;/pre&gt;
HTML
html_footer
</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>@r</string>
<key>name</key>
<string>Run Javascript</string>
<key>output</key>
<string>showAsHTML</string>
<key>scope</key>
<string>source.js</string>
<key>uuid</key>
<string>EA26235D-2A24-4ED4-8BC2-5424B9E80CFF</string>
</dict>
</plist>