Class: Asciidoctor::Diagram::GnuplotConverter

Inherits:
Object
  • Object
show all
Includes:
CliGenerator, DiagramConverter
Defined in:
lib/asciidoctor-diagram/gnuplot/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

#native_scaling?, #wrap_source

Instance Method Details

#collect_options(source) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/asciidoctor-diagram/gnuplot/converter.rb', line 17

def collect_options(source)
  {
      :width => source.attr('width'),
      :height => source.attr('height'),
      :transparent => source.attr('transparent'),
      :crop => source.attr('crop'),
      :font => source.attr('font'),
      :fontscale => source.attr('fontscale'),
      :background => source.attr('background'),
  }
end

#convert(source, format, options) ⇒ Object



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
62
63
64
65
# File 'lib/asciidoctor-diagram/gnuplot/converter.rb', line 29

def convert(source, format, options)
  if format == :txt || format == :literal
    terminal = 'dumb'
  else
    terminal = format.to_s
  end
  code = "set term #{terminal}"

  width = options[:width]
  height = options[:height]
  code << " size #{width},#{height}" unless width.nil? or height.nil?

  transparent = options[:transparent]
  code << (transparent ? " transparent" : " notransparent") unless transparent.nil?

  crop = options[:crop]
  code << (crop ? " crop" : " nocrop") unless crop.nil?

  font = options[:font]
  code << %( font "#{font}") unless font.nil?

  font_scale = options[:fontscale]
  code << " fontscale #{font_scale}" unless font_scale.nil?

  background = options[:background]
  code << %( background "#{background}") unless background.nil?

  code << "\n"
  code << source.to_s

  generate_stdin_stdout(source.find_command('gnuplot'), code) do |tool|
    {
      :args => [tool],
      :chdir => source.base_dir
    }
  end
end

#supported_formatsObject



13
14
15
# File 'lib/asciidoctor-diagram/gnuplot/converter.rb', line 13

def supported_formats
  [:png, :svg, :gif, :txt, :literal]
end