Skip to content

Commit

Permalink
#163 Clean up Travis debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed Feb 24, 2018
1 parent a1aea68 commit 0e0efac
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 48 deletions.
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/blockdiag/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ def blockdiag(tool, parent, source, format)

font_path = source.attr('fontpath', nil, inherit_prefix)

result = generate_stdin(which(parent, cmd_name, :alt_cmds => [alt_cmd_name]), format.to_s, source.to_s) do |tool_path, output_path|
generate_stdin(which(parent, cmd_name, :alt_cmds => [alt_cmd_name]), format.to_s, source.to_s) do |tool_path, output_path|
args = [tool_path, '-a', '-o', Platform.native_path(output_path), "-T#{format.to_s}"]
args << "-f#{Platform.native_path(font_path)}" if font_path
args << '-'
args
end

result[:data]
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/erd/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ def erd(parent, source, format)
[tool_path, '-o', Platform.native_path(output_path), '-f', 'dot']
end

result = generate_stdin(dot_path, format.to_s, dot_code[:data]) do |tool_path, output_path|
generate_stdin(dot_path, format.to_s, dot_code) do |tool_path, output_path|
[tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
end

result[:data]
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/graphviz/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ def self.included(mod)
def graphviz(parent, source, format)
inherit_prefix = name

result = generate_stdin(which(parent, 'dot', :alt_attrs => ['graphvizdot']), format.to_s, source.to_s) do |tool_path, output_path|
generate_stdin(which(parent, 'dot', :alt_attrs => ['graphvizdot']), format.to_s, source.to_s) do |tool_path, output_path|
args = [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]

layout = source.attr('layout', nil, inherit_prefix)
args << "-K#{layout}" if layout

args
end

result[:data]
end
end

Expand Down
14 changes: 2 additions & 12 deletions lib/asciidoctor-diagram/mermaid/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,11 @@ def mermaid(parent_block, source, format)
if config
options[:config] = parent_block.normalize_system_path(config, source.base_dir)
end
result = run_mmdc(mmdc, source, format, options)
run_mmdc(mmdc, source, format, options)
else
mermaid = which(parent_block, 'mermaid')
result = run_mermaid(mermaid, parent_block, source, format, options)
run_mermaid(mermaid, parent_block, source, format, options)
end

if format == :png
begin
PNG.get_image_size(result[:data])
rescue
raise "Invalid PNG data:\nstatus: #{result[:status]}\nstdout: #{result[:out]}\nstderr: #{result[:err]}\ndata: #{result[:data]}"
end
end

result[:data]
end

private
Expand Down
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/msc/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ def mscgen(parent, source, format)
inherit_prefix = name
font = source.attr('font', nil, inherit_prefix)

result = generate_stdin(which(parent, 'mscgen'), format.to_s, source.to_s) do |tool_path, output_path|
generate_stdin(which(parent, 'mscgen'), format.to_s, source.to_s) do |tool_path, output_path|
args = [tool_path, '-o', Platform.native_path(output_path), '-T', format.to_s]
if font
args << '-F' << font
end
args << '-'
args
end

result[:data]
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/shaape/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ def self.included(mod)
end

def shaape(parent, source, format)
result = generate_stdin(which(parent, 'shaape'), format.to_s, source.to_s) do |tool_path, output_path|
generate_stdin(which(parent, 'shaape'), format.to_s, source.to_s) do |tool_path, output_path|
[tool_path, '-o', Platform.native_path(output_path), '-t', format.to_s, '-']
end

result[:data]
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/svgbob/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ def self.included(mod)
end

def svgbob(parent, source, format)
result = generate_stdin(which(parent, 'svgbob'), format.to_s, source.to_s) do |tool_path, output_path|
generate_stdin(which(parent, 'svgbob'), format.to_s, source.to_s) do |tool_path, output_path|
[tool_path, '-o', Platform.native_path(output_path)]
end

result[:data]
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/syntrax/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.included(mod)
def syntrax(parent, source, format)
inherit_prefix = name

result = generate_file(which(parent, 'syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path|
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)
Expand All @@ -45,8 +45,6 @@ def syntrax(parent, source, format)

args
end

result[:data]
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/asciidoctor-diagram/umlet/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ def self.included(mod)
end

def umlet(parent, source, format)
result = generate_file(which(parent, 'umlet'), 'uxf', format.to_s, source.to_s) do |tool_path, input_path, output_path|
generate_file(which(parent, 'umlet'), 'uxf', format.to_s, source.to_s) do |tool_path, input_path, output_path|
[tool_path, '-action=convert', "-format=#{format.to_s}", "-filename=#{Platform.native_path(input_path)}", "-output=#{Platform.native_path(output_path)}"]
end

result[:data]
end
end

Expand Down
25 changes: 17 additions & 8 deletions lib/asciidoctor-diagram/util/cli_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def generate_stdin(tool, format, code)

opts = yield tool, target_file.path

generate(opts, target_file, :stdin_data => code)
generate(opts, target_file.path, :stdin_data => code)
ensure
target_file.unlink
end
Expand All @@ -33,7 +33,7 @@ def generate_file(tool, input_ext, output_ext, code)

opts = yield tool, source_file.path, target_file.path

generate(opts, target_file)
generate(opts, target_file.path)
ensure
target_file.unlink
end
Expand All @@ -42,6 +42,7 @@ def generate_file(tool, input_ext, output_ext, code)
end
end

private
def generate(opts, target_file, open3_opts = {})
case opts
when Array
Expand All @@ -56,17 +57,25 @@ def generate(opts, target_file, open3_opts = {})

result = ::Asciidoctor::Diagram::Cli.run(*args, open3_opts)

unless File.exist?(out_file || target_file.path)
data = read_result(target_file, out_file)

if data.empty?
raise "#{args[0]} failed: #{result[:out].empty? ? result[:err] : result[:out]}"
end

if out_file
File.rename(out_file, target_file.path)
end
data
end

result[:data] = File.binread(target_file.path)
def read_result(target_file, out_file = nil)
if File.exist?(out_file || target_file)
if out_file
File.rename(out_file, target_file)
end

result
File.binread(target_file)
else
''
end
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/asciidoctor-diagram/wavedrom/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def wavedrom(parent, source, format)
phantomjs = which(parent, 'phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false)

if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs
result = generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
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
Expand All @@ -36,12 +36,10 @@ def wavedrom(parent, source, format)
wavedrom = which(parent, 'WaveDromEditor')
end

result = generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
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

result[:data]
end
end

Expand Down

0 comments on commit 0e0efac

Please sign in to comment.