Class: Asciidoctor::Diagram::HttpConverter
- Inherits:
-
Object
- Object
- Asciidoctor::Diagram::HttpConverter
show all
- Includes:
- DiagramConverter
- Defined in:
- lib/asciidoctor-diagram/http/converter.rb
Constant Summary
collapse
- DEFAULT_MAX_GET_SIZE =
1024
Instance Method Summary
collapse
#native_scaling?, #wrap_source
Constructor Details
#initialize(base_uri, type, converter) ⇒ HttpConverter
Returns a new instance of HttpConverter.
17
18
19
20
21
|
# File 'lib/asciidoctor-diagram/http/converter.rb', line 17
def initialize(base_uri, type, converter)
@base_uri = base_uri
@type = type
@converter = converter
end
|
Instance Method Details
#collect_options(source) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/asciidoctor-diagram/http/converter.rb', line 27
def collect_options(source)
options = {}
options[:max_get_size] = source.global_attr('max-get-size', DEFAULT_MAX_GET_SIZE).to_i
options
end
|
#convert(source, format, options) ⇒ Object
35
36
37
38
39
40
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/asciidoctor-diagram/http/converter.rb', line 35
def convert(source, format, options)
code = source.code
uri = URI(@base_uri)
case @type
when :plantuml
deflate = Zlib::Deflate.new(Zlib::BEST_COMPRESSION,
-Zlib::MAX_WBITS,
Zlib::MAX_MEM_LEVEL,
Zlib::DEFAULT_STRATEGY)
compressed = deflate.deflate(code, Zlib::FINISH)
deflate.close
data = Base64.urlsafe_encode(compressed)
data.tr!(
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
)
path = uri.path.dup
path << '/' unless path.end_with? '/'
path << format.to_s
when :kroki_io
compressed = Zlib.deflate(code, Zlib::BEST_COMPRESSION)
data = Base64.urlsafe_encode(compressed)
path = uri.path.dup
path << '/' unless path.end_with? '/'
path << source.diagram_type.to_s
path << '/' << format.to_s
else
raise "Unsupported server type: " + @type
end
get_path = path.dup << '/' << data
if get_path.length > options[:max_get_size]
uri.path = path
get_uri(uri, code, 'text/plain; charset=utf-8')
else
uri.path = get_path
get_uri(uri)
end
end
|
23
24
25
|
# File 'lib/asciidoctor-diagram/http/converter.rb', line 23
def supported_formats
@converter.supported_formats
end
|