Class: Asciidoctor::Diagram::SyntraxConverter
- Inherits:
-
Object
- Object
- Asciidoctor::Diagram::SyntraxConverter
- Includes:
- CliGenerator, DiagramConverter
- Defined in:
- lib/asciidoctor-diagram/syntrax/converter.rb
Constant Summary collapse
- CLASSPATH_ENV =
Java.environment_variable('DIAGRAM_JSYNTRAX_CLASSPATH')
- CLI_HOME_ENV =
Java.environment_variable('DIAGRAM_JSYNTRAX_HOME')
- JSYNTRAX_JARS =
if CLASSPATH_ENV CLASSPATH_ENV.split(File::PATH_SEPARATOR) elsif CLI_HOME_ENV lib_dir = File.('lib', CLI_HOME_ENV) Dir.children(lib_dir).select { |c| c.end_with? '.jar' }.map { |c| File.(c, lib_dir) } else begin require 'asciidoctor-diagram/jsyntrax/classpath' ::Asciidoctor::Diagram::JsyntraxClasspath::JAR_FILES rescue LoadError nil end end
Instance Method Summary collapse
- #collect_options(source) ⇒ Object
- #convert(source, format, options) ⇒ Object
- #native_scaling? ⇒ Boolean
- #supported_formats ⇒ Object
Methods included from CliGenerator
#generate_file, #generate_file_stdout, #generate_stdin, #generate_stdin_file, #generate_stdin_stdout
Methods included from DiagramConverter
Instance Method Details
#collect_options(source) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/asciidoctor-diagram/syntrax/converter.rb', line 37 def (source) { :heading => source.attr('heading'), :scale => source.attr('scale'), :transparent => source.attr('transparent'), :style => source.attr('style-file') || source.attr("#{source.diagram_type}-style", nil, true) } end |
#convert(source, format, options) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/asciidoctor-diagram/syntrax/converter.rb', line 46 def convert(source, format, ) shared_args = [] title = [:heading] if title shared_args << '--title' << title end scale = [:scale] if scale shared_args << '--scale' << scale end transparent = [:transparent] if transparent == 'true' shared_args << '--transparent' end style = [:style] if style shared_args << '--style' << style end if JSYNTRAX_JARS Java.load = shared_args.join(' ') case format when :png mime_type = 'image/png' when :svg mime_type = 'image/svg+xml' else raise "Unsupported format: #{format}" end headers = { 'Accept' => mime_type, 'X-Options' => } response = Java.send_request( :url => '/syntrax', :body => source.to_s, :headers => headers ) unless response[:code] == 200 raise Java.create_error("JSyntrax code generation failed", response) end response[:body] else generate_file(source.find_command('syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path| { :args => ([tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)] + shared_args), :chdir => source.base_dir } end end end |
#native_scaling? ⇒ Boolean
108 109 110 |
# File 'lib/asciidoctor-diagram/syntrax/converter.rb', line 108 def native_scaling? true end |
#supported_formats ⇒ Object
33 34 35 |
# File 'lib/asciidoctor-diagram/syntrax/converter.rb', line 33 def supported_formats [:png, :svg] end |