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 =
'DIAGRAM_DITAA_CLASSPATH'
- DITAA_JARS =
if ENV.has_key?(CLASSPATH_ENV) ENV[CLASSPATH_ENV].split(File::PATH_SEPARATOR) else begin require 'asciidoctor-diagram/ditaa/classpath' ::Asciidoctor::Diagram::DitaaClasspath::JAR_FILES rescue LoadError raise "Could not load Ditaa. Eiter require 'asciidoctor-diagram-ditaamini' or specify the location of the Ditaa JAR(s) using the 'DIAGRAM_DITAA_CLASSPATH' environment variable." 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
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 46 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
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 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 61 def convert(source, format, ) return source.to_s if format == :txt 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
57 58 59 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 57 def native_scaling? true end |
#supported_formats ⇒ Object
42 43 44 |
# File 'lib/asciidoctor-diagram/ditaa/converter.rb', line 42 def supported_formats [:png, :svg, :txt] end |