=begin
customize
=end
#日付毎アンカーを「#NN」から「#dn」へ変更
module DiaryModule
def date2fileanchor(date)
# date[6..7]
"d" + date[6..7].to_i.to_s
end
end
#日付の曜日を英2文字に変更
class Time
def strftime2(format_str)
youbi2a = %w(Sn Mn Te We Th Fr St)
youbi2A = %w(Su Mo Tu We Th Fr Sa)
format = format_str.dup
format.gsub!(/%2a/, youbi2a[self.wday])
format.gsub!(/%2A/, youbi2A[self.wday])
strftime(format)
end
end
#トピック文字列が生成結果として空文字列になった時「.」を代入
class Topics
def tohtml(diaries, putmonth = true, year = '')
body = ''
@diaries = diaries
topic = Marshal::load(filter_topics(diaries))
pattern = Regexp::compile(@pattern)
topic.keys.sort.reverse_each{ |month|
next unless month[0..3].index(year)
monthlink = []
monthhtml = ''
topic[month].keys.sort.each{ |date|
d = Time::local(month[0..3], month[4..5], date)
monthhtml << "\t\t
#{d.strftime2(@topicDateFormat)} : "
monthhtml << topic[month][date].collect!{ |t|
monthlink << "#{@monthPartNames[date.to_i]}"
# "#{t[1].gsub(pattern, @replace)}"
string = t[1].gsub(pattern, @replace)
string = "." if string == ""
"#{string}"
}.join(' / ')
monthhtml << "\n"
}
if putmonth then
m = Time::local(month[0..3], month[4..5])
if @monthPartNames.uniq.size == 1 then
body << "\t"
body << "#{m.strftime2(@topicMonthFormat)}\n\t\n"
else
monthlink.uniq!
body << "\t- #{m.strftime2(@topicMonthFormat)} ( "
body << monthlink.join(' / ')
body << " )
\n\t\n"
end
end
body << monthhtml
body << "\t
\n" if putmonth
}
if putmonth then
return "\n" + body + "
\n"
else
return "\n"
end
end
end
#カスタム
class Filter
def custom(str, type)
case type
when :P
#「Book:」本感想文エリア
str.gsub!(/^Book:(?: (-.*))?(\n(.*))*/i){
param = $1
str.gsub!(/^Book:(?: (-.*))?\n/i, "")
str = "" + str + "
"
}
#「Review:」その他(映像などの)感想文エリア
str.gsub!(/^Review:(?: (-.*))?(\n(.*))*/i){
param = $1
str.gsub!(/^Review:(?: (-.*))?\n/i, "")
str = "" + str + "
"
}
#「Comment:」メモをコメントアウト
str.gsub!(/^Comment:(?: (-.*))?(\n(.*))*/i){
param = $1
str.gsub!(/^Comment:(?: (-.*))?\n/i, "")
str = ""
}
#「Dust:」愚痴をコメントアウト
str.gsub!(/^Dust:(?: (-.*))?(\n(.*))*/i){
param = $1
str.gsub!(/^Dust:(?: (-.*))?\n/i, "")
str = ""
}
#「Money:」家計簿をコメントアウト
str.gsub!(/^Money:(?: (-.*))?(\n(.*))*/i){
param = $1
str.gsub!(/^Money:(?: (-.*))?\n/i, "")
str = ""
}
when :DATE_ANCHOR
#ヘッダに巻頭言マーク挿入
str.gsub!(/<\/h4>/, '')
when :AFTER_ONEDAY
header = ''
str.gsub!(/(.*?)<' + $1.strip + ''
''
}
str.gsub!(//,header)
when :ONEDAY
#「Head:」巻頭言(一行のみ)を別色調に、して日付直後へ移動。
#未完。行数制限を修正。更にそのうちヘッダに組込
header = ''
str.gsub!(/^Head:(?: (-.*))?(\n(.*?))\n\n/mi){
header << "<<\n"
header << ""
header << $2.strip.gsub(/\n/,'
')
header << ""
''
}
str.replace(header + str)
#「Book:」の一行目をトピック「□」としてコピー。
#「」で囲まれたタイトルを『』へ
str.gsub!(/^Book:(.*?)\n(.*?)「(.*)」(.*?)\n/i){
replace = "□『"+$3+"』\n\nBook:"+$1+"\n"+$2+"「"+$3+"」"+$4+"\n"
}
#「Review:」の一行目をトピック「△」としてコピー。
#「」で囲まれたタイトルを『』へ
str.gsub!(/^Review:(.*?)\n(.*?)「(.*)」(.*?)\n/i){
replace = "△『"+$3+"』\n\nReview:"+$1+"\n"+$2+"「"+$3+"」"+$4+"\n"
}
#の行に対して改行を付けないよう削除。
when :AFTER_P, :AFTER_UL, :AFTER_DL, :AFTER_TOPIC
str.gsub!(/-->
/, '-->')
end
end
end