module Asciidoctor::Diagram::Office

@private

Constants

VERSION

Public Class Methods

included(mod) click to toggle source
# File lib/asciidoctor-diagram-office/extension.rb, line 51
def self.included(mod)
  [:png, :svg].each do |f|
    mod.register_format(f, :image) do |parent, source|
      office(parent, source, f)
    end
  end
end

Public Instance Methods

office(parent_block, source, format) click to toggle source
# File lib/asciidoctor-diagram-office/extension.rb, line 59
def office(parent_block, source, format)
  inherit_prefix = name

  options = {}

  unoconv = which(parent_block, 'unoconv', :raise_on_error => false)
  inkscape = which(parent_block, 'inkscape', :raise_on_error => false)

  if unoconv
    OfficeServer.listen
    options[:page] = source.attr('page', '1', inherit_prefix)
    run_convert(unoconv, inkscape, source, format, options)
  end
end

Private Instance Methods

run_convert(unoconv, inkscape, source, format, options = {}) click to toggle source
# File lib/asciidoctor-diagram-office/extension.rb, line 75
def run_convert(unoconv, inkscape, source, format, options = {})
  # office document => PDF
  pdf = generate_file(unoconv, 'office', 'pdf', source.to_s) do |tool_path, input_path, output_path|
    args = [tool_path, '-f', 'pdf', '-e', "PageRange=#{options[:page]}-#{options[:page]}", '-o', Platform.native_path(output_path), Platform.native_path(input_path)]
    args
  end
  
  # PDF => target format
  if inkscape
    generate_file(inkscape, 'pdf', format.to_s, pdf) do |tool_path, input_path, output_path|
      case format.to_s
      when 'png'
        args = [tool_path, '-f', Platform.native_path(input_path), '-e', Platform.native_path(output_path)]
      when 'svg'
        args = [tool_path, '-f', Platform.native_path(input_path), '-l', Platform.native_path(output_path)]
      end
      args
    end
  else
    generate_file(unoconv, 'pdf', format.to_s, pdf) do |tool_path, input_path, output_path|
      args = [tool_path, '-f', format.to_s, '-o', Platform.native_path(output_path), Platform.native_path(input_path)]
      args
    end
  end
end