summaryrefslogtreecommitdiff
path: root/config/initializers/markdown_handler.rb
blob: b9e73ba3f7e52e264e1f0208a4813de6b49068d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#
# This adds support for markdown in views. Just name the template with ".md"
# erb expansion is supported.
#

require 'rdiscount'

module MarkdownHandler
  def self.erb
    @erb ||= ActionView::Template.registered_template_handler(:erb)
  end

  def self.call(template)
    compiled_source = erb.call(template)
    "RDiscount.new(begin;#{compiled_source};end, :generate_toc, :smart, :autolink).to_html"
  end
end

ActionView::Template.register_template_handler :md, MarkdownHandler