class Rabbit::ImageManipulable::Dia

Constants

DIA_COMMANDS

Public Class Methods

match?(filename) click to toggle source
# File lib/rabbit/image/dia.rb, line 33
def match?(filename)
  return true if File.extname(filename).downcase.end_with?(".dia")

  File.open(filename) do |f|
    begin
      first_line = f.gets
      second_line = f.gets
      return false unless second_line
      return false unless first_line.start_with?("<?xml")
      return false unless second_line.start_with?("<dia:diagram")
      true
    rescue EncodingError
      false
    end
  end
end
new(filename, props) click to toggle source
Calls superclass method Rabbit::ImageManipulable::Base::new
# File lib/rabbit/image/dia.rb, line 58
def initialize(filename, props)
  init_svg_loader(filename, props)
  super
end

Private Instance Methods

init_svg_loader(filename, props) click to toggle source
# File lib/rabbit/image/dia.rb, line 64
def init_svg_loader(filename, props)
  @svg_file = Tempfile.new(["rabbit-loader-dia", ".svg"])
  args = ["--export=#{@svg_file.path}"]
  args << "--filter=svg"
  args << filename
  if DIA_COMMANDS.any? {|dia| run(dia, *args)}
    @svg_loader = SVG.new(@svg_file.path, props)
  else
    raise DiaCanNotHandleError.new("dia #{args.join(' ')}",
                                   DIA_COMMANDS)
  end
end
load_image() click to toggle source
# File lib/rabbit/image/dia.rb, line 77
def load_image
  # do nothing
end