Class: Metanorma::Output::Pdf
Instance Method Summary collapse
Instance Method Details
#convert(url_path, output_path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/metanorma/output/pdf.rb', line 10 def convert(url_path, output_path) file_url = Utils::file_path(url_path) pdfjs = File.join(File.dirname(__FILE__), "../../../bin/metanorma-pdf.js") node_path = ENV["NODE_PATH"] || `npm root --quiet -g`.strip node_cmd = ["node", pdfjs, file_url, output_path].map { |arg| shellescape(arg) }.join(" ") _, error_str, status = Open3.capture3({ "NODE_PATH" => node_path }, node_cmd) raise error_str unless status.success? end |
#shellescape(str) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/metanorma/output/pdf.rb', line 21 def shellescape(str) if Gem.win_platform?() # https://bugs.ruby-lang.org/issues/16741 str.match(" ") ? "\"#{str}\"" : str else Shellwords.shellescape(str) end end |