Module: Rabbit::Parser::Ext::BlockDiag

Includes:
GetText
Defined in:
lib/rabbit/parser/ext/blockdiag.rb

Constant Summary collapse

AVAILABLE_FLAG_OPTIONS =
["antialias"]
AVAILABLE_VALUE_OPTIONS =

“font” is treated as specially.

[]

Constants included from GetText

GetText::DOMAIN

Class Method Summary collapse

Methods included from GetText

included

Class Method Details

.find_font(prop) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/rabbit/parser/ext/blockdiag.rb', line 39

def find_font(prop)
  font = prop["font"]
  return font if font and File.exist?(font)
  fonts = prop["fonts"]
  return nil if fonts.nil?
  fonts = fonts.split(/\s*,\s*/) if fonts.is_a?(String)
  fonts.find do |font|
    File.exist?(font)
  end
end

.make_image(path, prop, logger) ⇒ Object



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
# File 'lib/rabbit/parser/ext/blockdiag.rb', line 11

def make_image(path, prop, logger)
  image_file = Tempfile.new(["rabbit-image-blockdiag", ".svg"])
  command_line = [
    "-T", "svg",
    "-o", image_file.path,
  ]
  font = find_font(prop)
  command_line.concat(["-f", font]) if font
  AVAILABLE_FLAG_OPTIONS.each do |name|
    command_line << "--#{name}" if /\A(?:true|yes)\z/i =~ prop[name].to_s
  end
  AVAILABLE_VALUE_OPTIONS.each do |name|
    command_line.concat(["--#{name}", prop[name]]) if prop.has_key?(name)
  end
  command_line << path
  blockdiag_commands = ["blockdiag3", "blockdiag"]
  blockdiag_commands.each do |blockdiag|
    if SystemRunner.run(blockdiag, *command_line)
      return image_file
    end
  end
  command_line.unshift(blockdiag_commands.first)
  format = _("tried blockdiag command: %s")
  additional_info = format % command_line
  raise BlockDiagCanNotHandleError.new(command_line.join(' '),
                                       additional_info)
end