Class: PBSimply::Processor::Docutils

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

Overview

Docutils processor (rst2html5 command)

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, find_docroot, #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

#outext, #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) ⇒ Docutils

Returns a new instance of Docutils.



7
8
9
10
# File 'lib/pbsimply/docengine/docutils.rb', line 7

def initialize(config)
  @docutils_cli_options = []
  super
end

Instance Method Details

Invoke pandoc, parse and format and write out.



32
33
34
# File 'lib/pbsimply/docengine/docutils.rb', line 32

def print_fileproc_msg(filename)
  $stderr.puts "#{filename} is going Docutils."
end

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pbsimply/docengine/docutils.rb', line 36

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

  # Go Docutils
  cmdline = ["rst2html5"]
  cmdline += @docutils_cli_options
  cmdline += [ procdoc ]
  IO.popen((cmdline)) do |io|
    doc = io.read
  end

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

  doc
end

#setup_config(dir) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pbsimply/docengine/docutils.rb', line 12

def setup_config(dir)
  super
  @docutils_cli_options.push("--template=#{@config["template"]}") if @config["template"]

  if @config["css"]
    if @config["css"].kind_of?(String)
      @docutils_cli_options.push("--stylesheet=#{@config["css"]}")
    elsif @config["css"].kind_of?(Array)
      @docutils_cli_options.push("--stylesheet=#{@config["css"].join(",")}")
    else
      abort "css in Config should be a String or an Array."
    end
  end

  if Array === @config["docutils_options"]
    @docutils_cli_options.concat! @config["docutils_options"]
  end
end

#target_file_extensionsObject



55
56
57
# File 'lib/pbsimply/docengine/docutils.rb', line 55

def target_file_extensions
  [".rst"]
end