Skip to content

Instantly share code, notes, and snippets.

@ingeniarius
Created July 29, 2013 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ingeniarius/6105667 to your computer and use it in GitHub Desktop.
Save ingeniarius/6105667 to your computer and use it in GitHub Desktop.
.merb handler for Rails, inspired by https://github.com/plataformatec/markerb
require "action_view/template"
require "redcarpet"
module MerbHandler
mattr_accessor :processing_options, :renderer
@@processing_options = {}
@@renderer = Redcarpet::Render::XHTML
class Handler
def erb_handler
@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
end
def call(template)
compiled_source = erb_handler.call(template)
if template.formats.include?(:html)
"Redcarpet::Markdown.new(MerbHandler.renderer, MerbHandler.processing_options).render(begin;#{compiled_source};end).html_safe"
else
compiled_source
end
end
end
end
ActionView::Template.register_template_handler :merb, MerbHandler::Handler.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment