Skip to content

Instantly share code, notes, and snippets.

@bheeshmar
Created February 7, 2012 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bheeshmar/1762576 to your computer and use it in GitHub Desktop.
Save bheeshmar/1762576 to your computer and use it in GitHub Desktop.
Webserver for Textaid Chrome plugin
require 'webrick'
require 'tempfile'
# Start gvim in foreground mode
$EDITOR = "gvim -f "
s = WEBrick::HTTPServer.new(:Port => 9292)
%w(INT TERM).each { |signal| trap(signal) { s.shutdown } }
s.mount_proc("/") do |req,res|
t = Tempfile.open('textaid') { |f| f.write(req.body); f }
system($EDITOR + t.path)
res.body = File.read(t.path)
t.unlink
end
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment