class Asciidoctor::Diagram::SyntraxConverter

@private

Constants

CLASSPATH_ENV
CLI_HOME_ENV
JSYNTRAX_JARS

Public Instance Methods

collect_options(source) click to toggle source
# File lib/asciidoctor-diagram/syntrax/converter.rb, line 37
def collect_options(source)
  {
      :heading => source.attr('heading'),
      :scale => source.attr('scale'),
      :transparent => source.attr('transparent'),
      :style => source.attr('style-file') || source.attr("#{source.diagram_type}-style", nil, true)
  }
end
convert(source, format, options) click to toggle source
# File lib/asciidoctor-diagram/syntrax/converter.rb, line 46
def convert(source, format, options)
  shared_args = []
  title = options[:heading]
  if title
    shared_args << '--title' << title
  end

  scale = options[:scale]
  if scale
    shared_args << '--scale' << scale
  end

  transparent = options[:transparent]
  if transparent == 'true'
    shared_args << '--transparent'
  end
  style = options[:style]
  if style
    shared_args << '--style' << style
  end

  if JSYNTRAX_JARS
    Java.load

    options_string = shared_args.join(' ')

    case format
    when :png
      mime_type = 'image/png'
    when :svg
      mime_type = 'image/svg+xml'
    else
      raise "Unsupported format: #{format}"
    end

    headers = {
      'Accept' => mime_type,
      'X-Options' => options_string
    }

    response = Java.send_request(
      :url => '/syntrax',
      :body => source.to_s,
      :headers => headers
    )

    unless response[:code] == 200
      raise Java.create_error("JSyntrax code generation failed", response)
    end

    response[:body]
  else
    generate_file(source.find_command('syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path|
      {
        :args => ([tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)] + shared_args),
        :chdir => source.base_dir
      }
    end
  end

end
native_scaling?() click to toggle source
# File lib/asciidoctor-diagram/syntrax/converter.rb, line 108
def native_scaling?
  true
end
supported_formats() click to toggle source
# File lib/asciidoctor-diagram/syntrax/converter.rb, line 33
def supported_formats
  [:png, :svg]
end