class Pandocomatic::FileInfoPreprocessor

FileInfoPreprocessor collects information about a file to be converted and mixes that information into that file’s metadata. It is a default preprocessor.

Public Class Methods

run(input, path, src_path, options) click to toggle source

Run this FileInfoPreprocessor

@param input [String] the contents of the document being preprocessed @param path [String] the path to the input document @param options [Hash] pandoc options collected by pandocomatic to run on

this file
# File lib/pandocomatic/processors/fileinfo_preprocessor.rb, line 37
def self.run(input, path, src_path, options)
  created_at = File.stat(path).ctime
  modified_at = File.stat(path).mtime

  file_info = "\npandocomatic-fileinfo:\n"
  file_info += "  from: #{options['from']}\n" if options.key? 'from'
  file_info += "  to: #{options['to']}\n" if options.key? 'to'
  file_info += "  template: #{options['template']}\n" if options.key? 'template'
  file_info += "  path: '#{path}'\n"
  file_info += "  src_path: '#{src_path}'\n"
  file_info += "  created: #{created_at.strftime '%Y-%m-%d'}\n"
  file_info += "  modified: #{modified_at.strftime '%Y-%m-%d'}"

  Pandocomatic::LOG.debug '     | FileInfoPreprocessor. Adding file information to metadata:' \
    "#{Pandocomatic::LOG.indent(
      file_info, 37
    )}"

  "#{input}\n\n---#{file_info}\n...\n\n"
end