Skip to content

Commit

Permalink
log via Asciidoctor logger to provide the user with a file name and l…
Browse files Browse the repository at this point in the history
…ine number in the log, plus redirection of log content in IDEs
  • Loading branch information
ahus1 committed Jan 23, 2021
1 parent 1372acb commit 1134215
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ruby/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Metrics/PerceivedComplexity:
Max: 10

Metrics/AbcSize:
Max: 30
Max: 31
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def process(processor, parent, attrs, diagram_type, diagram_text)
attrs['role'] = get_role(format, role)
attrs['format'] = format
kroki_diagram = KrokiDiagram.new(diagram_type, format, diagram_text)
kroki_client = KrokiClient.new(server_url(doc), http_method(doc), KrokiHttpClient)
kroki_client = KrokiClient.new(server_url(doc), http_method(doc), KrokiHttpClient, doc.reader.cursor_at_mark)
if TEXT_FORMATS.include?(format)
text_content = kroki_client.text_content(kroki_diagram)
block = processor.create_block(parent, 'literal', text_content, attrs)
Expand Down Expand Up @@ -257,20 +257,22 @@ def _join_uri_segments(base, *uris)
# Kroki client
#
class KrokiClient
include Asciidoctor::Logging
attr_reader :server_url
attr_reader :method

SUPPORTED_HTTP_METHODS = %w[get post adaptive].freeze

def initialize(server_url, http_method, http_client)
def initialize(server_url, http_method, http_client, location = nil)
@server_url = server_url
@max_uri_length = 4096
@http_client = http_client
method = (http_method || 'adaptive').downcase
if SUPPORTED_HTTP_METHODS.include?(method)
@method = method
else
puts "Invalid value '#{method}' for kroki-http-method attribute. The value must be either: 'get', 'post' or 'adaptive'. Proceeding using: 'adaptive'."
logger.warn message_with_context "Invalid value '#{method}' for kroki-http-method attribute. The value must be either: " \
"'get', 'post' or 'adaptive'. Proceeding using: 'adaptive'.", source_location: location
@method = 'adaptive'
end
end
Expand Down

0 comments on commit 1134215

Please sign in to comment.