class Media::LibreOfficeTransmogrifier
Public Class Methods
available?()
click to toggle source
# File lib/media/transmogrifiers/libreoffice.rb, line 55 def self.available? command_available?(LIBREOFFICE_COMMAND) end
input_types()
click to toggle source
# File lib/media/transmogrifiers/libreoffice.rb, line 24 def self.input_types %w( text/plain text/html text/richtext application/rtf text/csv text/comma-separated-values application/msword application/mswrite application/powerpoint application/excel application/access application/vnd.ms-msword application/vnd.ms-mswrite application/vnd.ms-powerpoint application/vnd.ms-excel application/vnd.ms-access application/msword-template application/excel-template application/powerpoint-template application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.image application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.presentation application/vnd.oasis.opendocument.text-web application/vnd.oasis.opendocument.text application/vnd.oasis.opendocument.text-template application/vnd.oasis.opendocument.text-master application/vnd.oasis.opendocument.presentation-template application/vnd.oasis.opendocument.graphics-template application/vnd.oasis.opendocument.spreadsheet-template application/vnd.openxmlformats-officedocument.wordprocessingml.document ) end
output_types()
click to toggle source
# File lib/media/transmogrifiers/libreoffice.rb, line 51 def self.output_types ["application/pdf"] + input_types end
Public Instance Methods
run() { |msg| ... }
click to toggle source
# File lib/media/transmogrifiers/libreoffice.rb, line 59 def run(&block) status = nil # make a unique temporary directory for output, so that the filename won't collide. Dir.mktmpdir do |work_directory| # run command ext = extension(output_type) if ext arguments = [ LIBREOFFICE_COMMAND, '--headless', "-env:UserInstallation=file://#{work_directory}/home", '-convert-to', extension(output_type), '-outdir', work_directory, input_file ] status = run_command(*arguments, &block) # we cannot specify the name of the output file, so grab what it generated and move it to self.output_file libreoffice_output = work_directory + '/' + replace_extension(input_file, extension(output_type)) if File.exist?(libreoffice_output) replace_file from: libreoffice_output, to: output_file else msg = ["Error: Could not find libreoffice output %s \n" % output_file] msg << arguments.join(' ') msg += Dir[work_directory + '/*'] unless command_output.empty? msg << 'LibreOffice said:' msg << command_output end msg = msg.join("\n") error msg yield(msg) if block_given? return :failure end else yield('could not find extension for type %s' % output_type) if block_given? return :failure end end return status end