# recent_amazon.rb $Revision:$ # # recent_comment: 最近の amazon プラグイン記述をリストアップする # パラメタ: # max: 最大表示数(未指定時:3) # sep: セパレータ(未指定時:空白) # # Copyright (C) 2004 by Suzuki # # Original: http://suzuki.tdiary.net/ # # def recent_amazon (max = 3, sep = ' ') regex = Regexp.new('<%=\s*(amazon|isbn|isbn_image|isbn_image_left|isbn_image_right)\s*"([^(?:%>)]*)"\s*,\s*"([^(?:%>)]*)"\s*%>') data = [] for date in @diaries.keys.sort @diaries[date].each_section do |section| @dailydata = [] @imgchk = {} @textchk = {} if (section.subtitle) section.subtitle.gsub(regex) { add_dailydata($1,$2,$3) } end section.body.gsub(regex) { add_dailydata($1,$2,$3) } data = data + @dailydata end end amazon = [] counter = 0 data.reverse.each do | p,i,c | if counter >= max break else case p when 'isbn_image_left','isbn_image_right' p = 'isbn_image' end amazon << apply_plugin("<%= #{p} \"#{i}\",\"#{c}\" %>") counter += 1 end end ret = "
\n" if (amazon.size) ret += amazon.join(sep) end ret += "
\n" return ret end def add_dailydata (type,asin,comment) # とりあえずダミーとしてイメージ優先とする @conf['recent_amazon.priority'] = 'img' if (@conf['recent_amazon.priority'] == 'img') # イメージ優先の場合 case type when 'amazon','isbn_image','isbn_image_left','isbn_image_right' if @imgchk[asin] != 1 if @textchk[asin] == 1 pos = @dailydata.index(@dailydata.rassoc(asin)) if pos != nil @dailydata.delete_at(pos) end end @dailydata << [type,asin,comment] @imgchk[asin] = 1 end when 'isbn' if @textchk[asin] != 1 if @imgchk[asin] == 1 pos = @dailydata.index(@dailydata.rassoc(asin)) if pos != nil @dailydata.delete_at(pos) end end @dailydata << [type,asin,comment] @textchk[asin] = 1 end end end end