Class: Pandocomatic::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/pandocomatic/processor.rb

Overview

Generic class for processors used to preprocess, postproces, setup, and cleanup with external scripts or programs during the conversion process.

For preprocessors and postprocessors it is assumed that the input is the contents of the file to convert and the output the processed input. In the end, the output will be put through pandoc.

Direct Known Subclasses

FileInfoPreprocessor, MetadataPreprocessor

Class Method Summary collapse

Class Method Details

.run(script, input) ⇒ String

Run script on input and return captured output

Parameters:

  • script (String)

    path to script to run

  • input (String)

    input to process in the script

Returns:

  • (String)

    output of script.



38
39
40
41
42
43
44
45
46
47
# File 'lib/pandocomatic/processor.rb', line 38

def self.run(script, input)
  output, error, status = Open3.capture3(script, stdin_data: input)
  warn error unless error.empty?

  if status.exitstatus.positive?
    raise ProcessorError.new(:error_processing_script, StandardError.new(error), [script, input])
  end

  output
end