# recent_comment.rb $Revision: 1.4.2.1 $ # # recent_comment: 最近のツッコミをリストアップする # パラメタ: # max: 最大表示数(未指定時:3) # sep: セパレータ(未指定時:空白) # form: 日付のフォーマット(未指定時:(日記の日付表記 時:分)) # except: 無視する名前(未指定時:nil) # # Copyright (C) 2002 by TADA Tadashi # You can redistribute it and/or modify it under GPL2. # def recent_comment( max = 3, sep = ' ', form = nil, except = nil ) form = "(#{@date_format + ' %H:%M'})" unless form comments = [] date = {} index = {} @diaries.each_value do |diary| next unless diary.visible? diary.each_comment_tail( max ) do |comment, idx| if except && (/#{except}/ =~ comment.name) next end comments << comment date[comment.date] = diary.date index[comment.date] = idx end end result = [] comments.sort{|a,b| (a.date)<=>(b.date)}.reverse.each_with_index do |com,idx| break if idx >= max str = '' str << %Q[#{idx+1}.] str << %Q[] str << %Q[#{CGI::escapeHTML( com.name )}] str << %Q[#{com.date.dup.strftime( form )}] result << str end result.join( sep ) end