ActionMailer : Render multipart emails (text/html) from markdown the correct way?

Viewed 510

I would like to render all my emails from markdown with using a layout "email". Have been investigating gems and options there are 2 gems I could both could not get to work:

maildown and markerb.

Has anyone implemented a method to render text,html emails with action mailer from a markdown mail template and also using a layout? Or knows a good updated writeup on this?

Markerb registers a .markerb file extension like so:

module Markerb
  class Railtie < ::Rails::Railtie
    config.markerb = Markerb
    config.app_generators.mailer :template_engine => :markerb
  end
end

and require "redcarpet" require "markerb/railtie"

module Markerb
  mattr_accessor :processing_options, :renderer
  @@processing_options = {}
  @@renderer = Redcarpet::Render::HTML

  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(Markerb.renderer, Markerb.processing_options).render(begin;#{compiled_source};end).html_safe"
      else
        compiled_source
      end
    end
  end
end

ActionView::Template.register_template_handler :markerb, Markerb::Handler.new
0 Answers
Related