class Asciidoctor::Diagram::PlantUmlConverter

@private

Constants

CLASSPATH_ENV
LIB_DIR
PLANTUML_JARS

Public Instance Methods

add_common_headers(headers, source) click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 55
def add_common_headers(headers, source)
  base_dir = source.base_dir

  config_file = source.attr('plantumlconfig', nil, true) || source.attr('config')
  if config_file
    headers['X-PlantUML-Config'] = File.expand_path(config_file, base_dir)
  end

  headers['X-PlantUML-Basedir'] = Platform.native_path(File.expand_path(base_dir))

  include_dir = source.attr('includedir')
  if include_dir
    headers['X-PlantUML-IncludeDir'] = Platform.native_path(File.expand_path(include_dir, base_dir))
  end
end
add_size_limit_header(headers, limit) click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 75
def add_size_limit_header(headers, limit)
  headers['X-PlantUML-SizeLimit'] = limit if limit
end
add_theme_header(headers, theme) click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 71
def add_theme_header(headers, theme)
  headers['X-PlantUML-Theme'] = theme if theme
end
collect_options(source) click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 38
def collect_options(source)
  options = {
      :size_limit => source.attr('size-limit', '4096'),
  }

  options[:smetana] = true if source.opt('smetana')

  theme = source.attr('theme', nil)
  options[:theme] = theme if theme

  options
end
convert(source, format, options) click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 79
def convert(source, format, options)
  unless PLANTUML_JARS
    raise "Could not load PlantUML. Either require 'asciidoctor-diagram-plantuml' or specify the location of the PlantUML JAR(s) using the 'DIAGRAM_PLANTUML_CLASSPATH' environment variable."
  end
  Java.load

  code = source.code

  case format
  when :png
    mime_type = 'image/png'
  when :svg
    mime_type = 'image/svg+xml'
  when :txt, :utxt
    mime_type = 'text/plain;charset=utf-8'
  when :atxt
    mime_type = 'text/plain'
  else
    raise "Unsupported format: #{format}"
  end

  headers = {
      'Accept' => mime_type
  }

  unless should_preprocess(source)
    add_common_headers(headers, source)
  end

  add_theme_header(headers, options[:theme])
  add_size_limit_header(headers, options[:size_limit])

  if options[:smetana]
    headers['X-Graphviz'] = 'smetana'
  else
    dot = source.find_command('dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
    if dot
      headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot)
    end
  end

  response = Java.send_request(
      :url => '/plantuml',
      :body => code,
      :headers => headers
  )

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

  response[:body]
end
should_preprocess(source) click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 51
def should_preprocess(source)
  source.attr('preprocess', 'true') == 'true'
end
supported_formats() click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 34
def supported_formats
  [:png, :svg, :txt, :atxt, :utxt]
end
wrap_source(source) click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 30
def wrap_source(source)
  PlantUMLPreprocessedSource.new(source, self)
end