Class: Maliq::Converter
- Inherits:
-
Object
- Object
- Maliq::Converter
- Includes:
- FileUtils
- Defined in:
- lib/maliq/converter.rb
Constant Summary
Constants included from FileUtils
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Instance Method Summary collapse
-
#initialize(text, opts = {}) ⇒ Converter
constructor
A new instance of Converter.
- #run(template = :epub, context = {}) ⇒ Object (also: #to_xhtml, #convert)
- #save(path = "out.xhtml") ⇒ Object
- #set_meta(meta) ⇒ Object
Methods included from FileUtils
create_filename, retrieveYFM, split
Constructor Details
#initialize(text, opts = {}) ⇒ Converter
Returns a new instance of Converter.
9 10 11 12 13 14 15 16 |
# File 'lib/maliq/converter.rb', line 9 def initialize(text, opts={}) @engine = ->text{ ::RDiscount.new(text).to_html } @text = text @converted = nil @meta = { language:'ja', liquid:'plugins' } (opts) end |
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
8 9 10 |
# File 'lib/maliq/converter.rb', line 8 def @meta end |
Instance Method Details
#run(template = :epub, context = {}) ⇒ Object Also known as: to_xhtml, convert
18 19 20 21 |
# File 'lib/maliq/converter.rb', line 18 def run(template=:epub, context={}) text = (@text, context) @converted = apply_template(template) { @engine.call(text) } end |
#save(path = "out.xhtml") ⇒ Object
25 26 27 28 |
# File 'lib/maliq/converter.rb', line 25 def save(path="out.xhtml") @converted ||= run File.write(path, @converted) end |
#set_meta(meta) ⇒ Object
30 31 32 |
# File 'lib/maliq/converter.rb', line 30 def () @meta.update() end |