|
| 1 | +# Grunt Email Design Workflow |
| 2 | +based on [github.com/leemunroe](https://github.com/leemunroe/grunt-email-workflow) |
| 3 | + |
| 4 | +## Changelog |
| 5 | + |
| 6 | +### v0.2.0 - 09/01/2024 |
| 7 | + |
| 8 | +* update packages and dependencies for current node versions: nvm not needed |
| 9 | +* disable third-party connections (see [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation)) |
| 10 | + |
| 11 | +## Purpose |
| 12 | + |
| 13 | +Designing and testing emails is a pain. HTML tables, inline CSS, various devices and clients to test, and varying support for the latest web standards. |
| 14 | + |
| 15 | +This Grunt task helps simplify things. |
| 16 | + |
| 17 | +1. Compiles your SCSS to CSS |
| 18 | +2. Builds your HTML email templates |
| 19 | +3. Inlines your CSS |
| 20 | + |
| 21 | +## Requirements |
| 22 | + |
| 23 | +You may already have these installed on your system. If not, you'll have to install them. |
| 24 | + |
| 25 | +* Node.js - [Install Node.js](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager) |
| 26 | +* Grunt-cli and Grunt (`npm install grunt-cli -g`) |
| 27 | +* (optional) [Litmus](https://litmus.com) - Tests the email across all clients/browsers/devices |
| 28 | + |
| 29 | +## Getting started |
| 30 | + |
| 31 | +If you haven't used [Grunt](http://gruntjs.com/) before check out Chris Coyier's post on [getting started with Grunt](http://24ways.org/2013/grunt-is-not-weird-and-hard/). |
| 32 | + |
| 33 | +#### 1. Setup |
| 34 | + |
| 35 | +Clone this repo, cd to the directory, run `npm install` to install the necessary packages. |
| 36 | + |
| 37 | +```sh |
| 38 | +cd grunt-email-workflow |
| 39 | +npm install |
| 40 | +``` |
| 41 | + |
| 42 | +#### 2. Run Grunt |
| 43 | + |
| 44 | +Run `grunt build` and check out your `/dist` folder to see your compiled and inlined email templates. |
| 45 | + |
| 46 | +Run `grunt serve`, a new live-reload browser tab will open. Happy coding :) |
| 47 | + |
| 48 | +## How it works |
| 49 | + |
| 50 | +### CSS |
| 51 | + |
| 52 | +This project uses [SCSS](http://sass-lang.com/). You don't need to touch the .css files, these are compiled automatically. |
| 53 | + |
| 54 | +For changes to CSS, modify the `.scss` files. |
| 55 | + |
| 56 | +Media queries and responsive styles are in a separate style sheet so that they don't get inlined. Note that only a few clients support media queries e.g. iOS Mail app. |
| 57 | + |
| 58 | +### Email templates and content |
| 59 | + |
| 60 | +Handlebars and Assemble are used for templating. |
| 61 | + |
| 62 | +`/layouts` contains the standard header/footer HTML wrapper markup. You most likely will only need one layout template, but you can have as many as you like. |
| 63 | + |
| 64 | +`/emails` is where your email content will go. To start you off I've included example transactional emails based on my [simple HTML email template](https://github.com/leemunroe/html-email-template). |
| 65 | + |
| 66 | +`/data` contains _optional_ .yml or .json data files that can be used in your templates. It's a good way to store commonly used strings and variables. See `/data/default.yml` and `/partials/follow_lee.hbs` for an example. |
| 67 | + |
| 68 | +`/partials` contains _optional_ .hbs files that can be thought of like includes. To use a partial, for example `/partials/follow_lee.hbs` you would use the following code in your emails template: |
| 69 | + |
| 70 | +```hbs |
| 71 | +{{> follow_lee }} |
| 72 | +``` |
| 73 | + |
| 74 | +`/partials/components` contains _optional_ .hbs files that can help generate your markup. Each component will typically have a corresponding Sass file in `src/css/sass/<component_name>.scss`. To use a component, for example `/partials/components/button.hbs` you would use the following code in your emails template. _(note: You can use single -or- double quotes for attributes)_ |
| 75 | + |
| 76 | +```hbs |
| 77 | +{{> button type="primary" align="center" url="LINK GOES HERE" title="ANCHOR TEXT GOES HERE" }} |
| 78 | +``` |
| 79 | + |
| 80 | +### Generate your email templates |
| 81 | + |
| 82 | +In terminal, run `grunt build`. This will: |
| 83 | + |
| 84 | +* Compile your SCSS to CSS |
| 85 | +* Generate your email layout and content |
| 86 | +* Inline your CSS |
| 87 | + |
| 88 | +See the output HTML in the `dist` folder. Open them and preview it the browser. |
| 89 | + |
| 90 | +Alternatively run `grunt serve`. This will check for any changes you make to your .scss and .hbs templates, automatically run the tasks, and serve you a preview in the browser on http://localhost:4000. Saves you having to run grunt every time you make a change. |
| 91 | + |
| 92 | +### Browser-based previews |
| 93 | + |
| 94 | +In terminal, run `grunt serve`. |
| 95 | + |
| 96 | +* This will run the default tasks `grunt` + the `watch` task will be initiated |
| 97 | +* A preview UI will automagically open on [http://localhost:4000](http://localhost:4000) and you can review your templates |
| 98 | +* Go about your business editing templates and see your template changes live-reload |
| 99 | +* __NOTE:__ The express server stops working when the `watch` task is not running |
| 100 | + |
| 101 | + |
| 102 | +### Sample email templates |
| 103 | + |
| 104 | +I've added a few templates here to help you get started. |
| 105 | + |
| 106 | +* [Simple transactional email template](http://leemunroe.github.io/grunt-email-workflow/dist/transaction.html) |
| 107 | +* [Branded email via CDN](http://leemunroe.github.io/grunt-email-workflow/dist/branded.html) |
| 108 | +* [Email with components](http://leemunroe.github.io/grunt-email-workflow/dist/components.html) |
| 109 | + |
| 110 | +### More resources |
| 111 | + |
| 112 | +* For more transactional email templates check out [HTML Email templates](https://htmlemail.io) |
| 113 | +* [Things I've learned about sending email](http://www.leemunroe.com/sending-email-designers-developers/) |
| 114 | +* [Things I've learned about building email templates](http://www.leemunroe.com/building-html-email/) |
| 115 | +* [Things I've learned about responsive email](https://www.leemunroe.com/responsive-email-design/) |
| 116 | +* Prefer Gulp? Daryll Doyle has created a [Gulp email creator](https://github.com/darylldoyle/Gulp-Email-Creator) |
0 commit comments