Module: Asciidoctor::Diagram::Extensions::DiagramProcessor
- Included in:
- DiagramBlockMacroProcessor, DiagramBlockProcessor
- Defined in:
- lib/asciidoctor-diagram/extensions.rb
Overview
Mixin that provides the basic machinery for image generation. When this module is included it will include the FormatRegistry into the singleton class of the target class.
Constant Summary collapse
- IMAGE_PARAMS =
{ :svg => { :encoding => Encoding::UTF_8, :decoder => SVG }, :gif => { :encoding => Encoding::ASCII_8BIT, :decoder => GIF }, :png => { :encoding => Encoding::ASCII_8BIT, :decoder => PNG }, :pdf => { :encoding => Encoding::ASCII_8BIT, :decoder => PDF } }
Class Method Summary collapse
Instance Method Summary collapse
-
#process(parent, reader_or_target, attributes) ⇒ Asciidoctor::AbstractBlock
Processes the diagram block or block macro by converting it into an image or literal block.
Class Method Details
.included(mod) ⇒ Object
85 86 87 88 89 |
# File 'lib/asciidoctor-diagram/extensions.rb', line 85 def self.included(mod) class << mod include FormatRegistry end end |
Instance Method Details
#process(parent, reader_or_target, attributes) ⇒ Asciidoctor::AbstractBlock
Processes the diagram block or block macro by converting it into an image or literal block.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/asciidoctor-diagram/extensions.rb', line 98 def process(parent, reader_or_target, attributes) source = create_source(parent, reader_or_target, attributes.dup) format = source.attributes.delete('format') || self.class.default_format format = format.to_sym if format.respond_to?(:to_sym) raise "Format undefined" unless format generator_info = self.class.formats[format] raise "#{self.class.name} does not support output format #{format}" unless generator_info begin case generator_info[:type] when :literal create_literal_block(parent, source, generator_info) else create_image_block(parent, source, format, generator_info) end rescue => e case parent.attr('diagram-on-error') || 'log' when 'abort' raise e else text = "Failed to generate image: #{e.message}" warn_msg = text.dup if $VERBOSE warn_msg << "\n" << e.backtrace.join("\n") end warn %(asciidoctor-diagram: ERROR: #{warn_msg}) text << "\n" text << source.code Asciidoctor::Block.new parent, :listing, :source => text, :attributes => attributes end end end |