Class: Asciidoctor::Foodogsquared::Extensions::FlathubInlineMacro

Inherits:
Extensions::InlineMacroProcessor
  • Object
show all
Defined in:
lib/asciidoctor/foodogsquared/extensions/flathub-inline-macro.rb

Instance Method Summary collapse

Instance Method Details

#process(parent, target, attrs) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/asciidoctor/foodogsquared/extensions/flathub-inline-macro.rb', line 13

def process(parent, target, attrs)
  doc = parent.document

  # FlatHub API seems to have no documentation aside from the source code.
  # You can easily infer the API with its source code at
  # https://github.com/flathub/website.
  app_id = target
   = %(https://flathub.org/api/v2/appstream/#{app_id})

  headers = {
    'Accept' => 'application/json',
    'User-Agent' => ::Asciidoctor::Foodogsquared::USER_AGENT
  }

   = OpenURI.open_uri(, headers) { |f| JSON.parse(f.read) }
  attrs['caption'] ||= ['name']

  url = %(https://flathub.org/apps/#{app_id})
  doc.register :links, url
  create_anchor parent, attrs['caption'], type: :link, target: url
end