* hiki/util.rb (Hiki::Util): add module functions
(euc_to_utf8, utf8_to_euc) for hiki/xmlrpc.rb
* hiki/xmlrpc.rb: use Util.utf8_to_euc,euc_to_utf8 insted of
Object#utf8_to_euc,euc_to_utf8
@@ -313,6 +313,8 @@ | ||
313 | 313 | end |
314 | 314 | end |
315 | 315 | |
316 | + module_function :euc_to_utf8 | |
317 | + | |
316 | 318 | def utf8_to_euc(str) |
317 | 319 | if NKF.const_defined?(:UTF8) |
318 | 320 | return NKF.nkf('-m0 -e', str) |
@@ -326,6 +328,8 @@ | ||
326 | 328 | end |
327 | 329 | end |
328 | 330 | |
331 | + module_function :utf8_to_euc | |
332 | + | |
329 | 333 | def to_native(str, charset=nil) |
330 | 334 | # XXX to_charset will be 'utf-8' in the future version |
331 | 335 | begin |
@@ -9,7 +9,7 @@ | ||
9 | 9 | |
10 | 10 | def init_handler(server, cgi_class=CGI) |
11 | 11 | server.add_handler('wiki.getPage') do |page| |
12 | - page = utf8_to_euc( page ) | |
12 | + page = Util.utf8_to_euc( page ) | |
13 | 13 | conf = Hiki::Config.new |
14 | 14 | db = conf.database |
15 | 15 | ret = db.load( page ) |
@@ -16,18 +16,18 @@ | ||
16 | 16 | unless ret |
17 | 17 | raise XMLRPC::FaultException.new(1, "No such page was found.") |
18 | 18 | end |
19 | - XMLRPC::Base64.new( euc_to_utf8( ret ) ) | |
19 | + XMLRPC::Base64.new( Util.euc_to_utf8( ret ) ) | |
20 | 20 | end |
21 | 21 | |
22 | 22 | server.add_handler('wiki.getPageInfo') do |page| |
23 | - page = utf8_to_euc( page ) | |
23 | + page = Util.utf8_to_euc( page ) | |
24 | 24 | conf = Hiki::Config.new |
25 | 25 | db = conf.database |
26 | 26 | title = db.get_attribute( page, :title ) |
27 | 27 | title = page if title.nil? || title.empty? |
28 | 28 | { |
29 | - 'title' => XMLRPC::Base64.new( euc_to_utf8( title ) ), | |
30 | - 'keyword' => db.get_attribute( page, :keyword ).collect { |k| XMLRPC::Base64.new( euc_to_utf8( k ) ) }, | |
29 | + 'title' => XMLRPC::Base64.new( Util.euc_to_utf8( title ) ), | |
30 | + 'keyword' => db.get_attribute( page, :keyword ).collect { |k| XMLRPC::Base64.new( Util.euc_to_utf8( k ) ) }, | |
31 | 31 | 'md5hex' => db.md5hex( page ), |
32 | 32 | 'lastModified' => db.get_attribute( page, :last_modified ).getutc, |
33 | 33 | 'author' => XMLRPC::Base64.new( db.get_attribute( page, :editor ) || '' ) |
@@ -35,15 +35,15 @@ | ||
35 | 35 | end |
36 | 36 | |
37 | 37 | server.add_handler('wiki.putPage') do |page, content, attributes| |
38 | - page = utf8_to_euc( page ) | |
39 | - content = utf8_to_euc( content ) | |
38 | + page = Util.utf8_to_euc( page ) | |
39 | + content = Util.utf8_to_euc( content ) | |
40 | 40 | attributes ||= {} |
41 | 41 | attributes.each_pair { |k, v| |
42 | 42 | case v |
43 | 43 | when String |
44 | - v.replace( utf8_to_euc( v ) ) | |
44 | + v.replace( Util.utf8_to_euc( v ) ) | |
45 | 45 | when Array |
46 | - v.map!{ |s| s.replace( utf8_to_euc( s ) ) } | |
46 | + v.map!{ |s| s.replace( Util.utf8_to_euc( s ) ) } | |
47 | 47 | end |
48 | 48 | } |
49 | 49 | conf = Hiki::Config.new |
@@ -83,7 +83,7 @@ | ||
83 | 83 | server.add_handler('wiki.getAllPages') do |
84 | 84 | conf = Hiki::Config.new |
85 | 85 | db = conf.database |
86 | - db.pages.collect{|p| XMLRPC::Base64.new( euc_to_utf8( p ) )} | |
86 | + db.pages.collect{|p| XMLRPC::Base64.new( Util.euc_to_utf8( p ) )} | |
87 | 87 | end |
88 | 88 | |
89 | 89 | #add_multicall |
@@ -1,5 +1,12 @@ | ||
1 | 1 | 2010-05-29 hiraku <hiraku@sapporo.email.ne.jp> |
2 | 2 | |
3 | + * hiki/util.rb (Hiki::Util): add module functions | |
4 | + (euc_to_utf8, utf8_to_euc) for hiki/xmlrpc.rb | |
5 | + * hiki/xmlrpc.rb: use Util.utf8_to_euc,euc_to_utf8 insted of | |
6 | + Object#utf8_to_euc,euc_to_utf8 | |
7 | + | |
8 | +2010-05-29 hiraku <hiraku@sapporo.email.ne.jp> | |
9 | + | |
3 | 10 | * hiki/util.rb (Hiki::Util): add module function (get_common_data) |
4 | 11 | for misc/plugin/history.rb |
5 | 12 |