Class: Revision

Inherits:
Object
  • Object
show all
Defined in:
app/models/revision.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, number, content, created_at, author) ⇒ Revision

Returns a new instance of Revision.



15
16
17
18
# File 'app/models/revision.rb', line 15

def initialize(page, number, content, created_at, author)
  @page, @number, @created_at, @author = page, number, created_at, author
  self.content = content
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



13
14
15
# File 'app/models/revision.rb', line 13

def author
  @author
end

#contentObject

Returns the value of attribute content.



13
14
15
# File 'app/models/revision.rb', line 13

def content
  @content
end

#created_atObject

Returns the value of attribute created_at.



13
14
15
# File 'app/models/revision.rb', line 13

def created_at
  @created_at
end

#numberObject

Returns the value of attribute number.



13
14
15
# File 'app/models/revision.rb', line 13

def number
  @number
end

#pageObject

Returns the value of attribute page.



13
14
15
# File 'app/models/revision.rb', line 13

def page
  @page
end

Instance Method Details

#clear_display_cacheObject



78
79
80
# File 'app/models/revision.rb', line 78

def clear_display_cache
  @display_cache = @published_cache = @wiki_words_cache = nil
end

#created_onObject



25
26
27
# File 'app/models/revision.rb', line 25

def created_on
  Date.new(@created_at.year, @created_at.mon, @created_at.day)
end

#display_contentObject

Explicit check for new type of display cache with find_chunks method. Ensures new version works with older snapshots.



67
68
69
70
71
72
# File 'app/models/revision.rb', line 67

def display_content
  unless @display_cache && @display_cache.respond_to?(:find_chunks)
    @display_cache = WikiContent.new(self)
  end
  @display_cache
end

#display_content_for_exportObject



87
88
89
# File 'app/models/revision.rb', line 87

def display_content_for_export
  WikiContent.new(self, {:mode => :export} )
end

#display_diffObject



74
75
76
# File 'app/models/revision.rb', line 74

def display_diff
  previous_revision ? HTMLDiff.diff(previous_revision.display_content, display_content) : display_content
end

#display_publishedObject



82
83
84
85
# File 'app/models/revision.rb', line 82

def display_published
  @published_cache = WikiContent.new(self, {:mode => :publish}) if @published_cache.nil?
  @published_cache
end

#existing_pagesObject

Returns an array of all the WikiWords present in the content of this revision. that already exists as a page in the web.



55
56
57
# File 'app/models/revision.rb', line 55

def existing_pages
  wiki_words.select { |wiki_word| page.web.pages[wiki_word] }
end

#next_revisionObject



36
37
38
# File 'app/models/revision.rb', line 36

def next_revision
  page.revisions[number + 1]
end

#pretty_created_atObject



29
30
31
32
33
34
# File 'app/models/revision.rb', line 29

def pretty_created_at
  # Must use DateTime because Time doesn't support %e on at least some platforms
  DateTime.new(
    @created_at.year, @created_at.mon, @created_at.day, @created_at.hour, @created_at.min
  ).strftime "%B %e, %Y %H:%M" 
end

#previous_revisionObject



40
41
42
# File 'app/models/revision.rb', line 40

def previous_revision
  number - 1 >= 0 && page.revisions[number - 1]
end

#unexisting_pagesObject

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.



61
62
63
# File 'app/models/revision.rb', line 61

def unexisting_pages
  wiki_words - existing_pages
end

#wiki_wordsObject

Returns an array of all the WikiWords present in the content of this revision.



45
46
47
48
49
50
51
# File 'app/models/revision.rb', line 45

def wiki_words
  unless @wiki_words_cache 
    wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink)
    @wiki_words_cache = wiki_chunks.map { |c| ( c.escaped_text ? nil : c.page_name ) }.compact.uniq
  end
  @wiki_words_cache
end