Class: Tilt::PandocTemplate

Inherits:
Template show all
Defined in:
lib/tilt/pandoc.rb

Overview

Pandoc markdown implementation. See: pandoc.org/

Direct Known Subclasses

RstPandocTemplate

Instance Attribute Summary

Attributes inherited from Template

#data, #file, #line, #options

Instance Method Summary collapse

Methods inherited from Template

#basename, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Instance Method Details

#allows_script?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/tilt/pandoc.rb', line 45

def allows_script?
  false
end

#evaluate(scope, locals, &block) ⇒ Object



41
42
43
# File 'lib/tilt/pandoc.rb', line 41

def evaluate(scope, locals, &block)
  @output ||= @engine.to_html.strip
end

#pandoc_optionsObject

turn options hash into an array Map tilt options to pandoc options Replace hash keys with value true with symbol for key Remove hash keys with value false Leave other hash keys untouched



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tilt/pandoc.rb', line 23

def pandoc_options
  options.reduce([]) do |sum, (k,v)|
    case v
    when true
      sum << (tilt_to_pandoc_mapping[k] || k)
    when false
      sum
    else
      sum << { k => v }
    end
  end
end

#prepareObject



36
37
38
39
# File 'lib/tilt/pandoc.rb', line 36

def prepare
  @engine = PandocRuby.new(data, *pandoc_options)
  @output = nil
end

#tilt_to_pandoc_mappingObject



10
11
12
13
14
15
16
# File 'lib/tilt/pandoc.rb', line 10

def tilt_to_pandoc_mapping
  { :smartypants => :smart,
    :escape_html => { :f => 'markdown-raw_html' },
    :commonmark => { :f => 'commonmark' },
    :markdown_strict => { :f => 'markdown_strict' }
  }
end