Class: Asciidoctor::Diagram::DitaaConverter
- Inherits:
-
Object
- Object
- Asciidoctor::Diagram::DitaaConverter
- Includes:
- DiagramConverter
- Defined in:
- lib/asciidoctor-diagram/ditaa/converter.rb
Constant Summary collapse
- OPTIONS =
{ :scale => lambda { |o, v| o << '--scale' << v if v }, :tabs => lambda { |o, v| o << '--tabs' << v if v }, :background => lambda { |o, v| o << '--background' << v if v }, :antialias => lambda { |o, v| o << '--no-antialias' if v == 'false' }, :separation => lambda { |o, v| o << '--no-separation' if v == 'false'}, :round_corners => lambda { |o, v| o << '--round-corners' if v == 'true'}, :shadows => lambda { |o, v| o << '--no-shadows' if v == 'false'}, :debug => lambda { |o, v| o << '--debug' if v == 'true'}, :fixed_slope => lambda { |o, v| o << '--fixed-slope' if v == 'true'}, :transparent => lambda { |o, v| o << '--transparent' if v == 'true'}, :bullet_characters => lambda { |o, v| o << '--bullet-characters' << v if v } }
- CLASSPATH_ENV =
Java.environment_variable('DIAGRAM_DITAA_CLASSPATH')
- DITAA_JARS =
if CLASSPATH_ENV CLASSPATH_ENV.split(File::PATH_SEPARATOR) else begin require 'asciidoctor-diagram/ditaa/classpath' ::Asciidoctor::Diagram::DitaaClasspath::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 DiagramConverter
Instance Method Details
#collect_options(source) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 48 def (source) = {} OPTIONS.keys.each do |option| attr_name = option.to_s.tr('_', '-') [option] = source.attr(attr_name) || source.attr(attr_name, nil, 'ditaa-option') end end |
#convert(source, format, options) ⇒ Object
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 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 63 def convert(source, format, ) return source.to_s if format == :txt unless DITAA_JARS raise "Could not load Ditaa. Either require 'asciidoctor-diagram-ditaamini' or specify the location of the Ditaa JAR(s) using the 'DIAGRAM_DITAA_CLASSPATH' environment variable." end Java.load flags = [] .each do |option, value| OPTIONS[option].call(flags, value) end = flags.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 => '/ditaa', :body => source.to_s, :headers => headers ) unless response[:code] == 200 raise Java.create_error("Ditaa image generation failed", response) end response[:body] end |
#native_scaling? ⇒ Boolean
59 60 61 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 59 def native_scaling? true end |
#supported_formats ⇒ Object
44 45 46 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 44 def supported_formats [:png, :svg, :txt] end |