0.0
No release in over 3 years
Low commit activity in last 3 years
This gem will processes html part of your mail using `mjml` cli before delivery using rails ActionMailer hook
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.3

Runtime

 Project Readme

mjml-premailer

Write your emails using mjml framework on rails, using any template language supported by Rails

Travis Gem Version Maintainability Coverage Status

How it works

This gem will processes html part of your mail using mjml cli before delivery, just use mjml_mail function for delivery instead of mail

class ApplicationMailer < ActionMailer::Base
  include MjmlPremailer::MjmlMail # adds function `mjml_mail`

  layout "mailer"
end
class WelcomeMailer < ApplicationMailer
  def welcome(user)
    @user = user
    mjml_mail(to: @user.email, subject: 'Welcome')
  end
end
<!-- app/views/layouts/mailer.html.erb -->

<mjml>
  <mj-head>
    <mj-head>
      My site
    <mj-head>
  <mj-head>
  <mj-body>
    <%= yield %>
  <mj-body>
</mjml>
<!-- app/views/welcome_mailer/welcome.html.erb -->

<mj-text>Hello, <%= @user.name %></mj-text>

Or you can transform mail object yourself using

MjmlPremailer::TransformMail.transform_mail(mail)

Example rails project you can find here

Mjml documentation is here

Installation

Install mjml npm package (v4) globally

$ npm install -g mjml@^4.0

or locally

$ npm install --save-dev mjml@^4.0

Add the gem to your Gemfile:

gem "mjml-premailer"

Configuration options

In /config/initializers/mjml_premailer.rb

MjmlPremailer.config.merge!(
  minify:        Rails.env.production?,  # default - false
  beautify:      !Rails.env.production?, # default - true
  keep_comments: !Rails.env.production?, # default - false

  ## other possible options

  # debug: false,           # default - false
  # bin:   ...,             # by default bin path is found authomatically, but you can specify it here
  # validation_level: :skip # default - :skip, possible options - :strict/:soft/:skip
)

More about options here

Difference from other gems

sighmon/mjml-rails:

  • no support for /app/views/layouts

kolybasov/mjml-ruby:

  • best gem I found, this gem is based on it, thanks kolybasov for his work
  • doesnt support mjml v4 (at time of writing)
  • doesnt support template languages other then erb (at least I didnt managed)

Hacking

make run_env
make test
make publish