require 'clothesline' class Nukumi2::Entry DEFAULT_ENCODING = "BlueCloth RubyPants" attr_accessor :title attr_accessor :time attr_accessor :gmtime attr_accessor :change_time attr_accessor :encoding attr_accessor :content attr_accessor :summary attr_accessor :backend attr_accessor :backend_data attr_reader :fields attr_reader :categories def initialize(title="", content="", time=Time.now, change_time=nil) self.title = title self.time = time self.change_time = change_time || self.time @fields = {} @categories = [] self.encoding = DEFAULT_ENCODING self.content = self.summary = content @cache = nil end def outdated? @backend.outdated? self end def update! replace @backend.load(self) end def replace(new) delete_from_topictree # XXX icky self.title = new.title self.time = new.time self.gmtime = new.gmtime self.change_time = new.change_time self.encoding = new.encoding self.content = new.content self.summary = new.summary @fields = new.fields @categories = new.categories insert_into_topictree @topictree if @topictree end def insert_into_topictree(topictree) @topictree = topictree topictree.create permalink, title topictree.add permalink, self categories.each { |category| topictree.add "/category/**/" + category.downcase, self } if fields["page"] path = "/static/" + fields["page"].gsub(/\/index$/, '') unless topictree.name(path) topictree.create path, title end topictree.add path, self end if fields["topic"] unless topictree.name(fields["topic"]) topictree.create fields["topic"], title end topictree.add fields["topic"], self end end def delete_from_topictree @topictree.delete self if @topictree end def to_html if outdated? update! @cache = nil end begin @cache ||= ClothesLine.parse(encoding).new(content).to_html rescue @cache = nil return <<-EOF
Error during HTML conversion:
#{CGI.escapeHTML($!.to_s)}
EOF end @cache end def summary_html ClothesLine.parse(encoding).new(summary).to_html end def anchor # Ick. time.dup.gmtime.strftime "x-%Y%m%d-%H%M%S" end # This is used to create the filename. def basename title.downcase.strip.gsub(/[^a-z0-9]/, '-'). squeeze('-').gsub(/^-*/, '').gsub(/-*$/, '') end def permalink time.strftime "/archive/%Y/%m/#{basename}" end end