Class: Pandocomatic::FileInfoPreprocessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/pandocomatic/processors/fileinfo_preprocessor.rb

Overview

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

Class Method Summary collapse

Class Method Details

.run(input, path, src_path, options) ⇒ Object

Run this FileInfoPreprocessor

Parameters:

  • input (String)

    the contents of the document being preprocessed

  • path (String)

    the path to the input document

  • options (Hash)

    pandoc options collected by pandocomatic to run on this file



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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