class Asciidoctor::Diagram::Server

Public Instance Methods

get_converter(type) click to toggle source
# File lib/asciidoctor-diagram/http/server.rb, line 61
def get_converter(type)
  case type
  when :graphviz
    GraphvizConverter.new
  else
    nil
  end
end
render_diagram(type, accepts, code, attributes) click to toggle source
# File lib/asciidoctor-diagram/http/server.rb, line 70
def render_diagram(type, accepts, code, attributes)
  converter = get_converter(type.downcase.to_sym)
  return [500, "Unsupported diagram type #{type}"] unless converter

  format = converter.supported_formats.find {|f| accepts.call(f)}
  return [500, "Could not determine supported output format"] unless format

  source = ServerSource.new(code, attributes)
  options = converter.collect_options(source, type.downcase)
  diagram = converter.convert(source, format, options)

  content_type to_mime_type(format)
  diagram
end
to_mime_type(type) click to toggle source
# File lib/asciidoctor-diagram/http/server.rb, line 46
def to_mime_type(type)
  case type
  when :pdf
    'application/pdf'
  when :png
    'image/png'
  when :svg
    'image/svg'
  when :txt
    'text/plain'
  else
    nil
  end
end