Skip to content

Commit

Permalink
#453 Improve error message when WaveDrom cannot be located
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed Jan 22, 2024
1 parent 36d3a09 commit eae8875
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

== 2.2.15

Enhacements::

* Issue #453: Improve error message when WaveDrom cannot be located

Bugfixes::

* Issue #428: Improve support for reading UTF-16 encoded source files
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/diagram_types/wavedrom.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ include::partial$uris.adoc[]
[cols=">,<,<",options="header"]
|===
|Name |Default value |Description
|wavedrom |wavedrom |The path to the `wavedrom` executable
|wavedrom |wavedrom |The path to the `wavedrom-cli` or `wavedrom` executable
|===
67 changes: 36 additions & 31 deletions lib/asciidoctor-diagram/wavedrom/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,53 @@ class WavedromConverter
include DiagramConverter
include CliGenerator


def supported_formats
[:png, :svg]
end


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|
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.end_with?('-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
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|
{
: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
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|
{
:args => [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)],
:chdir => source.base_dir
}
end
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
Expand Down

0 comments on commit eae8875

Please sign in to comment.