Files
kJS.tmbundle/Commands/Run Javascript.tmCommand
T
2009-02-25 11:18:39 -05:00

74 lines
1.9 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;input type="button" value="Show Code" onclick="var c=document.getElementById('code');c.style.display==''?c.style.display='none':c.style.display='';" /&gt;
&lt;pre id="code" style="display:none"&gt;
$YOURCODE
&lt;/pre&gt;
&lt;pre id="log"&gt;
&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>