Module: Asciidoctor::Diagram::Mermaid

Includes:
Which
Included in:
MermaidBlockMacroProcessor, MermaidBlockProcessor
Defined in:
lib/asciidoctor-diagram/mermaid/extension.rb

Class Method Summary collapse

Methods included from Which

which, #which

Class Method Details

.included(mod) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/asciidoctor-diagram/mermaid/extension.rb', line 11

def self.included(mod)
  [:png, :svg].each do |f|
    mod.register_format(f, :image) do |c, p|
      mermaid = which(p, 'mermaid')

      seq_config = c.attributes['sequenceConfig'] || p.attr('sequenceConfig')
      if seq_config
        seq_config = p.normalize_system_path(seq_config, p.document.base_dir)
      end

      width = c.attributes['width']

      CliGenerator.generate_file(mermaid, f.to_s, c.to_s) do |tool_path, input_path, output_path|
        output_dir = File.dirname(output_path)
        output_file = File.expand_path(File.basename(input_path) + ".#{f.to_s}", output_dir)

        args = [tool_path, "--#{f.to_s}", '-o', output_dir]

        if seq_config
          args << '--sequenceConfig' << seq_config
        end

        if width
          args << '--width' << width
        end

        args << input_path

        {
            :args => args,
            :out_file => output_file
        }
      end
    end
  end
end