=begin 今日はなんの日?みたいなプラグイン by IPPO WoinaryさんのToDoプラグインを参考に変更。 #よく考えるとschedule.rbいじった方がはやかったような…… 動作確認:nDiary 0.9.3b18 + mswin版 Ruby 1.6.8 書式:file=input_file なんの日ファイル pre=N N日前まで含む suf=M M日後まで含む span=O O日前後まで含む(default:0=0) deco 飾り付け(というか、私専用) simp シンプルに 例: Today書式:MMDDdatetext... が一行。xN行。 #Today書式:日付(YYYY/MM/DD)テキスト が一行。xN行。       上の形式に従ってない部分、行頭が#の部分は無視します。 1.1: 2001.11.7・初版。カスタム、イレギュラー対応。 1.2: 2003.5.19 CSSっぽく =end def plug(opt) # 引数は必ず付けて if opt['file'].nil? then return '' end pre_span = 3 suf_span = 3 if !opt['pre'].nil? then pre_span = opt['pre'].to_i end if !opt['suf'].nil? then suf_span = opt['suf'].to_i end if !opt['span'].nil? then pre_span = opt['span'].to_i suf_span = opt['span'].to_i end mode_decorate = false mode_decorate = true if !opt['deco'].nil? mode_simple = false mode_simple = true if !opt['simp'].nil? # 入力ファイル名の生成 today_src = @logDirectory.chomp('/') + '/' + opt['file'] $stderr.print "CHK; today #{today_src}\n" # ToDoの読込み today_list = [] time_now = Time.now year_now = time_now.strftime("%Y").to_i time_pre = pre_span * 60 * 60 * 24 time_suf = suf_span * 60 * 60 * 24 month_old = '' day_old = '' open(today_src, 'r').each { |line| data = line.chomp.split("\t") # フォーマットのチェック if (data[0] !~ /^#/) && (data[0] =~ /(\d\d)(\d\d)/) then year = year_now month = $1 day = $2 # $stderr.puts "CHK; #{year} #{month} #{day}" # イレギュラー対策 if month.to_i == 0 then month = month_old end if month.to_i > 12 then month = "12" end if day.to_i == 0 then day = day_old end if day.to_i > 31 then day = "31" end time = Time.mktime(year_now, month.to_i, day.to_i) # $stderr.puts "CHK; #{time}" # $stderr.puts "CHK; #{year} #{month} #{day}" flag = false flag = true if (time - time_now) == 0 flag = true if ((time - time_now) > 0) && ((time - time_now) < time_suf) flag = true if ((time - time_now) < 0) && ((time_now - time) < time_pre) if flag then $stderr.puts "CHK; find #{data[1]}" data.shift date = data.shift str = data.join("\t") today_list << [date, str] end month_old = '' month_old << month day_old = '' day_old << day end } # $stderr.puts "CHK;---" if today_list.size > 0 then if mode_simple then today_list.each { |date, str| today << date << " " << str << "
\n" } elsif mode_decorate then mo = time_now.strftime("%b").downcase md = time_now.strftime("%m%d") today = '' << "\n" today << '' << "\n" today_list.each { |date, str| data = str.split("\t") str1 = data.shift str2 = data.join today << '' today << '' today << '' today << '' << "\n" } today << '
' today << '今日はなんの日?' today << ' SF版' today << '
' << date << '' << str1 << '
' today << '
' << str2 << '
' << "\n" else today = "\n" today_list.each { |date, str| today << '' today << '' today << '' today << '' << "\n" } today << "
' << date << '' << str << '
\n" end end return today end