Module: Asciidoctor::Diagram::Wavedrom

Includes:
CliGenerator, Which
Included in:
WavedromBlockMacroProcessor, WavedromBlockProcessor
Defined in:
lib/asciidoctor-diagram/wavedrom/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/wavedrom/extension.rb', line 13

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

Instance Method Details

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

def wavedrom(parent, source, format)
  wavedrom_cli = which(parent, 'wavedrom', :raise_on_error => false)
  phantomjs = which(parent, 'phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false)

  if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs
    generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
      [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)]
    end
  else
    if ::Asciidoctor::Diagram::Platform.os == :macosx
      wavedrom = which(parent, 'WaveDromEditor.app', :alt_attrs => ['wavedrom'], :path => ['/Applications'])
      if wavedrom
        wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
      end
    else
      wavedrom = which(parent, 'WaveDromEditor', :alt_attrs => ['wavedrom'])
    end

    generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
      [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)]
    end
  end
end