=begin をゐなりさん作成ToDOプラグイン(http://woinary.pobox.ne.jp/ndiarydl.html)改変 単なる文字列挿入プラグイン 読込ファイル名は、デフォルトでは、過去日記ファイルと同名.word  script/plugin/word.rb 分割型(abcなど)に一応対応してるつもり 書式: file=input_file                :読込ファイル名指定 filemode=hoge(現状は、なんでもついてたらいい):読込ファイル名を「年月」化 encode=hoge(現状は、なんでもついてたらいい) :

を付加 例: <= 過去日記ファイルと同名.word <= yyyymm.word =end def plug(opt) #入力ファイル名の生成 #引数によりけり word_src = '' if opt['file'].nil? then #ファイル名の取得、拡張子の掃除 thisfile = date2monthlyfilename(@diarys[0]).chomp("\.html").chomp("\.htm") if !opt['filemode'].nil? then #年月情報の取得(ページに付する日付の先頭より)、それをファイル名に thisfile = @diarys[0][0..5] #targetMonthを利用するのはやめてみた # if self.kind_of?(LastDiary) then # thisfile = @diarys[0][0..5] # elsif self.kind_of?(PastDiary) then # @targetMonth.gsub(/\D*(\d+)\D*/,$1) # thisfile = $1 # end end #LOG_DIRECTORY以下のファイルの総当り検索:該当名ファイルがあるか? Dir::find(@logDirectory){ |file| #ここの拡張子を修正すれば「.word」ファイル以外も読むだろう next unless /\/(.+)(\.word)$/i =~ file word_src = file if $1 =~ thisfile } else #特にファイル名指定があった場合はそれ。元DIRはLOG_DIRECTORY word_src = @logDirectory.chomp('/') + '/' + opt['file'] end #エラーメッセージ等 $stderr.print "CHK; word #{word_src}\n" if word_src == '' then $stderr.print "ERR; can't find word file.\n" return end #読込。ファイルから1行ずつ読んでは変数「word」へ吐き出し word = '' open(word_src, 'r') do |word_file| while line = word_file.gets word << line #吐き出すついでに改行コード修正(私の環境ローカルな問題)、治った? # word << line.chomp("\r\n") + "\n" end end #フラグによっては、文字飾りモードに if !opt['encode'].nil? then #改行を「
」に変更 word.gsub!(/\n/, "
\n") #改行が3つ並んでるとそれを「
」に変更 word.gsub!(/
\n
\n
\n/,"\n
\n\n") end #このあたりで #word.gsub!(/\n(.+\.jpg)\n/,"\n") #とかなんとかすると、ファイル中の「...jpg」がイメージとして読まれると思う #変数「word」を返す(日記ページに組み込まれる文字列) return word end