Class: Asciidoctor::Diagram::StructurizrConverter

Inherits:
Object
  • Object
show all
Includes:
DiagramConverter
Defined in:
lib/asciidoctor-diagram/structurizr/converter.rb

Constant Summary collapse

CLASSPATH_ENV =
Java.environment_variable('DIAGRAM_STRUCTURIZR_CLASSPATH')
CLI_HOME_ENV =
Java.environment_variable('DIAGRAM_STRUCTURIZRCLI_HOME')
STRUCTURIZR_JARS =
if CLASSPATH_ENV
  CLASSPATH_ENV.split(File::PATH_SEPARATOR)
elsif CLI_HOME_ENV
  lib_dir = File.expand_path('lib', CLI_HOME_ENV)
  Dir[File.join(lib_dir, '*.jar')]
else
  nil
end

Instance Method Summary collapse

Methods included from DiagramConverter

#native_scaling?, #wrap_source

Instance Method Details

#collect_options(source) ⇒ Object



34
35
36
37
38
39
# File 'lib/asciidoctor-diagram/structurizr/converter.rb', line 34

def collect_options(source)
  {
    :view => source.attr('view'),
    :renderer => Renderers.get_renderer_type(source)
  }
end

#convert(source, format, options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/asciidoctor-diagram/structurizr/converter.rb', line 41

def convert(source, format, options)
  unless STRUCTURIZR_JARS
    raise "Could not load Structurizr. Specify the location of the Structurizr JAR(s) using the 'DIAGRAM_STRUCTURIZRCLI_HOME' or DIAGRAM_STRUCTURIZR_CLASSPATH' environment variable."
  end

  Java.load

  headers = {
    'Accept' => Renderers.mime_type(options[:renderer])
  }
  headers['X-Structurizr-View'] = options[:view] if options[:view]
  headers['X-Structurizr-IncludeDir'] = Platform.native_path(source.base_dir)


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

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

  response[:body].force_encoding(Encoding::UTF_8)
end

#supported_formatsObject



30
31
32
# File 'lib/asciidoctor-diagram/structurizr/converter.rb', line 30

def supported_formats
  [:txt]
end