Skip to content

Instantly share code, notes, and snippets.

@bheeshmar
Created February 7, 2012 22:28
Show Gist options
  • 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