module Asciidoctor::Diagram::Extensions::FormatRegistry
Provides the means for diagram processors to register supported output formats and image generation routines
Public Instance Methods
default_format()
click to toggle source
Returns the default format
@return [Symbol] the default format @api private
# File lib/asciidoctor-diagram/extensions.rb, line 64 def default_format @default_format end
formats()
click to toggle source
Returns the registered formats
@return [Hash] @api private
# File lib/asciidoctor-diagram/extensions.rb, line 56 def formats @formats ||= {} end
register_format(format, type, &block)
click to toggle source
Registers a supported format. The first registered format becomes the default format for the block processor.
@param [Symbol] format the format name @param [Symbol] type a symbol indicating the type of block that should be generated; either :image or :literal @yieldparam parent [Asciidoctor::AbstractNode] the asciidoc block that is being processed @yieldparam source [DiagramSource] the source object @yieldreturn [String] the generated diagram
Examples
register_format(:png, :image ) do |parent_block, source| File.read(source.to_s) end
# File lib/asciidoctor-diagram/extensions.rb, line 39 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