From 43f9efbbaf3ad5557b1bf39a8f972f1a91205949 Mon Sep 17 00:00:00 2001 From: kiuKisas Date: Tue, 17 May 2016 12:34:28 +0200 Subject: [PATCH 1/3] fix output when converting binary --- lib/pandoc-ruby.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/pandoc-ruby.rb b/lib/pandoc-ruby.rb index c7c47f5..7237e8d 100644 --- a/lib/pandoc-ruby.rb +++ b/lib/pandoc-ruby.rb @@ -170,18 +170,27 @@ class << self private # Execute the pandoc command for binary writers. A temp file is created - # and written to, then read back into the program as a string, then the - # temp file is closed and unlinked. + # if there is no output and written to, then read back into the program + # as a string, then the temp file is closed and unlinked. def convert_binary - tmp_file = Tempfile.new('pandoc-conversion') - begin + unless (self.option_string.include?('-o') && self.option_string.include?('--output')) + tmp_file = Tempfile.new('pandoc-conversion') self.options += [{ :output => tmp_file.path }] self.option_string = "#{self.option_string} --output #{tmp_file.path}" + end + begin execute_pandoc + if tmp_file == nil + option_tab = self.option_string.split(' ') + index = option_tab.rindex {|x| x == '--output' || x == '-o'} + return File.read(option_tab[index + 1]) + end return IO.binread(tmp_file) ensure - tmp_file.close - tmp_file.unlink + unless tmp_file == nil + tmp_file.close + tmp_file.unlink + end end end From d39e5d088b98d3bce5240300f48ce5826d6ee02b Mon Sep 17 00:00:00 2001 From: kiuKisas Date: Thu, 19 May 2016 16:13:10 +0200 Subject: [PATCH 2/3] delete useless nil comparaison --- lib/pandoc-ruby.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pandoc-ruby.rb b/lib/pandoc-ruby.rb index 7237e8d..66d9c15 100644 --- a/lib/pandoc-ruby.rb +++ b/lib/pandoc-ruby.rb @@ -180,14 +180,14 @@ def convert_binary end begin execute_pandoc - if tmp_file == nil + if tmp_file option_tab = self.option_string.split(' ') index = option_tab.rindex {|x| x == '--output' || x == '-o'} return File.read(option_tab[index + 1]) end return IO.binread(tmp_file) ensure - unless tmp_file == nil + unless tmp_file tmp_file.close tmp_file.unlink end From 108c5ca1a4eaa429d769a94a14083d56c66f9a52 Mon Sep 17 00:00:00 2001 From: kiuKisas Date: Thu, 19 May 2016 16:34:02 +0200 Subject: [PATCH 3/3] oops --- lib/pandoc-ruby.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pandoc-ruby.rb b/lib/pandoc-ruby.rb index 66d9c15..2765ce4 100644 --- a/lib/pandoc-ruby.rb +++ b/lib/pandoc-ruby.rb @@ -180,14 +180,14 @@ def convert_binary end begin execute_pandoc - if tmp_file + if tmp_file.nil? option_tab = self.option_string.split(' ') index = option_tab.rindex {|x| x == '--output' || x == '-o'} return File.read(option_tab[index + 1]) end return IO.binread(tmp_file) ensure - unless tmp_file + unless tmp_file.nil? tmp_file.close tmp_file.unlink end