Class: PandocRuby
- Inherits:
-
Object
- Object
- PandocRuby
- Defined in:
- lib/pandoc-ruby.rb
Constant Summary collapse
- READERS =
The available readers and their corresponding names. The keys are used to generate methods and specify options to Pandoc.
{ 'native' => 'pandoc native', 'json' => 'pandoc JSON', 'markdown' => 'markdown', 'rst' => 'reStructuredText', 'textile' => 'textile', 'html' => 'HTML', 'latex' => 'LaTeX' }.freeze
- STRING_WRITERS =
The available string writers and their corresponding names. The keys are used to generate methods and specify options to Pandoc.
{ 'native' => 'pandoc native', 'json' => 'pandoc JSON', 'html' => 'HTML', 'html5' => 'HTML5', 's5' => 'S5 HTML slideshow', 'slidy' => 'Slidy HTML slideshow', 'dzslides' => 'Dzslides HTML slideshow', 'docbook' => 'DocBook XML', 'opendocument' => 'OpenDocument XML', 'latex' => 'LaTeX', 'beamer' => 'Beamer PDF slideshow', 'context' => 'ConTeXt', 'texinfo' => 'GNU Texinfo', 'man' => 'groff man', 'markdown' => 'markdown', 'plain' => 'plain', 'rst' => 'reStructuredText', 'mediawiki' => 'MediaWiki markup', 'textile' => 'textile', 'rtf' => 'rich text format', 'org' => 'emacs org mode', 'asciidoc' => 'asciidoc' }.freeze
- BINARY_WRITERS =
The available binary writers and their corresponding names. The keys are used to generate methods and specify options to Pandoc.
{ 'odt' => 'OpenDocument', 'docx' => 'Word docx', 'epub' => 'EPUB V2', 'epub3' => 'EPUB V3' }.freeze
- WRITERS =
All of the available Writers.
STRING_WRITERS.merge(BINARY_WRITERS)
- @@pandoc_path =
'pandoc'
Instance Attribute Summary collapse
-
#binary_output ⇒ Object
Returns the value of attribute binary_output.
-
#option_string ⇒ Object
Returns the value of attribute option_string.
-
#options ⇒ Object
Returns the value of attribute options.
-
#writer ⇒ Object
Returns the value of attribute writer.
Class Method Summary collapse
-
.convert(*args) ⇒ Object
A shortcut method that creates a new PandocRuby object and immediately calls ‘#convert`.
-
.pandoc_path=(path) ⇒ Object
To use run the pandoc command with a custom executable path, the path to the pandoc executable can be set here.
Instance Method Summary collapse
-
#convert(*args) ⇒ Object
(also: #to_s)
Run the conversion.
-
#initialize(*args) ⇒ PandocRuby
constructor
Create a new PandocRuby converter object.
Constructor Details
#initialize(*args) ⇒ PandocRuby
Create a new PandocRuby converter object. The first argument contains the input either as string or as an array of filenames.
Any other arguments will be converted to pandoc options.
Usage:
new("# A String", :option1 => :value, :option2)
new(["/path/to/file.md"], :option1 => :value, :option2)
new(["/to/file1.html", "/to/file2.html"], :option1 => :value)
103 104 105 106 107 108 109 110 |
# File 'lib/pandoc-ruby.rb', line 103 def initialize(*args) if args[0].is_a?(String) @input_string = args.shift elsif args[0].is_a?(Array) @input_files = args.shift.join(' ') end self. = args end |
Instance Attribute Details
#binary_output ⇒ Object
Returns the value of attribute binary_output.
84 85 86 |
# File 'lib/pandoc-ruby.rb', line 84 def binary_output @binary_output end |
#option_string ⇒ Object
Returns the value of attribute option_string.
79 80 81 |
# File 'lib/pandoc-ruby.rb', line 79 def option_string @option_string end |
#options ⇒ Object
Returns the value of attribute options.
74 75 76 |
# File 'lib/pandoc-ruby.rb', line 74 def end |
#writer ⇒ Object
Returns the value of attribute writer.
89 90 91 |
# File 'lib/pandoc-ruby.rb', line 89 def writer @writer end |
Class Method Details
.convert(*args) ⇒ Object
A shortcut method that creates a new PandocRuby object and immediately calls ‘#convert`. Options passed to this method are passed directly to `#new` and treated the same as if they were passed directly to the initializer.
70 71 72 |
# File 'lib/pandoc-ruby.rb', line 70 def self.convert(*args) new(*args).convert end |
.pandoc_path=(path) ⇒ Object
To use run the pandoc command with a custom executable path, the path to the pandoc executable can be set here.
62 63 64 |
# File 'lib/pandoc-ruby.rb', line 62 def self.pandoc_path=(path) @@pandoc_path = path end |
Instance Method Details
#convert(*args) ⇒ Object Also known as: to_s
Run the conversion. The convert method can take any number of arguments, which will be converted to pandoc options. If options were already specified in an initializer or reader method, they will be combined with any that are passed to this method.
Returns a string with the converted content.
Example:
PandocRuby.new("# text").convert
# => "<h1 id=\"text\">text</h1>\n"
123 124 125 126 127 128 129 130 131 |
# File 'lib/pandoc-ruby.rb', line 123 def convert(*args) self. += args if args self.option_string = (self.) if self.binary_output convert_binary else convert_string end end |