Module: Asciidoctor::Diagram::Mermaid

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Which

which, #which

Methods included from CliGenerator

#generate, #generate_file, #generate_stdin

Class Method Details

.included(mod) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/asciidoctor-diagram/mermaid/extension.rb', line 14

def self.included(mod)
  [:png, :svg].each do |f|
    mod.register_format(f, :image) do |parent, source|
      mermaid(parent, source, f)
    end
  end
end

Instance Method Details

#mermaid(parent, source, format) ⇒ Object



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
47
48
49
50
51
52
53
54
55
56
# File 'lib/asciidoctor-diagram/mermaid/extension.rb', line 22

def mermaid(parent, source, format)
  mermaid = which(parent, 'mermaid')
  @is_mermaid_v6 ||= ::Asciidoctor::Diagram::Cli.run(mermaid, '--version').split('.')[0].to_i >= 6
  # Mermaid >= 6.0.0 requires PhantomJS 2.1; older version required 1.9
  phantomjs = which(parent, 'phantomjs', :alt_attrs => [@is_mermaid_v6 ? 'phantomjs_2' : 'phantomjs_19'])

  seq_config = source.attr('sequenceConfig', nil, true)
  if seq_config
    seq_config = parent.normalize_system_path(seq_config, source.base_dir)
  end

  width = source.attr('width')

  generate_file(mermaid, 'mmd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
    output_dir = File.dirname(output_path)
    output_file = File.expand_path(File.basename(input_path) + ".#{format.to_s}", output_dir)

    args = [tool_path, '--phantomPath', Platform.native_path(phantomjs), "--#{format.to_s}", '-o', Platform.native_path(output_dir)]

    if seq_config
      args << '--sequenceConfig' << Platform.native_path(seq_config)
    end

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

    args << Platform.native_path(input_path)

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