# scheduler.rb : schedule 表示 plugin # v.20031010 # # 使い方: # scheduler.rb を plugin directory に放り込んで、 # <%= schedule %> を header/footer に挿入する。 # @cache_path/schedule に予定を記述する。 # default では 今日から 30日分のうち 8件を表示。 # # @cache_path/schedule の記述方法: # ``MM/DD 予定''の形で記述する。 # ex. 03/03 birthday # また、``mon 予定''の形で毎週の予定も記述可能。 # # tdiary.confで指定するオプション: # @options['scheduler.path'] = '/home/user/any/' # 予定を記述した file の path # file name は schedule # default : @cache_path # @options['scheduler.sche_pnum'] = 8 # 最大表示件数 # default : 8 # @options['scheduler.sche_pday'] = 30 # 今日から 30 日分表示 # default : 30 # @options['scheduler.sche_bday'] = 0 # 今日から 0 日前分まで表示 # default : 0 # # Copyright (c) 2003 YAA # Distributed under the GPL # def schedule return if @mode.to_s != 'latest' if @options and @options["scheduler.path"] data_path = @options["scheduler.path"] else data_path = @cache_path end if @options and @options["scheduler.sche_pnum"] pnum = @options["scheduler.sche_pnum"] else pnum = 8 end if @options and @options["scheduler.sche_pday"] pday = @options["scheduler.sche_pday"] else pday = 30 end if @options and @options["scheduler.sche_bday"] bday = @options["scheduler.sche_bday"] else bday = 0 end result = '' # 表示期間 today = Time.now fday = Time.now - (bday * 24 * 60 * 60) # 表示期間(first_date から表示) first_date = "#{fday.strftime('%m/%d')}" lday = Time.now + (pday * 24 * 60 * 60) # 表示期間(last_date の前日まで表示) last_date = "#{lday.strftime('%m/%d')}" result << "Schedule
" # schedule data 読み込み file = open(data_path.sub(/\/$/, '') + "/schedule", "r") lines = file.readlines file.close weeks = %w(sun mon tue wed thu fri sat) # 展開する期間 num_weeks 週分 num_weeks = (pday + bday) / 7 schedules_original = [] for line in lines # 'MM/DD ' で始まる行はそのまま schedule 要素 schedules_original << line if line =~ /^[0-9]{2}\/[0-9]{2} / # mon とかを展開 for week in weeks if line =~ /^#{week} /i then for i in 0..6 do if (fday + (i * 24 * 60 * 60)).strftime('%a') =~ /^#{week}$/i schedules_original << line.gsub(/^#{week} /, "#{(fday + (i * 24 * 60 * 60)).strftime('%m/%d')} ") break end end for j in 1..num_weeks do schedules_original << line.gsub(/^#{week} /, "#{(fday + ((j * 7) + i) * 24 * 60 * 60).strftime('%m/%d')} ") end end end end # ここで日付順に sort schedules_original = schedules_original.sort # 今日 - 年末, 年末 - 昨日 な順に sort schedules = [] for line in schedules_original schedules << line if first_date <= line end for line in schedules_original schedules << line if first_date > line end result << "" result end