Sha256: 9ff5dddb19b41243817d5b1686ae7063d766f4a06c8af159c24c4120f97dad9f
Contents?: true
Size: 984 Bytes
Versions: 2
Compression:
Stored size: 984 Bytes
Contents
require "open3" require "pathname" require "shellwords" module Metanorma module Output class Pdf < Base def convert(url_path, output_path) file_url = url_path file_url = "file://#{url_path}" if Pathname.new(file_url).absolute? file_url = "file://#{Dir.pwd}/#{url_path}" unless %r{^file://} =~ file_url 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 def shellescape(str) if Gem.win_platform?() # https://bugs.ruby-lang.org/issues/16741 str.match(" ") ? "\"#{str}\"" : str else Shellwords.shellescape(str) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
metanorma-1.0.2 | lib/metanorma/output/pdf.rb |
metanorma-1.0.1 | lib/metanorma/output/pdf.rb |