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



80
81
82
# File 'app/models/revision.rb', line 80

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.



69
70
71
72
73
74
# File 'app/models/revision.rb', line 69

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



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

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

#display_diffObject



76
77
78
# File 'app/models/revision.rb', line 76

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

#display_publishedObject



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

def display_published
  @published_cache ||= WikiContent.new(self, {:mode => :publish})
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.



57
58
59
# File 'app/models/revision.rb', line 57

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.



63
64
65
# File 'app/models/revision.rb', line 63

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
52
53
# File 'app/models/revision.rb', line 45

def wiki_words
  unless @wiki_words_cache 
    wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink)
    # BlikiLinks are used to link outside the wiki, so are not WikiLinks.
    wiki_chunks.reject! { |chunk| chunk.kind_of? WikiChunk::BlikiLink }
    @wiki_words_cache = wiki_chunks.map { |c| ( c.escaped_text ? nil : c.page_name ) }.compact.uniq
  end
  @wiki_words_cache
end