cirandas.net

ref: master

plugins/web_odf/models/web_odf_plugin/document.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class WebODFPlugin::Document < Article

  def self.icon_name article = nil
    'web-odf-document'
  end

  def self.short_description
    I18n.t'web_odf_plugin.models.document.short_description'
  end

  def self.description
    I18n.t'web_odf_plugin.models.document.description'
  end

  def self.can_display_blocks?
    false
  end

  # #body method override will crash due to binary on db adapter, so use #odf
  def odf
    Base64.decode64 self[:body]
  end
  def body= value
    self[:body] = Base64.encode64 value.split(',').map(&:to_i).pack('C*')
  end

  def filename
    "#{self.name}.odt"
  end

  def to_html options = {}
    lambda do
      render template: 'content_viewer/web_odf_plugin/document'
    end
  end

end