Git Product home page Git Product logo

swig-email-templates's Introduction

Build Status

swig-email-templates

Node.js module for rendering emails with swig templates and email-friendly inline CSS using juice.

Inspired by niftylettuce/node-email-templates.

Features

  • Uses swig, which supports Django-inspired template inheritance.
  • Uses juice, which takes an HTML file and inlines all the <link rel="stylesheet">s and the <style>s.
  • URL rewrite support - you can provide a urlRewriteFn argument to rewrite your links.

Usage

var path = require('path')
  , emailTemplates = require('swig-email-templates')

var options = {
  root: path.join(__dirname, "templates"),
  // any other swig options allowed here
};
emailTemplates(options, function(err, render) {
  var context = {
    meatballCount: 9001,
  };
  render('meatball-sandwich.html', context, function(err, html) {
    // send html email
  });
});

Command Line

Installing swig-email-templates through npm will put the swig-email-templates command in your system path, allowing it to be run from any directory.

Usage

swig-email-templates render [files] [options]

Where [files] can be any number of input files to process.

The options are:

  • -v, --version: Display the installed version of swig-email-templates

  • -h, --help: Show the help screen

  • -o --output: The directory to output your files to. Defaults to stdout

  • -r, --root: The root location for the files. The default is templates.

  • -j, --json: The file that contains your context, stored in JSON

  • -c, --context: The file that contains your context, stored as a CommonJS module. Used only if -j is not provided.

Example usage

The following examples renders two files, email1.html and email2.html, which are both contained in the cwd. It uses the context stored in context/main.json for rendering, and places the results in the folder output.

swig-email-templates render email1.html email2.html -r ./ -o output/ -j context/main.json

Release Notes

1.0.0

  • BREAKING CHANGE - the ability to generate a dummy context was removed because swig dropped support for ability to access the parse tree when it went to 1.x.
  • Update swig dependency to 1.3.0
  • Update jsdom dependency to 0.8.11
  • Switch to juice2 fork

0.7.0

  • added command line program (thanks jmeas)

0.6.0

  • updated swig to 0.14.0

0.5.1

  • updated juice to 0.4.0

0.5.0

  • BREAKING CHANGE - render and generateDummy no longer automatically append .html to your template name to look it up. This means that if you before had render('meatball-sandwich') you must change it to render('meatball-sandwich.html') to work with 0.5.0.
  • fixed crash during cleanup
  • updated juice to 0.3.2
  • updated jsdom to 0.5.4

swig-email-templates's People

Contributors

andrewrk avatar jamesplease avatar avbel avatar podviaznikov avatar jhalickman avatar

Watchers

James Cloos 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.