• This repository has been archived on 21/Nov/2021
  • Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Grunt wrapper task for Premailer

grunt-premailer

Grunt wrapper task for Premailer

Requirements

This plugin is a Grunt wrapper around the Premailer Ruby gem developed by Alex Dunae. In order to run it you will need the following packages installed on your system:

  • Node.js >= 0.12.0 (install wiki)
  • Grunt-cli >= 0.1.7 and Grunt >=0.4.2 (npm install grunt-cli -g)
  • Ruby >= 1.9.3 (installers)
  • Premailer >= 1.8.0 (gem install premailer and, most of the time, gem install nokogiri)

Getting Started

This plugin is compatible with Grunt 1.x but requires Grunt >=0.4.2

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-premailer --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-premailer');

The "premailer" task

Overview

In your project's Gruntfile, add a section named premailer to the data object passed into grunt.initConfig().

grunt.initConfig({
  premailer: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

options.mode

Type: String Default value: 'html'

Output format. Either 'html' (HTML formatted email) or 'txt' (plaintext email).

options.baseUrl

Type: String Default value: ''

Base URL to append to relative links.

options.bundleExec

Type: Boolean Default value: false

Run premailer with bundle exec ruby.

options.queryString

Type: String Default value: ''

Query string to append to links.

options.css

Type: Array Default value: []

Additional CSS stylesheets to process. Paths are relative to the Gruntfile.js file. Any Grunt compatible globbing and template syntax is supported.

options.removeClasses

Type: Boolean Default value: false

Removes HTML classes.

options.removeScripts

Type: Boolean Default value: false

Removes HTML scripts. _(was true by default until v0.2.5)

options.removeComments

Type: Boolean Default value: false

Removes HTML comments.

options.removeIds

Type: Boolean Default value: false

Removes HTML ids.

options.preserveStyles

Type: Boolean Default value: false

Preserve any link rel=stylesheet and style elements.

options.preserveStyleAttribute

Type: Boolean Default value: false

Preserve original style attribute.

options.lineLength

Type: Number Default value: 65

Line length for plaintext version.

options.ioException

Type: Boolean Default value: false

Aborts on I/O errors.

options.verbose

Type: Boolean Default value: false

Prints additional information at runtime.

options.warnLevel

Type: String Default value: 'safe'

What level of CSS compatibility warnings to show (either 'none', 'safe', 'poor', 'risky').

Usage Examples

Default Options

In this example, the default options are used to inline CSS styles in into the markup.

grunt.initConfig({
  premailer: {
    simple: {
      options: {},
      files: {
        'dest/email.html': ['src/email.html']
      }
    }
  }
})

Custom Options

In this example, custom options are used to append a query string (such as a google campaign click tracking) to every link.

grunt.initConfig({
  premailer: {
    withqs: {
      options: {
        queryString: 'utm_source=premailer&utm_medium=email&utm_campaign=test'
      },
      files: {
        'dest/email.html': ['src/email.html']
      }
    }
  }
})

Usage Notes

BaseUrl option and stylesheets parsing

Be aware that the base URL gets applied before inlining styles. This process will convert all relative linked stylesheets to absolute ones, possibly preventing the parser to retrieve the resources (since link tags point to a different location). In this scenario it's advisable to use the css option since it's uneffected from BaseUrl.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

1.0.0 Updated dependency and Grunt 1.x ready

0.2.13 Added option warnLevel and removeIds

0.2.12 Dependencies updated. Fixing a bug when source and destination files are the same (#25)

0.2.11 Fixing EventEmitter error (#21)

0.2.10 Merging #20 (thanks to @Iszak)

0.2.9 Merging #19 to add Bundler support (thanks to @Iszak)

0.2.8 Merging #18 to fix #16 and #17.

0.2.7 Minor bug fixing

0.2.6 Added option removeScriptsto preserve/remove script tags (was true by default until v0.2.5)

0.2.5 Added ability to remove temp folders even outside project folder (thanx to @fadomire)

0.2.4 Updated dependencies to Nodejs 0.10+, Grunt 0.4.2+ and Premailer 1.8.0+ (media query support). Added postinstall check for Premailer gem version.

0.2.3 Check for large HTML emails (see #1)

0.2.2 Bugfix when passing multiple file targets (see #5)

0.2.1 Bugfix in custom premailer script

0.2.0 - Moved to custom ruby script to execute premailer instead of premailer binary. Added removeComments and preserveStyles options. Premailer not requires v1.7.8 or greater.

0.1.1 - Replaced deprecated reference to grunt.util._ with lodash npm module

0.1.0 - Initial release

More Repositories

1

vue-types

Vue Prop Types definitions
TypeScript
569
star
2

grunt-email-boilerplate

A Grunt template to create emails
JavaScript
285
star
3

grunt-ejs-render

Grunt plugin to render EJS templates with custom data and helpers
JavaScript
10
star
4

grunt-nodemailer

Grunt wrapper for Nodemailer
JavaScript
9
star
5

storypug

JavaScript
9
star
6

yuzu

Old School Component Management
TypeScript
8
star
7

marco.solazzi.me

My personal website
Astro
8
star
8

stapes-ui

Stapes.js Widget Framework
JavaScript
6
star
9

eslint-plugin-vue-types

ESLint plugin for vue-types and eslint-plugin-vue
JavaScript
6
star
10

currency-converter

Simple currency converter in Svelte + UnoCSS
TypeScript
3
star
11

domhooks

Hooks functions' execution to DOM queries
JavaScript
3
star
12

timezone-converter

A simple date and time converted.
JavaScript
2
star
13

vue-pomodoro-timer

A customizable, pomodoro-like timer.
Vue
2
star
14

tsumami

ES6 DOM Utility function
JavaScript
2
star
15

ractive-adaptors-stapes

Stapes.js adaptor for Ractive.js
JavaScript
2
star
16

angular-todolist

A sample todolist in AngularJS
JavaScript
2
star
17

storybook-addon-storyout

Storybook addon to visualize stories HTML output
TypeScript
1
star
18

umeboshi-cli

Simple project scaffolding for SPA applications, inspired by vue-cli and https://poi.js.org
JavaScript
1
star
19

umeboshi-template-webpack

Webpack template for umeboshi-cli 3+
CSS
1
star
20

umeboshi-react

Umeboshi React Template
CSS
1
star
21

connect-placeholderimg

A connect middleware to generate placeholder images
JavaScript
1
star
22

TeacupJS

Sort of a prototype of companion JS Framework for Bancha CMS
JavaScript
1
star
23

mokd

Programmable fake APIs server
JavaScript
1
star
24

angular-todolist-fevr

A sample AngularJS todolist for the Frontenders Verona Workshop
JavaScript
1
star