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
# 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
  output = input
  output << "\n\n---\n"
  output << "pandocomatic-fileinfo:\n"
  output << "  from: #{options['from']}\n" if options.key? 'from'
  output << "  to: #{options['to']}\n" if options.key? 'to'
  output << "  template: #{options['template']}\n" if options.key? 'template'
  output << "  path: '#{path}'\n"
  output << "  src_path: '#{src_path}'\n"
  output << "  created: #{created_at.strftime '%Y-%m-%d'}\n"
  output << "  modified: #{modified_at.strftime '%Y-%m-%d'}\n"
  output << "...\n\n"
end