Class: WikiContent::Version

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

Instance Method Summary collapse

Instance Method Details

#current_version?Boolean

Return true if the content is the current page content

Returns:

  • (Boolean)

118
119
120
# File 'app/models/wiki_content.rb', line 118

def current_version?
  page.content.version == self.version
end

#nextObject

Returns the next version or nil


131
132
133
134
135
136
# File 'app/models/wiki_content.rb', line 131

def next
  @next ||= WikiContent::Version.
    reorder('version ASC').
    includes(:author).
    where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first
end

#previousObject

Returns the previous version or nil


123
124
125
126
127
128
# File 'app/models/wiki_content.rb', line 123

def previous
  @previous ||= WikiContent::Version.
    reorder('version DESC').
    includes(:author).
    where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first
end

#projectObject


113
114
115
# File 'app/models/wiki_content.rb', line 113

def project
  page.project
end

#textObject


99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/wiki_content.rb', line 99

def text
  @text ||= begin
    str = case compression
          when 'gzip'
            Zlib::Inflate.inflate(data)
          else
            # uncompressed data
            data
          end
    str.force_encoding("UTF-8")
    str
  end
end

#text=(plain) ⇒ Object


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/wiki_content.rb', line 82

def text=(plain)
  case Setting.wiki_compression
  when 'gzip'
  begin
    self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)
    self.compression = 'gzip'
  rescue
    self.data = plain
    self.compression = ''
  end
  else
    self.data = plain
    self.compression = ''
  end
  plain
end