Chromeもいいけど,TextareaはEmacsで編集したいのでFirefox + Dafizilla ViewSourceWith から抜けだせないあなたへ。
- Google Chrome のテキストエリアを外部エディタで編集する Edit with Emacs (酒日記 はてな支店)
- Google Chromeのtextareaを外部エディタで編集する (Ruby版) (monoの開発ブログ)
自分はやっぱりemacsclientを使いたいのと,Ruby on Railsの環境を構築済みなので,monoさんのWEBrickを用いたWebサーバー版のを使わせていただきました。
しかし,
temp << req.bodyではutf-8を上手くあつかえていないので( << が駄目だと思う ),自分のところでは,
temp.puts req.body.toutf8に手直しして使っています。
自分のところのruby-server.rbはこんな感じです。どうもありがとうございました。
#!/usr/bin/ruby -Ku
require 'webrick'
require 'tempfile'
require 'kconv'
$EDITOR = '/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.puts req.body.toutf8
end
temp.close false
system $EDITOR, temp.path
temp.open
res.body = temp.read.toutf8
temp.close
res.status = 200
res['Content-Type'] = 'text/plain'
res['Content-Length'] = res.body.size
end
server.start
追記 req.body の nil チェック忘れてました。
if req.body
temp.puts req.body.toutf8
end
No comments:
Post a Comment