Coder Social home page Coder Social logo

naartjie / swig-email-templates Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrewrk/swig-email-templates

0.0 2.0 1.0 156 KB

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

License: Other

JavaScript 25.83% CSS 8.97% HTML 65.20%

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.
  • Text emails - for a template name passed into render(), if a file exists with the same name but a .txt extension it will be rendered separately. If the .txt file does not exist, html-to-text will auto-generate a text version of the html file. This can be disabled with the option text: false.

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, text) {
    // send html/text 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

swig-email-templates's People

Contributors

andrewrk avatar ckeenan avatar jamesplease avatar jhalickman avatar podviaznikov avatar psirenny avatar

Watchers

 avatar  avatar

Forkers

vitardus

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.