railsアプリをUTF-8でsubversionするときのスクリプト備忘録

http://wiki.rails2u.com/subversion%E3%81%A7Rails%E3%82%A2%E3%83%97%E3%83%AA%E3%82%92%E7%AE%A1%E7%90%86
ここにあったスクリプトを雛型に、
http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/
http://osakanas.blog19.fc2.com/blog-entry-81.html
http://osakanas.blog19.fc2.com/blog-entry-40.html
ここらのサイトを参考にしてみた。

gettext遣った方がよさそうらしいが、、、

hogehogeを適当なのにする

#!/bin/bash
#
# http://wiki.rails2u.com/subversion%E3%81%A7Rails%E3%82%A2%E3%83%97%E3%83%AA%E3%82%92%E7%AE%A1%E7%90%86
#
# to use gettext is better ?
#
if [ $# -ne 1 ];then
echo "Usage: $0 projectname"
exit
fi

RAILS_CMD='rails'
RAILS_APP_NAME=$1
SVN_TARGET=/home/hogehoge/svnrails/$RAILS_APP_NAME.rails

$RAILS_CMD $RAILS_APP_NAME

svnadmin create --fs-type fsfs $SVN_TARGET
cd $RAILS_APP_NAME
svn import -m 'generate rails app' . file://$SVN_TARGET
cd ../
rm -rf $RAILS_APP_NAME
svn co file://$SVN_TARGET $RAILS_APP_NAME
cd $RAILS_APP_NAME
svn remove log/*
svn ci -m 'rm logfile'
svn up
svn propset svn:ignore '*.log' log/
svn ci -m 'add ignore ./log/*.log'
svn up
svn move config/database.yml config/database.example.yml
svn ci -m 'move database.yml'
svn up
svn propset svn:ignore 'database.yml' config/
svn ci -m 'add ignore'
svn up
mv ./config/environment.rb ./config/environment.rb.org
echo "\$KCODE='utf-8'" > ./config/environment.rb
cat ./config/environment.rb.org >> ./config/environment.rb
# to use UTF-8
# http://osakanas.blog19.fc2.com/blog-entry-81.html
echo "ActiveRecord::Base.connection.execute 'SET NAMES UTF8'" >> ./config/environment.rb
# utf-8
# http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/
# http://osakanas.blog19.fc2.com/blog-entry-40.html
cat <<EOF > ./app/controllers/application.rb
# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
  before_filter :set_charset
  before_filter :configure_charsets

  def set_charset
    @headers["Content-Type"] = "text/html; charset=utf-8"
  end

  def configure_charsets
    @response.headers["Content-Type"] = "text/html; charset=utf-8"
    # Set connection charset. MySQL 4.0 doesn't support this so it
    # will throw an error, MySQL 4.1 needs this
    #suppress(ActiveRecord::StatementInvalid) do
    #  ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
    #end
  end
end
EOF
svn ci -m 'use UTF-8'
svn up
rm ./config/environment.rb.org
cd ../
svn co file://$SVN_TARGET $RAILS_APP_NAME.devel
cd $RAILS_APP_NAME.devel
cp ./config/database.example.yml ./config/database.yml
cd ..

echo "$RAILS_APP_NAME.devel is development directory"