#
# 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