Class: Asciidoctor::BeautifyUri::UriInlineMacro

Inherits:
Extensions::InlineMacroProcessor
  • Object
show all
Defined in:
lib/asciidoctor/beautify_uri/inline_macro.rb

Overview

uri:provider:path — see DESIGN-asciidoctor-beautify-uri.adoc, "Inline Macro Syntax". Provider lookup and resolution are identical to UriBlockMacro (extensions.rb); only the rendered shape differs — a single run of flowing text (InlineRenderer) instead of a whole bordered card (CardRenderer/PdfCard).

Instance Method Summary collapse

Instance Method Details

#process(parent, target, attrs) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/asciidoctor/beautify_uri/inline_macro.rb', line 18

def process(parent, target, attrs)
  doc = parent.document
  provider_key, path = target.split(':', 2)
  provider = ProviderRegistry.find(provider_key)

  unless provider
    Logging.debug(%(unknown provider "#{provider_key}" for target "#{target}"))
    return create_inline(parent, :quoted, Placeholder.inline_text(target))
  end

  data = resolve(provider, path, doc, target)

  unless data
    return create_inline(parent, :quoted, Placeholder.inline_text(target))
  end

  Logging.debug(%(#{provider.key} resolved inline "#{target}" -> #{[data[:title], data[:subtitle]].compact.join(' - ')}))

  want_code = attrs['code'] == 'true' && provider.respond_to?(:code_url)
  content =
    if doc.attr('backend') == 'pdf'
      code_path = want_code && code_tempfile_path(provider, path, doc)
      InlineRenderer.pdf(provider, data, code_path: code_path)
    else
      code_url = want_code && provider.code_url(path)
      InlineRenderer.html(provider, data, code_url: code_url)
    end
  create_inline(parent, :quoted, content)
end