Created
March 12, 2009 15:54
-
-
Save satyr/78137 to your computer and use it in GitHub Desktop.
Executes LL codes via lleval API <http://blog.livedoor.jp/dankogai/archives/51190474.html>.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Name = 'lleval', | |
Icon = 'http://www.dan.co.jp/favicon.ico', | |
Langs = [CmdUtils.makeSugg(name, null, ext) for each([name, ext] in Iterator({ | |
Perl: 'pl', | |
Ruby: 'rb', | |
Python: 'py', | |
JavaScript: 'js', | |
Gosh: 'scm', | |
PHP: 'php', | |
Perl6: 'perl6', | |
Basic: 'bas', | |
ELisp: 'el', | |
Clisp: 'lsp', | |
Haskell: 'hs', | |
Io: 'io', | |
Lua: 'lua', | |
OCaml: 'ml', | |
PostScript: 'ps', | |
TCL: 'tcl', | |
}))], | |
Style = <style><![CDATA[ | |
pre {padding-left:1em} | |
table {margin:0 1em 1em} | |
th {text-align:left} | |
]]></style>; | |
CmdUtils.CreateCommand({ | |
name: Name, | |
icon: Icon, | |
takes: {code: noun_arb_text}, | |
modifiers: {'#': {_name: 'lang', | |
default: function() Langs[0], | |
suggest: function(txt, htm, cb, sx){ | |
if(sx) return []; | |
try { var re = RegExp(txt, 'i') } catch(_){ re = /^/ } | |
var ss = Langs.filter(function(s) re.test(s.text +' '+ s.summary)), | |
[s] = ss; | |
if(s) this.default = function() s; | |
return s ? ss : Langs; | |
}}}, | |
description: 'Abuses '+ 'lleval.cgi'. | |
link('http://blog.livedoor.jp/dankogai/archives/51190474.html') +'.', | |
help: 'Execute to copy/insert the result.', | |
execute: function(dob, mod){ | |
this._eval(dob, mod, function({stdout, stderr}){ | |
var res = stdout || stderr; | |
CmdUtils[(CmdUtils.getSelection() | |
? 'setSelection' | |
: 'copyToClipboard')](res); | |
}); | |
}, | |
preview: function(pbl, dob, mod){ | |
this._eval(dob, mod, function(res){ | |
var pre = <pre>{res.stdout || ''}</pre>, table = <table/>; | |
delete res.stdout; | |
for(var k in res) table.* += <tr><th>{k}</th><td>{res[k]}</td></tr>; | |
pbl.innerHTML = Style + pre + table; | |
}, pbl); | |
}, | |
_eval: function({text: code}, {'#': {data: lang}}, fun, pbl){ | |
if(!code) return; | |
var params = { | |
url: 'http://api.dan.co.jp/lleval.cgi', | |
data: {c: '_', s: code, l: lang}, | |
success: function(jsonp){ fun(Utils.decodeJson(/{[\s\S]+}/(jsonp))) }, | |
error: this._ajaxerr }; | |
pbl ? CmdUtils.previewAjax(pbl, params) : jQuery.ajax(params); | |
}, | |
_ajaxerr: function(x) displayMessage({ | |
icon: Icon, title: 'Ajax Error', | |
text: x.status +' '+ x.statusText}), | |
previewDelay: 666, | |
author: 'satyr'.link('http://d.hatena.ne.jp/murky-satyr'), license: 'MIT', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment