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
todo: drop next_revision, previuous_revision and number from here - unused code.
- #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
92 93 94 95 |
# File 'app/models/revision.rb', line 92 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.
80 81 82 83 84 85 86 |
# File 'app/models/revision.rb', line 80 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
105 106 107 |
# File 'app/models/revision.rb', line 105 def display_content_for_export WikiContent.new(self, {:mode => :export} ).render! end |
#display_diff ⇒ Object
88 89 90 |
# File 'app/models/revision.rb', line 88 def display_diff previous_revision ? HTMLDiff.diff(previous_revision.display_content, display_content) : display_content end |
#display_published ⇒ Object
97 98 99 100 101 102 103 |
# File 'app/models/revision.rb', line 97 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.
68 69 70 |
# File 'app/models/revision.rb', line 68 def existing_pages wiki_words.select { |wiki_word| page.web.pages[wiki_word] } end |
#force_rendering ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/models/revision.rb', line 109 def force_rendering begin display_content.render! rescue => e ApplicationController.logger.error "Failed rendering page #{@name}" ApplicationController.logger.error e = e. # substitute content with an error message self.content = <<-EOL <p>Markup engine has failed to render this page, raising the following error:</p> <p>#{}</p> <pre>#{self.content}</pre> EOL clear_display_cache raise e end end |
#next_revision ⇒ Object
todo: drop next_revision, previuous_revision and number from here - unused code
31 32 33 |
# File 'app/models/revision.rb', line 31 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
35 36 37 |
# File 'app/models/revision.rb', line 35 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.
74 75 76 |
# File 'app/models/revision.rb', line 74 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.
40 41 42 43 44 45 46 |
# File 'app/models/revision.rb', line 40 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.
49 50 51 52 53 54 55 |
# File 'app/models/revision.rb', line 49 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.
58 59 60 61 62 63 64 |
# File 'app/models/revision.rb', line 58 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 |