class Asciidoctor::Diagram::D2Converter

@private

Public Instance Methods

collect_options(source) click to toggle source
# File lib/asciidoctor-diagram/d2/converter.rb, line 16
def collect_options(source)
  {
    :layout => source.attr('layout'),
    :theme => source.attr('theme'),
    :pad => source.attr('pad'),
    :animate_interval => source.attr('animate-interval'),
    :sketch => source.attr('sketch'),
    :font_regular => source.attr('font-regular'),
    :font_italic => source.attr('font-italic'),
    :font_bold => source.attr('font-bold')
  }
end
convert(source, format, options) click to toggle source
# File lib/asciidoctor-diagram/d2/converter.rb, line 29
def convert(source, format, options)
  generate_stdin(source.find_command('d2'), format.to_s, source.code) do |tool_path, output_path|
    args = [tool_path, '--browser', 'false']

    options.each_pair do |key, value|
      flag = "--#{key.to_s.gsub('_', '-')}"

      if key == :sketch && !value.nil? && value != 'false'
        args << flag
      elsif key.to_s.start_with?('font') && !value.nil?
        args << Platform.native_path(value)
      elsif !value.nil?
        args << flag
        args << value
      end
    end

    args << '-'
    args << Platform.native_path(output_path)

    {
      :args => args,
      :chdir => source.base_dir
    }
  end
end
supported_formats() click to toggle source
# File lib/asciidoctor-diagram/d2/converter.rb, line 12
def supported_formats
  [:svg, :png, :pdf]
end