Class: AsciidoctorExtensions::KrokiClient
- Inherits:
-
Object
- Object
- AsciidoctorExtensions::KrokiClient
- Includes:
- Asciidoctor::Logging
- Defined in:
- lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
Overview
Kroki client
Constant Summary collapse
- SUPPORTED_HTTP_METHODS =
%w[get post adaptive].freeze
Instance Attribute Summary collapse
-
#max_uri_length ⇒ Object
readonly
Returns the value of attribute max_uri_length.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#server_url ⇒ Object
readonly
Returns the value of attribute server_url.
Instance Method Summary collapse
- #get_image(kroki_diagram, encoding) ⇒ Object
-
#initialize(opts, logger = ::Asciidoctor::LoggerManager.logger) ⇒ KrokiClient
constructor
A new instance of KrokiClient.
- #text_content(kroki_diagram) ⇒ Object
Constructor Details
#initialize(opts, logger = ::Asciidoctor::LoggerManager.logger) ⇒ KrokiClient
Returns a new instance of KrokiClient.
410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 410 def initialize(opts, logger = ::Asciidoctor::LoggerManager.logger) @server_url = opts[:server_url] @max_uri_length = opts.fetch(:max_uri_length, 4000) @http_client = opts[:http_client] method = opts.fetch(:http_method, 'adaptive').downcase if SUPPORTED_HTTP_METHODS.include?(method) @method = method else logger.warn "Invalid value '#{method}' for kroki-http-method attribute. The value must be either: " \ "'get', 'post' or 'adaptive'. Proceeding using: 'adaptive'.", source_location: opts[:source_location] @method = 'adaptive' end end |
Instance Attribute Details
#max_uri_length ⇒ Object (readonly)
Returns the value of attribute max_uri_length.
406 407 408 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 406 def max_uri_length @max_uri_length end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
406 407 408 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 406 def method @method end |
#server_url ⇒ Object (readonly)
Returns the value of attribute server_url.
406 407 408 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 406 def server_url @server_url end |
Instance Method Details
#get_image(kroki_diagram, encoding) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 429 def get_image(kroki_diagram, encoding) type = kroki_diagram.type format = kroki_diagram.format text = kroki_diagram.text opts = kroki_diagram.opts if @method == 'adaptive' || @method == 'get' uri = kroki_diagram.get_diagram_uri(server_url) if uri.length > @max_uri_length # The request URI is longer than the max URI length. if @method == 'get' # The request might be rejected by the server with a 414 Request-URI Too Large. # Consider using the attribute kroki-http-method with the value 'adaptive'. @http_client.get(uri, opts, encoding) else @http_client.post("#{@server_url}/#{type}/#{format}", text, opts, encoding) end else @http_client.get(uri, opts, encoding) end else @http_client.post("#{@server_url}/#{type}/#{format}", text, opts, encoding) end end |
#text_content(kroki_diagram) ⇒ Object
425 426 427 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 425 def text_content(kroki_diagram) get_image(kroki_diagram, 'utf-8') end |