Class: Asciidoctor::Diagram::MermaidConverter

Inherits:
Object
  • Object
show all
Includes:
CliGenerator, DiagramConverter
Defined in:
lib/asciidoctor-diagram/mermaid/converter.rb

Instance Method Summary collapse

Methods included from CliGenerator

#generate_file, #generate_file_stdout, #generate_stdin, #generate_stdin_file, #generate_stdin_stdout

Methods included from DiagramConverter

#wrap_source

Instance Method Details

#collect_options(source) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/asciidoctor-diagram/mermaid/converter.rb', line 22

def collect_options(source)
  options = {}

  options[:css] = source.attr('css')
  options[:gantt_config] = source.attr(['ganttconfig', 'gantt-config'])
  options[:seq_config] = source.attr(['sequenceconfig', 'sequence-config'])
  options[:width] = source.attr('width')
  options[:height] = source.attr('height')
  options[:scale] = source.attr('scale')
  if options[:scale]
    raise "Mermaid only supports integer scale factors: #{options[:scale]}" unless options[:scale] =~ /^[0-9]+$/
  end
  options[:theme] = source.attr('theme')
  options[:background] = source.attr('background')
  options[:config] = source.attr('config')
  options[:puppeteer_config] = source.attr(['puppeteerconfig', 'puppeteer-config'])

  options
end

#convert(source, format, options) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/asciidoctor-diagram/mermaid/converter.rb', line 42

def convert(source, format, options)
  opts = {}

  css = options[:css]
  if css
    opts[:css] = source.resolve_path(css)
  end

  gantt_config = options[:gantt_config]
  if gantt_config
    opts[:gantt] = source.resolve_path(gantt_config)
  end

  seq_config = options[:seq_config]
  if seq_config
    opts[:sequence] = source.resolve_path(seq_config)
  end

  puppeteer_config = options[:puppeteer_config]
  if puppeteer_config
    opts[:puppeteer] = source.resolve_path(puppeteer_config)
  end

  opts[:width] = options[:width]

  mmdc = nil
  mmdc_exception = nil
  begin
    mmdc = source.find_command('mmdc')
  rescue => e
    mmdc_exception = e
  end

  if mmdc
    opts[:height] = options[:height]
    opts[:scale] = options[:scale]
    opts[:theme] = options[:theme]
    opts[:background] = options[:background]
    config = options[:config]
    if config
      opts[:config] = source.resolve_path(config)
    end
    run_mmdc(mmdc, source, format, opts)
  else
    begin
      mermaid = source.find_command('mermaid')
      run_mermaid(mermaid, source, format, opts)
    rescue
      if mmdc_exception
        raise mmdc_exception
      else
        raise
      end
    end
  end
end

#native_scaling?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/asciidoctor-diagram/mermaid/converter.rb', line 18

def native_scaling?
  true
end

#supported_formatsObject



14
15
16
# File 'lib/asciidoctor-diagram/mermaid/converter.rb', line 14

def supported_formats
  [:png, :svg]
end