| In: |
app/models/revision.rb
|
| Parent: | Object |
| author | [RW] | |
| content | [RW] | |
| created_at | [RW] | |
| number | [RW] | |
| page | [RW] |
# File app/models/revision.rb, line 15
15: def initialize(page, number, content, created_at, author)
16: @page, @number, @created_at, @author = page, number, created_at, author
17: self.content = content
18: end
# File app/models/revision.rb, line 78
78: def clear_display_cache
79: @display_cache = @published_cache = @wiki_words_cache = nil
80: end
Ensure that the wiki content is parsed when ever it is updated.
# File app/models/revision.rb, line 21
21: def content=(content)
22: @content = content
23: end
# File app/models/revision.rb, line 25
25: def created_on
26: Date.new(@created_at.year, @created_at.mon, @created_at.day)
27: end
Explicit check for new type of display cache with find_chunks method. Ensures new version works with older snapshots.
# File app/models/revision.rb, line 67
67: def display_content
68: unless @display_cache && @display_cache.respond_to?(:find_chunks)
69: @display_cache = WikiContent.new(self)
70: end
71: @display_cache
72: end
# File app/models/revision.rb, line 87
87: def display_content_for_export
88: WikiContent.new(self, {:mode => :export} )
89: end
# File app/models/revision.rb, line 74
74: def display_diff
75: previous_revision ? HTMLDiff.diff(previous_revision.display_content, display_content) : display_content
76: end
# File app/models/revision.rb, line 82
82: def display_published
83: @published_cache = WikiContent.new(self, {:mode => :publish}) if @published_cache.nil?
84: @published_cache
85: end
Returns an array of all the WikiWords present in the content of this revision. that already exists as a page in the web.
# File app/models/revision.rb, line 55
55: def existing_pages
56: wiki_words.select { |wiki_word| page.web.pages[wiki_word] }
57: end
# File app/models/revision.rb, line 29
29: def pretty_created_at
30: # Must use DateTime because Time doesn't support %e on at least some platforms
31: DateTime.new(
32: @created_at.year, @created_at.mon, @created_at.day, @created_at.hour, @created_at.min
33: ).strftime "%B %e, %Y %H:%M"
34: end
# File app/models/revision.rb, line 40
40: def previous_revision
41: number - 1 >= 0 && page.revisions[number - 1]
42: end
Returns an array of all the WikiWords present in the content of this revision that *doesn’t* already exists as a page in the web.
# File app/models/revision.rb, line 61
61: def unexisting_pages
62: wiki_words - existing_pages
63: end
Returns an array of all the WikiWords present in the content of this revision.
# File app/models/revision.rb, line 45
45: def wiki_words
46: unless @wiki_words_cache
47: wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink)
48: @wiki_words_cache = wiki_chunks.map { |c| ( c.escaped_text ? nil : c.page_name ) }.compact.uniq
49: end
50: @wiki_words_cache
51: end