Class: Tilt::Redcarpet2Template

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

Overview

Future proof mode for Redcarpet 2.x (not yet released)

Instance Attribute Summary

Attributes inherited from Template

#data, #file, #line, #options

Class Method Summary collapse

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

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/tilt/redcarpet.rb', line 38

def self.engine_initialized?
  defined? ::Redcarpet::Render and defined? ::Redcarpet::Markdown
end

Instance Method Details

#allows_script?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/tilt/redcarpet.rb', line 76

def allows_script?
  false
end

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



72
73
74
# File 'lib/tilt/redcarpet.rb', line 72

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

#generate_rendererObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tilt/redcarpet.rb', line 42

def generate_renderer
  renderer = options.delete(:renderer) || ::Redcarpet::Render::HTML
  return renderer unless options.delete(:smartypants)
  return renderer if renderer.is_a?(Class) && renderer <= ::Redcarpet::Render::SmartyPants

  if renderer == ::Redcarpet::Render::XHTML
    ::Redcarpet::Render::SmartyHTML.new(:xhtml => true)
  elsif renderer == ::Redcarpet::Render::HTML
    ::Redcarpet::Render::SmartyHTML
  elsif renderer.is_a? Class
    Class.new(renderer) { include ::Redcarpet::Render::SmartyPants }
  else
    renderer.extend ::Redcarpet::Render::SmartyPants
  end
end

#prepareObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tilt/redcarpet.rb', line 58

def prepare
  # try to support the same aliases
  Redcarpet1Template::ALIAS.each do |opt, aka|
    next if options.key? opt or not options.key? aka
    options[opt] = options.delete(aka)
  end

  # only raise an exception if someone is trying to enable :escape_html
  options.delete(:escape_html) unless options[:escape_html]

  @engine = ::Redcarpet::Markdown.new(generate_renderer, options)
  @output = nil
end