Class: AsciidoctorExtensions::KrokiBlockMacroProcessor
- Inherits:
-
Asciidoctor::Extensions::BlockMacroProcessor
- Object
- Asciidoctor::Extensions::BlockMacroProcessor
- AsciidoctorExtensions::KrokiBlockMacroProcessor
- Includes:
- Asciidoctor::Logging
- Defined in:
- lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
Overview
A block macro extension that converts a diagram into an image.
Instance Method Summary collapse
-
#initialize(name = nil, config = {}) ⇒ KrokiBlockMacroProcessor
constructor
A new instance of KrokiBlockMacroProcessor.
- #process(parent, target, attrs) ⇒ Object
Constructor Details
#initialize(name = nil, config = {}) ⇒ KrokiBlockMacroProcessor
Returns a new instance of KrokiBlockMacroProcessor.
51 52 53 54 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 51 def initialize(name = nil, config = {}) @logger = (config || {}).delete(:logger) { ::Asciidoctor::LoggerManager.logger } super(name, config) end |
Instance Method Details
#process(parent, target, attrs) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 56 def process(parent, target, attrs) diagram_type = @name target = parent.apply_subs(target, [:attributes]) unless read_allowed?(target) link = create_inline(parent, :anchor, target, type: :link, target: target) return create_block(parent, :paragraph, link.convert, {}, content_model: :raw) end unless (path = resolve_target_path(target)) logger.error "#{diagram_type} block macro not found: #{target}.", source_location: parent.document.reader.cursor_at_mark return create_block(parent, 'paragraph', (diagram_type, target), {}) end begin diagram_text = read(path) rescue => e # rubocop:disable Style/RescueStandardError logger.error "Failed to read #{diagram_type} file: #{path}. #{e}.", source_location: parent.document.reader.cursor_at_mark return create_block(parent, 'paragraph', (diagram_type, path), {}) end KrokiProcessor.process(self, parent, attrs, diagram_type, diagram_text, @logger) end |