Class: Maliq::Converter

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/maliq/converter.rb

Constant Summary

Constants included from FileUtils

FileUtils::SPLIT_MARKER

Instance Attribute Summary collapse

Instance Method Summary collapse

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' }
  retrieve_meta_from_yfm
  set_meta(opts)
end

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/maliq/converter.rb', line 8

def meta
  @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 = convert_liquid_tags(@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 set_meta(meta)
  @meta.update(meta)
end