Changeset 7743 for platform/tdiary/util

Show
Ignore:
Timestamp:
03/10/08 06:14:04 (9 months ago)
Author:
drry
Message:

platform/tdiary/util/tdiarysearch/search.rb:

  • UTF-8 向けの変更をしました。
  • HTML を修正しました。
  • unindent() を変更しました。
  • 正規表現を修正しました。
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/tdiary/util/tdiarysearch/search.rb

    r4633 r7743  
    2626# 
    2727 
    28 def unindent(str, n) 
    29   str.gsub(/^ {0,#{n}}/, '') 
    30 end 
    31  
    32 HEADER = unindent(<<-'EOS', 2) 
     28def unindent(str) 
     29  str.gsub(/^#{str[/\A(?:\t+| +)/]}/, '') 
     30end 
     31 
     32HEADER = unindent <<'EOS' 
    3333  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    34   <html lang="ja-JP"> 
     34  <html lang="ja"> 
    3535  <head> 
    36     <meta http-equiv="Content-Type" content="text/html; charset=euc-jp"> 
    37     <meta http-equiv="Content-Language" content="ja-JP"> 
     36    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     37    <meta http-equiv="Content-Language" content="ja"> 
    3838    <meta name="robots" content="noindex"> 
    3939    <link rel="stylesheet" href="theme/base.css" type="text/css" media="all"> 
     
    4444EOS 
    4545 
    46 FOOTER = unindent(<<'EOS', 2) 
     46FOOTER = unindent <<'EOS' 
    4747  </body> 
    4848  </html> 
    4949EOS 
    5050 
    51 SEARCH_FORM = unindent(<<"EOS", 2) 
     51SEARCH_FORM = unindent <<"EOS" 
    5252  <form method="post" action="#{File.basename(__FILE__)}"> 
    5353  <input type="text" name="q" size="20" value="<%= patterns.map {|re| escape(re.source) }.join(' ') %>"> 
     
    6161EOS 
    6262 
    63 SEARCH_PAGE = unindent(<<-"EOS", 2) 
     63SEARCH_PAGE = unindent <<"EOS" 
    6464  <h1>tDiary Search</h1> 
    6565  #{SEARCH_FORM} 
     
    6868TOO_MANY_HITS = 50 
    6969 
    70 SEARCH_RESULT = unindent(<<-"EOS", 2) 
     70SEARCH_RESULT = unindent <<"EOS" 
    7171  <h1>tDiary Search: Search Result</h1> 
    7272  #{SEARCH_FORM} 
     
    9595EOS 
    9696 
    97 SEARCH_ERROR = unindent(<<"EOS", 2) 
     97SEARCH_ERROR = unindent <<"EOS" 
    9898  #{SEARCH_FORM} 
    9999  <%= escape(reason) %>. 
    100100EOS 
    101101 
    102 HISTORY = unindent(<<"EOS", 2) 
     102HISTORY = unindent <<"EOS" 
    103103  <h1>tDiary Search: Search History</h1> 
    104104  #{SEARCH_FORM} 
     
    134134 
    135135def main 
    136   $KCODE = 'EUC' 
     136  $KCODE = 'u' 
    137137  cgi = CGI.new 
    138138  @config = TDiary::Config.new(cgi) 
     
    182182  print cgi.header('status' => '200 OK', 
    183183                   'type' => 'text/html', 
    184                    'charset' => 'euc-jp', 
     184                   'charset' => 'utf-8', 
    185185                   'Content-Length' => html.length.to_s, 
    186186                   'Cache-Control' => 'no-cache', 
     
    388388 
    389389def tdiary2text(html) 
    390   apply_tdiary_plugins(html).gsub(%r[<.*?>]em, '').slice(/\A.{0,120}/me) 
     390  apply_tdiary_plugins(html).gsub(%r[<[^>]*>]em, '').slice(/\A.{0,120}/me) 
    391391end 
    392392 
     
    433433 
    434434def urlencode(str) 
    435   str.gsub(/[^\w\-]/n) {|ch| sprintf('%%%02x', ch[0]) } 
     435  str.gsub(/[^\w-]/n) {|ch| sprintf('%%%02x', ch[0]) } 
    436436end 
    437437