Class: WikiContent::Version

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

Instance Method Summary collapse

Instance Method Details

#attachmentsObject



121
122
123
# File 'app/models/wiki_content.rb', line 121

def attachments
  page.nil? ? [] : page.attachments
end

#current_version?Boolean

Return true if the content is the current page content

Returns:

  • (Boolean)


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

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

#nextObject

Returns the next version or nil



139
140
141
142
143
144
# File 'app/models/wiki_content.rb', line 139

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



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

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

#projectObject



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

def project
  page.project
end

#textObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/models/wiki_content.rb', line 103

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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/wiki_content.rb', line 86

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