forked from matthewfallshaw/text-aid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
36 lines (30 loc) · 841 Bytes
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
EDITOR_CMD = '/opt/local/bin/mvim -c"au VimLeave * !open -a Google\ Chrome" -f'
%w[rubygems rack].each {|l| require l }
class TextAidServer
def call(env)
case env["REQUEST_METHOD"]
when "GET"
[
200,
{ 'Content-Type' => 'text/plain' },
<<STR
Server is up and running. To use it, issue a POST request with the file to edit as the content body.
{
#{env.keys.collect {|k| " \"#{k}\" => #{env[k].inspect}" }.join("\n")}
}
STR
]
when "POST"
tempfile = Tempfile.new("text-aid-server")
tempfile.print env["rack.input"].read
tempfile.flush
`#{EDITOR_CMD} #{tempfile.path}`
tempfile.open
body = tempfile.read.chomp
tempfile.close!
[200, { 'Content-Type' => 'text/plain' }, body]
end
end
end
run TextAidServer.new
# vim: set filetype=ruby: