Class: Asciidoctor::Diagram::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/asciidoctor-diagram/http/server.rb

Instance Method Summary collapse

Instance Method Details

#get_converter(type) ⇒ Object



61
62
63
64
65
66
67
68
# 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, source, attributes) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/asciidoctor-diagram/http/server.rb', line 70

def render_diagram(type, accepts, source, 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(type.downcase, source, attributes)
  options = converter.collect_options(source)
  diagram = converter.convert(source, format, options)

  content_type to_mime_type(format)
  diagram
end

#to_mime_type(type) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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