# # recent_photo.rb # # days: 最大表示画像数(default: 5) # width: 画像表示幅(default: 120) # # image.rb で設置した画像ファイルを表示します # <使い方> # * <%=recent_photo%> を記述するだけ # <仕様> # * @options['image.dir'] で設定されているディレクトリ内の全ての # 画像を、新しい順に days の数だけ表示 # * 隠されている日付の画像は表示しない # * 該当する日付の日記が存在しない場合は表示しません # * 該当する日付で使われてなくても、その日記が存在すれば表示します # <例> 20040708_0.jpg のみ日記で使っていても、20040708_1.jpg も表示 # # Copyright 2004- Kawabata, Kazumichi (Higemaru.) # =begin ChangeLog 2005/03/07 K.Kawabata * version 1.0.2 (fixed document typo) * version 1.0.1 (fixed document typo) 2004/07/09 K.Kawabata * version 1.0.0 =end def recent_photo days = @options && @options['recent_photo.days'] || 5 width = @options && @options['recent_photo.width'] || 120 days = days.to_i date_format ||= @date_format result = '' image_dir = @options && @options['image.dir'] || './images/' image_dir.chop! if /\/$/ =~ image_dir catch(:exit) { Dir["#{image_dir}/*"].sort.reverse_each do |path| file = path.split('/').pop (pyear, pmon, pday) = [file[0..3], file[4..5], file[6..7]] @diaries.each_value do |diary| next unless diary.date.strftime("%Y%m%d") == "#{pyear}#{pmon}#{pday}" next unless diary.visible? result <<%Q|

| result <<%Q|#{diary.date.strftime(date_format)}
| result <<%Q|#{file}| result <<%Q|

\n| days -= 1 throw :exit if days == 0 end end } apply_plugin( result ) end