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



54
55
56
# File 'lib/asciidoctor-diagram/extensions.rb', line 54

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)


46
47
48
# File 'lib/asciidoctor-diagram/extensions.rb', line 46

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, 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



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/asciidoctor-diagram/extensions.rb', line 29

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

   unless @default_format
     @default_format = format
   end

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