-
-
Save fukayatsu/5244731 to your computer and use it in GitHub Desktop.
https://chrome.google.com/webstore/detail/edit-with-emacs/ljobjlafonikaiipfkggjbhkghgicgoh の sublime text 2用のサーバー
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' | |
Process.daemon | |
$EDITOR = "/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl" | |
$OPTIONS = ['-w'] | |
$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_', '.md']) | |
temp << req.body if req.body | |
temp.close false | |
system $EDITOR, *$OPTIONS, temp.path | |
temp.open | |
res.body = temp.read | |
temp.close true | |
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