[Hiki-dev:00763] uconv の LoadError 捕捉

Back to archive index

KOMATSU Shinichiro koma2****@lovep*****
2005年 6月 7日 (火) 05:56:12 JST


小松です。

NKF が UTF-8 に対応していない場合(Ruby 1.8.2 以前)には
uconv を require するようになっているようですが、さらに

・ uconv も見付からなかった時は、Ruby を上げるか
   uconv or rbuconv をインストールするようエラーメッセージを出力
・ ドキュメントに、古い Ruby では uconv or rbuconv を
   インストールするように書いておく。

方が親切かと思います。

あと、trackback.rb と rss-show.rb ですが、

    Hiki::Util::utf8_to_euc

というのはエラーになります。
これは utf8_to_euc とすべきではないでしょうか?

-- 
┏━━━━━━━━━━━━━━━━━━━━━━┓
                小松  晋一朗            
             koma2****@lovep*****
     http://bloghome.lovepeers.org/daymemo2/
┗━━━━━━━━━━━━━━━━━━━━━━┛
-------------- next part --------------
Index: doc/INSTALL.txt
===================================================================
RCS file: /cvsroot/hiki/hiki/doc/INSTALL.txt,v
retrieving revision 1.5
diff -u -r1.5 INSTALL.txt
--- doc/INSTALL.txt	17 May 2005 04:08:09 -0000	1.5
+++ doc/INSTALL.txt	6 Jun 2005 20:47:01 -0000
@@ -4,6 +4,13 @@
 [[Rubyホームページ|http://www.ruby-lang.org/ja/]]からダウンロードしてイン
 ストールしてください。
 
+!!依存するライブラリのインストール
+Ruby 1.8.2 以前を使っていて、trackback.rb または rss-show.rb を使う時には、
+以下のいづれかをインストールする必要があります。
+
+*[[uconv|http://www.yoshidam.net/Ruby_ja.html#uconv]]
+*[[rbuconv|http://www.yoshidam.net/Ruby_ja.html#rbuconv]]
+
 !!インストール例で前提とする環境
 
 一般的なCGIの実行を許可しているISPやレンタルサーバ上で利用する場合を想定
Index: hiki/util.rb
===================================================================
RCS file: /cvsroot/hiki/hiki/hiki/util.rb,v
retrieving revision 1.33
diff -u -r1.33 util.rb
--- hiki/util.rb	24 May 2005 09:28:49 -0000	1.33
+++ hiki/util.rb	6 Jun 2005 20:47:01 -0000
@@ -255,8 +255,12 @@
       if NKF::const_defined?(:UTF8)
         return NKF::nkf('-m0 -w', str)
       else
-        require 'uconv'
-        return Uconv.euctou8(str)
+	begin
+	  require 'uconv'
+	rescue LoadError
+	    raise "Please update to Ruby >= 1.8.2, or install either uconv or rbuconv."
+	end
+	return Uconv.euctou8(str)
       end
     end
   
@@ -264,7 +268,11 @@
       if NKF::const_defined?(:UTF8)
         return NKF::nkf('-m0 -e', str)
       else
-        require 'uconv'
+	begin
+	  require 'uconv'
+	rescue LoadError
+	  raise "Please update to Ruby >= 1.8.2, or install either uconv or rbuconv."
+	end
         return Uconv.u8toeuc(str)
       end
     end
Index: misc/plugin/rss-show.rb
===================================================================
RCS file: /cvsroot/hiki/hiki/misc/plugin/rss-show.rb,v
retrieving revision 1.7
diff -u -r1.7 rss-show.rb
--- misc/plugin/rss-show.rb	6 Jun 2005 12:05:14 -0000	1.7
+++ misc/plugin/rss-show.rb	6 Jun 2005 20:47:01 -0000
@@ -57,7 +57,7 @@
 
 def rss_parse(rss)
   rss_re = /<item(?!s)[^>]*?>.*?<title[^>]*?>(.*?)<\/title>.*?<link[^>]*?>(.*?)<\/link>.*?<\/item>/mi
-  Hiki::Util::utf8_to_euc(rss).scan(rss_re)
+  utf8_to_euc(rss).scan(rss_re)
 end
 
 def rss_format_items(items)
Index: misc/plugin/trackback.rb
===================================================================
RCS file: /cvsroot/hiki/hiki/misc/plugin/trackback.rb,v
retrieving revision 1.7
diff -u -r1.7 trackback.rb
--- misc/plugin/trackback.rb	6 Jun 2005 12:05:14 -0000	1.7
+++ misc/plugin/trackback.rb	6 Jun 2005 20:47:01 -0000
@@ -14,9 +14,9 @@
     redirect(@cgi, "#{@conf.index_url}?#{@page.escapeHTML}")
     return
   end
-  blog_name = Hiki::Util::utf8_to_euc( params['blog_name'][0] || '' )
-  title = Hiki::Util::utf8_to_euc( params['title'][0] || '' )
-  excerpt = Hiki::Util::utf8_to_euc( params['excerpt'][0] || '' )
+  blog_name = utf8_to_euc( params['blog_name'][0] || '' )
+  title = utf8_to_euc( params['title'][0] || '' )
+  excerpt = utf8_to_euc( params['excerpt'][0] || '' )
 
   lines =****@db*****( @page )
   md5hex =****@db*****( @page )


Hiki-dev メーリングリストの案内
Back to archive index