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



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

def convert(source, format, options)
  wavedrom_cli = source.find_command('wavedrom-cli', :raise_on_error => false)
  if wavedrom_cli
    generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
      [Platform.native_path(tool_path), '--input', Platform.native_path(input_path), "--#{format.to_s}", Platform.native_path(output_path)]
    end
  else
    wavedrom_cli = source.find_command('wavedrom', :raise_on_error => false)
    phantomjs = source.find_command('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 = source.find_command('WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'], :path => ['/Applications'])
        if wavedrom
          wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
        end
      else
        wavedrom = source.find_command('WaveDromEditor')
      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
end

#supported_formatsObject



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

def supported_formats
  [:png, :svg]
end