module Asciidoctor::Diagram::Ditaa

@private

Constants

JARS
OPTIONS

Public Class Methods

included(mod) click to toggle source
# File lib/asciidoctor-diagram/ditaa/extension.rb, line 28
def self.included(mod)
  mod.register_format(:png, :image) do |parent, source|
    ditaa(parent, source, 'image/png')
  end

  mod.register_format(:svg, :image) do |parent, source|
    ditaa(parent, source, 'image/svg+xml')
  end
end

Public Instance Methods

ditaa(parent, source, mime_type) click to toggle source
# File lib/asciidoctor-diagram/ditaa/extension.rb, line 38
def ditaa(parent, source, mime_type)
  Java.load

  global_attributes = parent.document.attributes

  options = []

  OPTIONS.keys.each do |key|
    value = source.attributes.delete(key) || global_attributes["ditaa-option-#{key}"]
    OPTIONS[key].call(options, value)
  end

  options_string = options.join(' ')

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

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

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

  response[:body]
end