Module: Asciidoctor::Ptc::Processor

Included in:
BlockMacroProcessor, BlockProcessor
Defined in:
lib/asciidoctor/ptc/extension.rb

Overview

Shared behaviour for the block and block-macro processors: read options from attributes, drive the Renderer, and emit an image (or, on failure, a visible error block).

Instance Method Summary collapse

Instance Method Details

#render_ptc(parent, source, attrs, target_hint) ⇒ Object

Turn .ptc source into an image block placed in parent.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asciidoctor/ptc/extension.rb', line 15

def render_ptc(parent, source, attrs, target_hint)
  doc = parent.document

  begin
    # Constructing the Renderer already validates every option
    # (format, theme, size, orientation, the all-views/format
    # combination, ...), so an invalid attribute must be rescued here
    # too, not just a failure from #render itself.
    renderer = build_renderer(doc, attrs)
    filename = renderer.render(source, resolve_basename(attrs, target_hint))
  rescue Renderer::Error => e
    return error_block(parent, attrs, e.message)
  end

  create_ptc_image(parent, attrs, filename, renderer, doc)
end