Giter VIP home page Giter VIP logo

mjml-premailer's Introduction

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

mjml-premailer's People

Contributors

angelinatarapko avatar srghma avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.