monoの開発ブログ

プログラム開発の記録

Archive for the ‘Chrome’ Category

Google Chromeのtextareaを外部エディタで編集する (Ruby版)

without comments

Google Chrome のテキストエリアを外部エディタで編集する Edit with Emacs

自分のPCにはPerlがインストールされていないので、Rubyで書いてみました。Perlは分からないので勘で移植しましたが、一応動作しているようです。

#!/usr/bin/ruby -Ku
require 'webrick'
require 'tempfile'
require 'kconv'

$EDITOR = 'C:\vim\gvim.exe'
$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_')
  temp << req.body
  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

$EDITORと$PORTを適切に設定すれば動作するんじゃないかと思います。

Written by mono

1月 30th, 2010 at 7:26 pm

Posted in Chrome, Google, Ruby

Tagged with ,