Class: Tilt::CommonMarkerTemplate

Inherits:
Template
  • Object
show all
Defined in:
lib/tilt/commonmarker.rb

Constant Summary collapse

OPTION_ALIAS =
{
  :smartypants => :SMART
}
PARSE_OPTIONS =
[
  :SMART,
  :smartypants,
].freeze
RENDER_OPTIONS =
[
  :GITHUB_PRE_LANG,
  :HARDBREAKS,
  :NOBREAKS,
  :SAFE,
  :SOURCEPOS,
].freeze
EXTENSIONS =
[
  :autolink,
  :strikethrough,
  :table,
  :tagfilter,
].freeze

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)


74
75
76
# File 'lib/tilt/commonmarker.rb', line 74

def allows_script?
  false
end

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



69
70
71
72
# File 'lib/tilt/commonmarker.rb', line 69

def evaluate(scope, locals, &block)
  doc = CommonMarker.render_doc(data, parse_options, extensions)
  doc.to_html(render_options, extensions)
end

#extensionsObject



29
30
31
32
33
# File 'lib/tilt/commonmarker.rb', line 29

def extensions
  EXTENSIONS.select do |extension|
    options[extension]
  end
end

#parse_optionsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tilt/commonmarker.rb', line 35

def parse_options
  raw_options = PARSE_OPTIONS.select do |option|
    options[option]
  end
  actual_options = raw_options.map do |option|
    OPTION_ALIAS[option] || option
  end

  if actual_options.any?
    actual_options
  else
    :DEFAULT
  end
end

#prepareObject



64
65
66
67
# File 'lib/tilt/commonmarker.rb', line 64

def prepare
  @engine = nil
  @output = nil
end

#render_optionsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tilt/commonmarker.rb', line 50

def render_options
  raw_options = RENDER_OPTIONS.select do |option|
    options[option]
  end
  actual_options = raw_options.map do |option|
    OPTION_ALIAS[option] || option
  end
  if actual_options.any?
    actual_options
  else
    :DEFAULT
  end
end