My SQLRuby ERB modrubyCGI Kazuhiro Yoshida moriqmoriq com
My. SQL/Ruby, ERB, mod_rubyを使ったCGIの 実例 Kazuhiro Yoshida moriq@moriq. com 9/12/2021 1 KANSAI OPEN SOURCE+FREEWARE 2003
使用するライブラリ n n n My. SQL/Ruby ERB mod_ruby 9/12/2021 5
My. SQL/Ruby n n n by とみたさん Ruby/My. SQL (Ruby/DBI) デフォルトcharsetをShift JISに メッセージカタログもShift JISで用意 9/12/2021 6
ERB n n n e. Ruby 前田さん ↓使いやすさ ERB 咳さん ↓速度 erbscan moonwolfさん 9/12/2021 7
apache/ruby-run. rb: … Apache. chdir_file(filename) load(filename, true) … 9/12/2021 9
app 1. rbx: $gv = 0 def inc_gv $gv += 1 end 5. times{inc_gv} … print $gv 9/12/2021 10
app 2. rbx: require '. /lib 2. rb' 5. times{inc_gv} … print gv 9/12/2021 lib 2. rb: $gv = 0 def inc_gv $gv += 1 end def gv $gv end 11
app 3. rbx: require '. /lib 3. rb' foo = Foo. new 5. times{foo. inc_iv} … print foo. iv 9/12/2021 lib 3. rb: class Foo def initialize @iv = 0 end def inc_iv @iv += 1 end attr : iv end 12
require 'erb' class Foo include ERB: : Util include ERB: : Def. Method dir = File. dirname( __FILE__ ) def_erb_method( : output, File. join(dir, 'foo. erb') ) end 9/12/2021 14
require 'cgi' cgi = CGI. new header = { 'type' => 'text/html', # 'charset' => 'shift_jis', 'Cache-Control' => 'no-cache', } foo = Foo. new cgi. out( header ){ foo. output } 9/12/2021 15
cgi. rb: def out(options = "text/html") … case options["charset"] when /shift_jis/ni content = NKF: : nkf('-s', content) … 9/12/2021 16
絵文字 n n 単純な置換で済む 各キャリアに対応 → HTTP_USER_AGENT cgi. user_agent httpd. conf: Rewrite. Conf %{HTTP_USER_AGENT} (JPHONE|UP. Browser) 9/12/2021 17
- Slides: 18