# $Id: enikki.rb,v 1.5 2003/10/30 16:40:46 not Exp $ # 2003/12/28 微修正 =begin 絵日記機能。OUTPUT_DIRECTORY で指定したディレクトリに 'enikki' という ディレクトリを作って '20001001.jpg' みたいなファイル名で画像ファイルを おいとくとその日の日記の冒頭に表示。対応してる画像の形式は jpg, gif, png。 =end class Filter def enikki(str, type) if @enikkifiles.nil? then @enikkifiles ||= {} Dir::find(@diary.outputDirectory + 'enikki/'){ |file| if /\/(\d{8})\.(jpg|png|gif)$/i =~ file then @enikkifiles[$1] = file.sub(/#{@diary.outputDirectory}/, '') #修正 end } end case type when :ONEDAY if @enikkifiles.key?(@diary.date) then require 'lib/imagesize' url = @enikkifiles[@diary.date] alt = "えにっき(#{@diary.date[0..3]}/#{@diary.date[4..5]}/#{@diary.date[6..7]})" w, h, c = ImageSize::size(@diary.outputDirectory + url) unless c.empty? then title = %Q! title="#{c}"! end unless w.zero? then size = %Q!width="#{w}" height="#{h}"! else size = '' end img = %Q!#{alt}' : '>') str.replace("<<\n" + img + "\n\n" + str) end end end end