Class: PBSimply::Processor::Pandoc

Inherits:
PBSimply
  • Object
show all
Defined in:
lib/pbsimply/docengine/pandoc.rb

Overview

Pandoc processor

Constant Summary

Constants included from ACCS

ACCS::DEFINITIONS, ACCS::INDEX

Constants included from PBSimply::Plugger

PBSimply::Plugger::POST_PROCESSORS

Instance Attribute Summary

Attributes inherited from PBSimply

#indexes

Instance Method Summary collapse

Methods inherited from PBSimply

#delete_missing, #delete_turn_draft, #doc, #generate, load_config, #load_index, #main, #proc_dir, #proc_docs, #treat_cmdline

Methods included from ACCS

#accsmode, #process_accs, #single_accs

Methods included from Frontmatter

#read_frontmatter

Methods included from PBSimply::Plugger

#post_plugins, #pre_plugins

Methods included from PBSimply::Prayer

#autobless, #bless, #bless_cmd, #bless_ruby

Constructor Details

#initialize(config) ⇒ Pandoc

Returns a new instance of Pandoc.



12
13
14
15
16
17
18
19
20
21
# File 'lib/pbsimply/docengine/pandoc.rb', line 12

def initialize(config)
  @pandoc_default_file = {}

  # -d
  @pandoc_default_file = {
    "to" => "html5",
    "standalone" => true
  }
  super
end

Instance Method Details

Invoke pandoc, parse and format and write out.



48
49
50
# File 'lib/pbsimply/docengine/pandoc.rb', line 48

def print_fileproc_msg(filename)
  STDERR.puts "#{filename} is going Pandoc."
end

#process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pbsimply/docengine/pandoc.rb', line 52

def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
  doc = nil

  File.open(@workfile_pandoc_defaultfiles, "w") {|f| YAML.dump(@pandoc_default_file, f)}
  File.open(@workfile_frontmatter, "w") {|f| YAML.dump(frontmatter, f)}

  # Go Pandoc
  pandoc_cmdline = [(@config["pandoc_command"] || "pandoc")]
  pandoc_cmdline += ["-d", @workfile_pandoc_defaultfiles, "--metadata-file", @workfile_frontmatter, "-M", "title:#{frontmatter["title"]}", "-w", "html5"]
  pandoc_cmdline += ["-f", frontmatter["input_format"]] if frontmatter["input_format"]
  pandoc_cmdline += [ procdoc ]
  pp pandoc_cmdline if ENV["DEBUG"] == "yes"
  IO.popen((pandoc_cmdline)) do |io|
    doc = io.read
  end

  # Abort if pandoc returns non-zero status
  if $?.exitstatus != 0
    abort "Pandoc returns exit code #{$?.exitstatus}"
  end

  doc
end

#setup_config(dir) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pbsimply/docengine/pandoc.rb', line 23

def setup_config(dir)
  super
  @pandoc_default_file["template"] = @config["template"]

  if @config["css"]
    if @config["css"].kind_of?(String)
      @pandoc_default_file["css"] = [@config["css"]]
    elsif @config["css"].kind_of?(Array)
      @pandoc_default_file["css"] = @config["css"]
    else
      abort "css in Config should be a String or an Array."
    end
  end

  if @config["toc"]
    @pandoc_default_file["toc"] = true
  end

  if Hash === @config["pandoc_additional_options"]
    @pandoc_default_file.merge! @config["pandoc_additional_options"]
  end

end

#target_file_extensionsObject



76
77
78
# File 'lib/pbsimply/docengine/pandoc.rb', line 76

def target_file_extensions
  [".md", ".rst"]
end