Class: Pandoku::Document
- Inherits:
-
Object
- Object
- Pandoku::Document
- Defined in:
- lib/pandoku/document.rb
Overview
Pseudo IR for Pandoc.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#command_for(format) ⇒ Object
Makes a command string to execute Pandoc.
-
#compile(format, io = false) ⇒ Object
Compiles the document to given
format
. -
#initialize(format, text) ⇒ Document
constructor
A new instance of Document.
Constructor Details
#initialize(format, text) ⇒ Document
Returns a new instance of Document.
11 12 13 14 15 16 17 |
# File 'lib/pandoku/document.rb', line 11 def initialize(format, text) unless format.is_a?(InputFormat) raise TypeError, 'format must be InputFormat' end @format = format @text = text end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/pandoku/document.rb', line 9 def format @format end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
9 10 11 |
# File 'lib/pandoku/document.rb', line 9 def text @text end |
Instance Method Details
#command_for(format) ⇒ Object
Makes a command string to execute Pandoc.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pandoku/document.rb', line 20 def command_for(format) commands = [PANDOC_PATH, '-f', self.format.class.name, '-t', format.class.name] commands += self.format.cliopts commands += format.cliopts escapeshellarg = lambda do |arg| "'" + arg.to_s.gsub(/[^\\]'/) {|s| %<#{s.chars.first}\\'> } + "'" end commands.select {|v| v }.collect(&escapeshellarg).join(' ') end |
#compile(format, io = false) ⇒ Object
Compiles the document to given format
. If a second argument io
is true
, returns IO
instead of String
.
33 34 35 36 37 38 |
# File 'lib/pandoku/document.rb', line 33 def compile(format, io = false) unless format.is_a?(OutputFormat) raise TypeError, 'format must be OutputFormat' end format.compile(self, io) end |