# $Id: topic_sort.rb,v 0.3 2003-02-05 18:33:55 by 有里 # 0.9.3b16用 # # を一部変更したやつ by アサノ # 出力結果は以下 URI のような感じになります。 # http://www.mushline.com/junk/genre_02_01.html =begin トピック一覧をソートしてTopicファイルに挿入 topic_sort=date 日付でソート topic_sort=topic トピック文字列でソート select=str データ抽出条件 pattern=str 文字置換パターン replace=str 置換パターン dateformat=str トピックの後に表示される日付フォーマット用文字列。 ex. 出力形式は以下の通り =end class Filter def topic_sort(str, type) end end # トピック一覧作成クラス class Topics def make_sortlst(diaries, year = '') @diaries = diaries topic = Marshal::load(filter_topics(diaries)) pattern = Regexp::compile(@pattern) topiclst = TopicLst.new topic.keys.sort.reverse_each{ |month| next unless month[0..3].index(year) topic[month].keys.sort.reverse_each{ |date| d = Time::local(month[0..3], month[4..5], date) topic[month][date].reverse_each{ |t| tday = month + date tank = t[0] tstr = t[1] topiclst.add(tday, tank, tstr) } } } @topic_list = topiclst end def sorthtml(optstr = 'date') select = Regexp::compile('') pattern = Regexp::compile(@pattern) replace = @replace dateformat = '%m/%d' #オプション解析 argv = [] argv = optstr.gsub('>','>').gsub('<','<').split(/\?/s) sortmode = argv.shift opt = {} argv.each{ |str| str = str.gsub('&question;','?').gsub('&','&') key, val = str.split(/=/, 2) opt[key.downcase] = val } select = Regexp::compile(opt['select']) if opt['select'] pattern = Regexp::compile(opt['pattern']) if opt['pattern'] replace = opt['replace'] if opt['replace'] dateformat = opt['dateformat'] if opt['dateformat'] topiclst= @topic_list if sortmode == 'topic' topiclst = @topic_list.sort{|a, b| a <=> b } end body = "\n" return body end def puthtml(filename, skelton, diaries, putmonth, year = '') out = open(filename, "w") begin make_sortlst(diaries, year) infile = open(skelton) infile.each { |line| loadplugin(line) if line.gsub!(//i, "") then out.print tohtml(diaries, putmonth, year).kconv(@outputKcode) end if line.gsub!(//i, "") then opt = $1 out.print sorthtml(opt).kconv(@outputKcode) end out.print line.kconv(@outputKcode) } infile.close out.close rescue Errno::ENOENT $stderr.puts "\n** error: topics skelton file: '#{skelton}' not found.\n" return end print "make '#{filename}'\n" end end class Mytopic include Comparable attr_accessor :date attr_accessor :tank attr_accessor :tstr def initialize(date, tank, tstr) @date = date @tank = tank @tstr = tstr end def <=>(other) t = @tstr.to_s <=> other.tstr.to_s return t if t != 0 t = @date <=> other.date return t if t != 0 return @tank <=> other.tank end end class TopicLst include Enumerable def initialize() @topiclst = Array.new end def add(date, tank, tstr) t = Mytopic.new(date, tank, tstr) @topiclst.push(t) end def each @topiclst.each{|topic| yield(topic) } end end