Class: Asciidoctor::Diagram::WavedromConverter

Inherits:
Object
  • Object
show all
Includes:
CliGenerator, DiagramConverter
Defined in:
lib/asciidoctor-diagram/wavedrom/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

#collect_options, #native_scaling?, #wrap_source

Instance Method Details

#convert(source, format, options) ⇒ Object



16
17
18
19
20
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
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/asciidoctor-diagram/wavedrom/converter.rb', line 16

def convert(source, format, options)
  wavedrom = source.find_command('wavedrom-cli', :attrs => ['wavedrom'], :raise_on_error => false)

  unless wavedrom
    wavedrom = source.find_command('wavedrom', :raise_on_error => false)
  end

  unless wavedrom
    if ::Asciidoctor::Diagram::Platform.os == :macosx
      wavedrom = source.find_command('WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'], :path => ['/Applications'], :raise_on_error => false)
      if wavedrom
        wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
      end
    else
      wavedrom = source.find_command('WaveDromEditor', :raise_on_error => false)
    end
  end

  unless wavedrom
    source.find_command('wavedrom-cli', :attrs => ['wavedrom'])
  end

  if wavedrom.include?('-cli')
    generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
      {
        :args => [Platform.native_path(tool_path), '--input', Platform.native_path(input_path), "--#{format.to_s}", Platform.native_path(output_path)],
        :chdir => source.base_dir
      }
    end
  elsif wavedrom.include?('WaveDromEditor')
    generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
      {
        :args => [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)],
        :chdir => source.base_dir
      }
    end
  else
    phantomjs = source.find_command('phantomjs', :alt_attrs => ['phantomjs_2'])
    generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
      {
        :args => [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)],
        :chdir => source.base_dir
      }
    end
  end
end

#supported_formatsObject



12
13
14
# File 'lib/asciidoctor-diagram/wavedrom/converter.rb', line 12

def supported_formats
  [:png, :svg]
end