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 chunks_by_type 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.
- #force_rendering ⇒ Object
-
#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_includes ⇒ Object
Returns an array of all the WikiIncludes present in the content of this revision.
-
#wiki_references ⇒ Object
Returns an array of all the WikiReferences present in the content of this revision.
-
#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.
12 13 14 15 16 |
# File 'app/models/revision.rb', line 12 def initialize(page, number, content, created_at, ) @page, @number, @created_at, @author = page, number, created_at, self.content = content @display_cache = nil end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
10 11 12 |
# File 'app/models/revision.rb', line 10 def @author end |
#content ⇒ Object
Returns the value of attribute content.
10 11 12 |
# File 'app/models/revision.rb', line 10 def content @content end |
#created_at ⇒ Object
Returns the value of attribute created_at.
10 11 12 |
# File 'app/models/revision.rb', line 10 def created_at @created_at end |
#number ⇒ Object
Returns the value of attribute number.
10 11 12 |
# File 'app/models/revision.rb', line 10 def number @number end |
#page ⇒ Object
Returns the value of attribute page.
10 11 12 |
# File 'app/models/revision.rb', line 10 def page @page end |
Instance Method Details
#clear_display_cache ⇒ Object
90 91 92 93 |
# File 'app/models/revision.rb', line 90 def clear_display_cache @wiki_words_cache = @published_cache = @display_cache = @wiki_includes_cache = @wiki_references_cache = nil end |
#created_on ⇒ Object
18 19 20 |
# File 'app/models/revision.rb', line 18 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 chunks_by_type method. Ensures new version works with older snapshots.
78 79 80 81 82 83 84 |
# File 'app/models/revision.rb', line 78 def display_content unless @display_cache && @display_cache.respond_to?(:chunks_by_type) @display_cache = WikiContent.new(self) @display_cache.render! end @display_cache end |
#display_content_for_export ⇒ Object
103 104 105 |
# File 'app/models/revision.rb', line 103 def display_content_for_export WikiContent.new(self, {:mode => :export} ).render! end |
#display_diff ⇒ Object
86 87 88 |
# File 'app/models/revision.rb', line 86 def display_diff previous_revision ? HTMLDiff.diff(previous_revision.display_content, display_content) : display_content end |
#display_published ⇒ Object
95 96 97 98 99 100 101 |
# File 'app/models/revision.rb', line 95 def display_published unless @published_cache && @published_cache.respond_to?(:chunks_by_type) @published_cache = WikiContent.new(self, {:mode => :publish}) @published_cache.render! end @published_cache 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.
66 67 68 |
# File 'app/models/revision.rb', line 66 def existing_pages wiki_words.select { |wiki_word| page.web.pages[wiki_word] } end |
#force_rendering ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/models/revision.rb', line 107 def force_rendering begin display_content.render! rescue Exception => e ApplicationController.logger.error "Failed rendering page #{@name}" ApplicationController.logger.error e = e..gsub(/\n/, '<br/>') # substitute content with an error message content = <<-EOL <p>Markup engine has failed to render this page, raising the following error:</p> <p>#{}</p> EOL raise e end end |
#next_revision ⇒ Object
29 30 31 |
# File 'app/models/revision.rb', line 29 def next_revision page.revisions[number + 1] end |
#pretty_created_at ⇒ Object
22 23 24 25 26 27 |
# File 'app/models/revision.rb', line 22 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
33 34 35 |
# File 'app/models/revision.rb', line 33 def previous_revision number > 0 ? page.revisions[number - 1] : nil 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.
72 73 74 |
# File 'app/models/revision.rb', line 72 def unexisting_pages wiki_words - existing_pages end |
#wiki_includes ⇒ Object
Returns an array of all the WikiIncludes present in the content of this revision.
38 39 40 41 42 43 44 |
# File 'app/models/revision.rb', line 38 def wiki_includes unless @wiki_includes_cache chunks = display_content.find_chunks(Include) @wiki_includes_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq end @wiki_includes_cache end |
#wiki_references ⇒ Object
Returns an array of all the WikiReferences present in the content of this revision.
47 48 49 50 51 52 53 |
# File 'app/models/revision.rb', line 47 def wiki_references unless @wiki_references_cache chunks = display_content.find_chunks(WikiChunk::WikiReference) @wiki_references_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq end @wiki_references_cache end |
#wiki_words ⇒ Object
Returns an array of all the WikiWords present in the content of this revision.
56 57 58 59 60 61 62 |
# File 'app/models/revision.rb', line 56 def wiki_words unless @wiki_words_cache wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink) @wiki_words_cache = wiki_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq end @wiki_words_cache end |