Module: Asciidoctor::Diagram::Erd

Includes:
CliGenerator, Which
Included in:
ErdBlockMacroProcessor, ErdBlockProcessor
Defined in:
lib/asciidoctor-diagram/erd/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



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

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

Instance Method Details

#erd(parent, source, format) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/asciidoctor-diagram/erd/extension.rb', line 21

def erd(parent, source, format)
  erd_path = which(parent, 'erd')
  dot_path = which(parent, 'dot', :alt_attrs => ['graphvizdot'])

  dot_code = generate_stdin(erd_path, format.to_s, source.to_s) do |tool_path, output_path|
    [tool_path, '-o', Platform.native_path(output_path), '-f', 'dot']
  end

  generate_stdin(dot_path, format.to_s, dot_code) do |tool_path, output_path|
    [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
  end
end