Created
April 15, 2010 12:57
-
-
Save kayakaya/367055 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'webrick' | |
require 'tempfile' | |
$EDITOR = '/Users/kayakaya/Applications/Emacs.app/Contents/MacOS/bin/emacsclient' | |
$PORT = 9292 | |
server = WEBrick::HTTPServer.new(:Port => $PORT) | |
trap('INT') { server.shutdown } | |
server.mount_proc('/status') do |req, res| | |
res.status = 200 | |
end | |
server.mount_proc('/edit') do |req, res| | |
temp = Tempfile.new('editwith_') | |
if req.body | |
temp << req.body | |
end | |
temp.close false | |
system $EDITOR, temp.path | |
temp.open | |
res.body = temp.read | |
temp.close | |
res.status = 200 | |
res['Content-Type'] = 'text/plain' | |
res['Content-Length'] = res.body.bytesize | |
end | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment