Module: Asciidoctor::Diagram::Extensions::FormatRegistry

Defined in:
lib/asciidoctor-diagram/extensions.rb

Overview

Provides the means for diagram processors to register supported output formats and image generation routines

Instance Method Summary collapse

Instance Method Details

#default_formatSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the default format

Returns:

  • (Symbol)

    the default format



58
59
60
# File 'lib/asciidoctor-diagram/extensions.rb', line 58

def default_format
  @default_format
end

#formatsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the registered formats

Returns:

  • (Hash)


50
51
52
# File 'lib/asciidoctor-diagram/extensions.rb', line 50

def formats
  @formats ||= {}
end

#register_format(format, type) {|parent, source| ... } ⇒ Object

Registers a supported format. The first registered format becomes the default format for the block processor.

Examples

register_format(:png, :image ) do |parent_block, source|
  File.read(source.to_s)
end

Parameters:

  • format (Symbol)

    the format name

  • type (Symbol)

    a symbol indicating the type of block that should be generated; either :image or :literal

Yield Parameters:

  • parent (Asciidoctor::AbstractNode)

    the asciidoc block that is being processed

  • source (DiagramSource)

    the source object

Yield Returns:

  • (String)

    the generated diagram



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/asciidoctor-diagram/extensions.rb', line 33

def register_format(format, type, &block)
  raise "Unsupported output type: #{type}" unless type == :image || type == :literal

  unless defined?(@default_format)
    @default_format = format
  end

  formats[format] = {
      :type => type,
      :generator => block
  }
end