Class Nukumi2::Entry
In: lib/nukumi2/entry.rb
Parent: Object

Methods

Constants

DEFAULT_ENCODING = "BlueCloth RubyPants"

Attributes

backend  [RW] 
backend_data  [RW] 
categories  [R] 
change_time  [RW] 
content  [RW] 
encoding  [RW] 
fields  [R] 
gmtime  [RW] 
summary  [RW] 
time  [RW] 
title  [RW] 

Public Class methods

[Source]

    # File lib/nukumi2/entry.rb, line 21
21:   def initialize(title="", content="", time=Time.now, change_time=nil)
22:     self.title = title
23:     self.time = time
24:     self.change_time = change_time || self.time
25: 
26:     @fields = {}
27:     @categories = []
28: 
29:     self.encoding = DEFAULT_ENCODING
30:     self.content = self.summary = content
31: 
32:     @cache = nil
33:   end

Public Instance methods

[Source]

     # File lib/nukumi2/entry.rb, line 119
119:   def anchor
120:     # Ick.
121:     time.dup.gmtime.strftime "x-%Y%m%d-%H%M%S"
122:   end

This is used to create the filename.

[Source]

     # File lib/nukumi2/entry.rb, line 125
125:   def basename
126:     title.downcase.strip.gsub(/[^a-z0-9]/, '-').
127:       squeeze('-').gsub(/^-*/, '').gsub(/-*$/, '')
128:   end

[Source]

    # File lib/nukumi2/entry.rb, line 89
89:   def delete_from_topictree
90:     @topictree.delete self  if @topictree
91:   end

[Source]

    # File lib/nukumi2/entry.rb, line 60
60:   def insert_into_topictree(topictree)
61:     @topictree = topictree
62: 
63:     topictree.create permalink, title
64:     topictree.add permalink, self
65: 
66:     categories.each { |category|
67:       topictree.add "/category/**/" + category.downcase, self
68:     }
69:     
70:     if fields["page"]
71:       path = "/static/" + fields["page"].gsub(/\/index$/, '')
72:       
73:       unless topictree.name(path)
74:         topictree.create path, title
75:       end
76:       
77:       topictree.add path, self
78:     end
79: 
80:     if fields["topic"]
81:       unless topictree.name(fields["topic"])
82:         topictree.create fields["topic"], title
83:       end
84:       
85:       topictree.add fields["topic"], self
86:     end
87:   end

[Source]

    # File lib/nukumi2/entry.rb, line 35
35:   def outdated?
36:     @backend.outdated? self
37:   end

[Source]

     # File lib/nukumi2/entry.rb, line 130
130:   def permalink
131:     time.strftime "/archive/%Y/%m/#{basename}"
132:   end

[Source]

    # File lib/nukumi2/entry.rb, line 43
43:   def replace(new)
44:     delete_from_topictree
45: 
46:     # XXX icky
47:     self.title = new.title
48:     self.time = new.time
49:     self.gmtime = new.gmtime
50:     self.change_time = new.change_time
51:     self.encoding = new.encoding
52:     self.content = new.content
53:     self.summary = new.summary
54:     @fields = new.fields
55:     @categories = new.categories
56: 
57:     insert_into_topictree @topictree  if @topictree
58:   end

[Source]

     # File lib/nukumi2/entry.rb, line 115
115:   def summary_html
116:     ClothesLine.parse(encoding).new(summary).to_html
117:   end

[Source]

     # File lib/nukumi2/entry.rb, line 93
 93:   def to_html
 94:     if outdated?
 95:       update!
 96:       @cache = nil
 97:     end
 98: 
 99:     begin
100:       @cache ||= ClothesLine.parse(encoding).new(content).to_html
101:     rescue
102:       @cache = nil
103:       return "<div class=\"html-conversion-error\">\n<strong>Error during HTML conversion:</strong>\n<pre>\#{CGI.escapeHTML($!.to_s)}</pre>\n</div>\n"
104:     end
105: 
106:     @cache
107:   end

[Source]

    # File lib/nukumi2/entry.rb, line 39
39:   def update!
40:     replace @backend.load(self)
41:   end

[Validate]