Class: Asciidoctor::Diagram::PlantUmlConverter
- Inherits:
-
Object
- Object
- Asciidoctor::Diagram::PlantUmlConverter
- Includes:
- DiagramConverter
- Defined in:
- lib/asciidoctor-diagram/plantuml/converter.rb
Direct Known Subclasses
Constant Summary collapse
- CLASSPATH_ENV =
Java.environment_variable('DIAGRAM_PLANTUML_CLASSPATH')
- LIB_DIR =
File.('../..', File.dirname(__FILE__))
- PLANTUML_JARS =
if CLASSPATH_ENV CLASSPATH_ENV.split(File::PATH_SEPARATOR) else begin require 'asciidoctor-diagram/plantuml/classpath' ::Asciidoctor::Diagram::PlantUmlClasspath::JAR_FILES rescue LoadError nil end end
Instance Method Summary collapse
- #add_common_headers(headers, source) ⇒ Object
- #add_size_limit_header(headers, limit) ⇒ Object
- #add_theme_header(headers, theme) ⇒ Object
- #collect_options(source) ⇒ Object
- #convert(source, format, options) ⇒ Object
- #should_preprocess(source) ⇒ Object
- #supported_formats ⇒ Object
- #wrap_source(source) ⇒ Object
Methods included from DiagramConverter
Instance Method Details
#add_common_headers(headers, source) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 55 def add_common_headers(headers, source) base_dir = source.base_dir config_file = source.attr('plantumlconfig', nil, true) || source.attr('config') if config_file headers['X-PlantUML-Config'] = File.(config_file, base_dir) end headers['X-PlantUML-Basedir'] = Platform.native_path(File.(base_dir)) include_dir = source.attr('includedir') if include_dir headers['X-PlantUML-IncludeDir'] = Platform.native_path(File.(include_dir, base_dir)) end end |
#add_size_limit_header(headers, limit) ⇒ Object
75 76 77 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 75 def add_size_limit_header(headers, limit) headers['X-PlantUML-SizeLimit'] = limit if limit end |
#add_theme_header(headers, theme) ⇒ Object
71 72 73 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 71 def add_theme_header(headers, theme) headers['X-PlantUML-Theme'] = theme if theme end |
#collect_options(source) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 38 def (source) = { :size_limit => source.attr('size-limit', '4096'), } [:smetana] = true if source.opt('smetana') theme = source.attr('theme', nil) [:theme] = theme if theme end |
#convert(source, format, options) ⇒ Object
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 79 def convert(source, format, ) unless PLANTUML_JARS raise "Could not load PlantUML. Either require 'asciidoctor-diagram-plantuml' or specify the location of the PlantUML JAR(s) using the 'DIAGRAM_PLANTUML_CLASSPATH' environment variable." end Java.load code = source.code case format when :png mime_type = 'image/png' when :svg mime_type = 'image/svg+xml' when :txt, :utxt mime_type = 'text/plain;charset=utf-8' when :atxt mime_type = 'text/plain' else raise "Unsupported format: #{format}" end headers = { 'Accept' => mime_type } unless should_preprocess(source) add_common_headers(headers, source) end add_theme_header(headers, [:theme]) add_size_limit_header(headers, [:size_limit]) if [:smetana] headers['X-Graphviz'] = 'smetana' else dot = source.find_command('dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false) if dot headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot) end end response = Java.send_request( :url => '/plantuml', :body => code, :headers => headers ) unless response[:code] == 200 raise Java.create_error("PlantUML image generation failed", response) end response[:body] end |
#should_preprocess(source) ⇒ Object
51 52 53 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 51 def should_preprocess(source) source.attr('preprocess', 'true') == 'true' end |
#supported_formats ⇒ Object
34 35 36 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 34 def supported_formats [:png, :svg, :txt, :atxt, :utxt] end |
#wrap_source(source) ⇒ Object
30 31 32 |
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 30 def wrap_source(source) PlantUMLPreprocessedSource.new(source, self) end |