class Asciidoctor::Diagram::PlantUMLPreprocessedSource

Public Class Methods

new(source, tag) click to toggle source
Calls superclass method
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 100
def initialize(source, tag)
  super(source)
  @tag = tag
end

Public Instance Methods

code() click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 105
def code
  @code ||= load_code
end
load_code() click to toggle source
# File lib/asciidoctor-diagram/plantuml/converter.rb, line 109
def load_code
  Java.load

  code = __getobj__.code

  code = "@start#{@tag}\n#{code}\n@end#{@tag}" unless code.index("@start") && code.index("@end")

  headers = {}

  config_file = attr('plantumlconfig', nil, true) || 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))

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

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

  code = response[:body]
  code.force_encoding(Encoding::UTF_8)

  code
end