Class: Asciidoctor::Diagram::OxdrawConverter

Inherits:
Object
  • Object
show all
Includes:
CliGenerator, DiagramConverter
Defined in:
lib/asciidoctor-diagram/oxdraw/converter.rb

Instance Method Summary collapse

Methods included from CliGenerator

#generate_file, #generate_file_stdout, #generate_stdin, #generate_stdin_file, #generate_stdin_stdout

Methods included from DiagramConverter

#wrap_source

Instance Method Details

#collect_options(source) ⇒ Object



20
21
22
23
24
25
# File 'lib/asciidoctor-diagram/oxdraw/converter.rb', line 20

def collect_options(source)
  {
    :background => source.attr('background'),
    :scale => source.attr('scale')
  }
end

#convert(source, format, options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/asciidoctor-diagram/oxdraw/converter.rb', line 27

def convert(source, format, options)
  data = generate_stdin(source.find_command('oxdraw'), format.to_s, source.code) do |tool_path, output_path|
    args = [tool_path]

    options.each_pair do |key, value|
      unless value.nil?
        args << "--#{key.to_s.gsub('_', '-')}"
        args << value
      end
    end

    args << '--input'
    args << '-'
    args << '--output'
    args << Platform.native_path(output_path)
    args << '--output-format'
    args << format.to_s
    args << '--quiet'

    {
      :args => args,
      :chdir => source.base_dir
    }
  end

  # oxdraw doesn't perform scaling for SVG files, so we have to do it ourselves since we claim to support native
  # scaling
  if format == :svg && options[:scale]
    scale = options[:scale].to_f
    data.sub!(/(<svg.*width=")([0-9]+)(".*>)/) { |_| $1 + ($2.to_i * scale).to_i.to_s + $3 }
    data.sub!(/(<svg.*height=")([0-9]+)(".*>)/) { |_| $1 + ($2.to_i * scale).to_i.to_s + $3 }
  end

  data
end

#native_scaling?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/asciidoctor-diagram/oxdraw/converter.rb', line 16

def native_scaling?
  true
end

#supported_formatsObject



12
13
14
# File 'lib/asciidoctor-diagram/oxdraw/converter.rb', line 12

def supported_formats
  [:svg, :png]
end