An efficient pipeline to build MJML-based HTML for emails.
JavaScript Smarty CSS HTML
Latest commit dce90e9 Oct 12, 2016 @Daylon committed on GitHub Merge pull request #2 from Daylon/greenkeeper-gulp-htmlmin-3.0.0
Update gulp-htmlmin to version 3.0.0 ๐Ÿš€
Permalink
Failed to load latest commit information.
__styles
__templates Init Jun 8, 2016
gulptasks Adding a maxLineLength parameter according to RFC required limit Jun 13, 2016
.gitignore
.stylelintrc Updating SCSS linter rule Sep 27, 2016
README.md
gulpfile.js Init Jun 8, 2016
package.json

README.md

hbs-mjml-seed

Gulp pipeline example dedicated to build HTML emails.

Disclaimer

This is a mere prototype. Use it at your own risks. This was intended to provide a faster to build a complete set of emails with custom parts and styling.

Usage

$ git clone https://github.com/Daylon/hbs-mjml-seed.git
$ cd hbs-mjml-seed
$ gulp

This pipeline use MJML for custom email markup, Handlebars for templating and SASS for styling. Please refer to their own documentation and/or repo for help:

Let's keep MJML and CSS separated, shall we?

Rationale

The same way that making HTML for email can be tedious, having to tweak CSS rules attributes by hand can be cumbersome as well. For these reasons, I didn't want to regress from my previous setup but MJML is pretty much the only solution (at the time of this writing) to provide a markup capable of removing noise from your HMTL templates.

To achieve this, this pipeline leverages a fork from the fantastic lib inline-css by (and, in the process, gulp-inline-css; same author). Here's the pull request, if you wish to weigh in. While this lib neatly converts class related css rules into style attributes, I tweak it up to support any custom rule, including exotic ones (e.g. full-width).

Interesting side-effect: VML style attributes (for, say, call-to-actions) can now be set, so you won't have to worry about having discrepancies between templates and style rules when modifying your call-to-actions.

Can I change these definitions?

Yes, you can. Open up /gulptasks/core/core-mjml.js and start adding properties. By default, any added rule will become an attribute.

Templating

Why using Handlebars

Handlebars allows us to use a neat built-in feature that make it skip partials declaration on first pass.

\{{>partialName}} (Source)

This way, a single handlebars template can produce multiple files, based on the first layer of variables, ready to be fed with real production data.

Use case: theming

First round โ€”Gulp task

Given a single index.tpl, we loop through an array of JSON data defined in /gulptasks/core/core-templates.js. Each index sets up what is static: pre-header, default unsuscribe link, invoke the correct partial, etc.

Second pass โ€”on server

The produced new templates (one per theme) can now be used for a specific scenario or userbase sampling.

Shortcomings

MJML being a young project, some elements can still be buggy or lack optimizations; you may have to mix up both MJML and raw html.