Sha256: d9cb7b0e4f669a8d5bf5776eb1a13ee827189cb26610785ff9a9649b6744c297
Contents?: true
Size: 812 Bytes
Versions: 4
Compression:
Stored size: 812 Bytes
Contents
require 'erubis' require 'rdiscount' require 'sinatra/base' module Sinatra module RDiscount def rdiscount(template, options={}, locals={}) render :rdiscount, template, options, locals end private def render_rdiscount(template, data, options, locals, &block) if block_given? # render layout instance = ::Erubis::Eruby.new(data) else # render template markdown = ::RDiscount.new(data) html = markdown.to_html instance = ::Erubis::Eruby.new(html, :pattern => '\{% %\}') end locals_assigns = locals.to_a.collect { |k,v| "#{k} = locals[:#{k}]" } src = "#{locals_assigns.join("\n")}\n#{instance.src}" eval src, binding, '(__ERB__)', locals_assigns.length + 1 end end helpers RDiscount end
Version data entries
4 entries across 4 versions & 1 rubygems