Module: Asciidoctor::Diagram::Syntrax

Includes:
CliGenerator, Which
Included in:
SyntraxBlockMacroProcessor, SyntraxBlockProcessor
Defined in:
lib/asciidoctor-diagram/syntrax/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



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

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

Instance Method Details

#syntrax(parent, source, format) ⇒ Object



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
47
48
# File 'lib/asciidoctor-diagram/syntrax/extension.rb', line 21

def syntrax(parent, source, format)
  inherit_prefix = name

  generate_file(which(parent, 'syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path|
    args = [tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]

    title = source.attr('heading', nil, inherit_prefix)
    if title
      args << '--title' << title
    end

    scale = source.attr('scale', nil, inherit_prefix)
    if scale
      args << '--scale' << scale
    end

    transparent = source.attr('transparent', nil, inherit_prefix)
    if transparent == 'true'
      args << '--transparent'
    end
    style = source.attr('style', nil, inherit_prefix)
    if style
      args << '--style' << style
    end

    args
  end
end