Class: Revision
- Inherits:
-
Object
- Object
- Revision
- Defined in:
- app/models/revision.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#content ⇒ Object
Returns the value of attribute content.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#number ⇒ Object
Returns the value of attribute number.
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
- #clear_display_cache ⇒ Object
- #created_on ⇒ Object
-
#display_content ⇒ Object
Explicit check for new type of display cache with find_chunks method.
- #display_content_for_export ⇒ Object
- #display_diff ⇒ Object
- #display_published ⇒ Object
-
#existing_pages ⇒ Object
Returns an array of all the WikiWords present in the content of this revision.
-
#initialize(page, number, content, created_at, author) ⇒ Revision
constructor
A new instance of Revision.
- #next_revision ⇒ Object
- #pretty_created_at ⇒ Object
- #previous_revision ⇒ Object
-
#unexisting_pages ⇒ Object
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.
-
#wiki_words ⇒ Object
Returns an array of all the WikiWords present in the content of this revision.
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, ) @page, @number, @created_at, @author = page, number, created_at, self.content = content end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
13 14 15 |
# File 'app/models/revision.rb', line 13 def @author end |
#content ⇒ Object
Returns the value of attribute content.
13 14 15 |
# File 'app/models/revision.rb', line 13 def content @content end |
#created_at ⇒ Object
Returns the value of attribute created_at.
13 14 15 |
# File 'app/models/revision.rb', line 13 def created_at @created_at end |
#number ⇒ Object
Returns the value of attribute number.
13 14 15 |
# File 'app/models/revision.rb', line 13 def number @number end |
#page ⇒ Object
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_cache ⇒ Object
80 81 82 |
# File 'app/models/revision.rb', line 80 def clear_display_cache @display_cache = @published_cache = @wiki_words_cache = nil end |
#created_on ⇒ Object
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_content ⇒ Object
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_export ⇒ Object
88 89 90 |
# File 'app/models/revision.rb', line 88 def display_content_for_export WikiContent.new(self, {:mode => :export} ) end |
#display_diff ⇒ Object
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_published ⇒ Object
84 85 86 |
# File 'app/models/revision.rb', line 84 def display_published @published_cache ||= WikiContent.new(self, {:mode => :publish}) end |
#existing_pages ⇒ Object
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_revision ⇒ Object
36 37 38 |
# File 'app/models/revision.rb', line 36 def next_revision page.revisions[number + 1] end |
#pretty_created_at ⇒ Object
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_revision ⇒ Object
40 41 42 |
# File 'app/models/revision.rb', line 40 def previous_revision number - 1 >= 0 && page.revisions[number - 1] end |
#unexisting_pages ⇒ Object
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_words ⇒ Object
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 |