Class: Asciidoctor::Diagram::VegaConverter

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



18
19
20
21
22
# File 'lib/asciidoctor-diagram/vega/converter.rb', line 18

def collect_options(source)
  {
      :vegalite => source.diagram_type.to_s.include?('lite') || source.attr('vegalite')
  }
end

#convert(source, format, options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/asciidoctor-diagram/vega/converter.rb', line 24

def convert(source, format, options)
  base_dir = source.base_dir

  code = source.to_s

  if code.include?('/schema/vega-lite/') || options[:vegalite]
    vega_code = generate_stdin_stdout(source.find_command("vl2vg"), code)
  else
    vega_code = code
  end

  generate_stdin_stdout(source.find_command("vg2#{format}"), vega_code) do |tool_path|
    args = [tool_path, '--base', Platform.native_path(base_dir)]
    if format == :svg
      args << '--header'
    end

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

#supported_formatsObject



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

def supported_formats
  [:svg, :png]
end