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_file, #generate_stdin, #generate_stdin_stdout

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_block, 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
57
58
# File 'lib/asciidoctor-diagram/mermaid/extension.rb', line 22

def mermaid(parent_block, source, format)
  inherit_prefix = name

  options = {}

  css = source.attr('css', nil, inherit_prefix)
  if css
    options[:css] = parent_block.normalize_system_path(css, source.base_dir)
  end

  gantt_config = source.attr('ganttConfig', nil, inherit_prefix) || source.attr('ganttconfig', nil, inherit_prefix)
  if gantt_config
    options[:gantt] = parent_block.normalize_system_path(gantt_config, source.base_dir)
  end

  seq_config = source.attr('sequenceConfig', nil, inherit_prefix) || source.attr('sequenceconfig', nil, inherit_prefix)
  if seq_config
    options[:sequence] = parent_block.normalize_system_path(seq_config, source.base_dir)
  end

  options[:width] = source.attr('width', nil, inherit_prefix)

  mmdc = which(parent_block, 'mmdc', :raise_on_error => false)
  if mmdc
    options[:height] = source.attr('height', nil, inherit_prefix)
    options[:theme] = source.attr('theme', nil, inherit_prefix)
    options[:background] = source.attr('background', nil, inherit_prefix)
    config = source.attr('config', nil, inherit_prefix) || source.attr('config', nil, inherit_prefix)
    if config
      options[:config] = parent_block.normalize_system_path(config, source.base_dir)
    end
    run_mmdc(mmdc, source, format, options)
  else
    mermaid = which(parent_block, 'mermaid')
    run_mermaid(mermaid, parent_block, source, format, options)
  end
end