Git Product home page Git Product logo

swig-email-templates's Introduction

swig-email-templates

This package is unmaintained; please volunteer if you want it to not rely on outdated dependencies.

swig-email-templates is a 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 function 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.

Upgrading from 1.x

Check out the changelog for details of what changed since 1.x. The upgrade should be pretty straightforward.

Quick start

Install:

npm install swig-email-templates

A quick working example:

var EmailTemplates = require('swig-email-templates');
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport();

var templates = new EmailTemplates();
var context = {
  meatballCount: 9001
};

const { html, text, subject } = await templates.render('meatball-sandwich.html', context) 
transporter.sendMail({
    from: 'sender@address',
    to: 'receiver@address',
    subject: subject,
    html: html,
    text: text
});

EmailTemplates API

Constructor(options)

Creates a a new EmailTemplates instance.

var EmailTemplates = require('swig-email-templates');
var templates = new EmailTemplates();

To set options, pass an object to the constructor. It can have the following keys:

root (string)

Path to template files. Defaults to path.join(__dirname, 'templates')

swig (object)

Swig options. Gets passed to swig.setDefaults(). See swig documentation for more information.

filters (object)

An object of Swig filters to set. Format: { name1: method1, name2: method2 }. For more information see Swig documentation for setFilter().

juice (object)

Juice options. See juice documentation for more information.

rewrite (function(cheerio instance))

After rendering the template and running the rewriteUrl function (see below), but before inlining resources, this function will be called if provided. It will be passed a cheerio instance and can alter its content. Cheerio instances are modified in-place so it does not need to return a value.

rewriteUrl (function (string) => string)

Each a href attribute in the output HTML will have its value replaced by the result of calling this function with the original href value.

text (boolean)

Whether to generate text alternative to HTML. Defaults to true.

Example

new EmailTemplates({
  root: '/var/www/test.site/templates',
  text: false,       // Disable text alternatives
  swig: {
    cache: false     // Don't cache swig templates
  },
  filters: {
    upper: function(str) {
      return str.toUpperCase();
    }
  },
  juice: {
    webResources: {
      images: 8      // Inline images under 8kB
    }
  },
  rewriteUrl: function (url) {
    return url + 'appendage';
  },
  rewrite: function($) {
    $("img").each(function(idx, anchor) {
      $(anchor).attr('src', 'no-img.png');
    });
  }
})

render(templateName, context, callback?)

Render a template with templateName, with the context provided.

If no callback is given, returns a promise which resolves to an object that looks like { html, text, subject }.

If a callback function is given, use legacy callback style. The callback has the signature function(err, html, text, subject).

Example (promise):

const EmailTemplates = require('swig-email-templates');
const templates = new EmailTemplates();
const { html, text, subject } = await templates.render('template.html', { user: 55 })
// html is inlined html
// text is text equivalent
// subject is parsed subject template or null if not found

Example (callback):

const EmailTemplates = require('swig-email-templates');
const templates = new EmailTemplates();
templates.render('template.html', { user: 55 }, function (err, html, text, subject) {
  // html is inlined html
  // text is text equivalent
  // subject is parsed subject template or null if not found
})

Behaviour of text templates

If the 'text' option is true (see above), then swig-email-templates will attempt to create a text equivalent as well as your HTML. By default, this will be by rendering the HTML output as text using html-to-text.

You can provide your own text template to override this behaviour. This should have the same basename as your HTML template but end in '.txt' instead of '.html'. For example, if your HTML template is 'template.html' then the text version should be 'template.txt'. This will receive the same context as the HTML template.

If the 'text' option is false, then no text alternative will be generated and the callback passed to the EmailTemplate.render() function will receive a falsy value instead of text as its third argument.

Behaviour of subject templates

swig-email-templates will attempt to create a text equivalent as well as your HTML. This template should have the same basename as your HTML template but end in .subject.txt. This will receive the same context as the HTML template.

Using subject templates, you can generate subject that contains variables.

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 [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 ..
  • -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

The following example 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 email1.html email2.html -o output/ -j context/main.json

Tests

npm test

swig-email-templates's People

Contributors

andrewrk avatar ckeenan avatar dependabot[bot] avatar jamesplease avatar jhalickman avatar luanmuniz avatar mattaudesse avatar maxwell2022 avatar podviaznikov avatar psirenny avatar takkaria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

swig-email-templates's Issues

Package.js out of date

Hello, I just update to node v12 and now I'm having an issue "error: uncaughtException: Module did not self-register" and I think is because the package.json inside swig-email-templates is really out of date.

I'm trying to trace the error and I think is jsdom because you are using "jsdom": "~3.1.2", and they are in the version 5.

Thanks

Breaks on node/iojs > v0.11.13, TypeError: Cannot read property 'removeChild' of nul

I'm getting a TypeError: Cannot read property 'removeChild' of null, for something which used to work on node v0.11.13, and is broken on any node or iojs version after that:

TypeError: Cannot read property 'removeChild' of null
  at removeStyleTags (server/node_modules/swig-email-templates/node_modules/juice2/lib/juice.js:272:32)
  at getStylesData (server/node_modules/swig-email-templates/node_modules/juice2/lib/juice.js:294:3)
  at /Users/marchi/Project/Swarm/loyalty-server/node_modules/swig-email-templates/node_modules/juice2/lib/juice.js:356:5

This looks related to andrewrk/juice#16.

Rendering Text Emails

Like node-email-templates, can swig-email-templates render text versions of emails as well?

Cannot set property 'useTemplate' of undefined

hi,
Code :-


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

var options = {
    root: path.join(__dirname, '../templates')
    // any other swig options allowed here
};
console.log('-------------------------------------------options'+JSON.stringify(options));

exports.orderConfirm=function(order,callback){
    emailTemplates(options, function(err, render) { Line 42
        render('email/order-confirm.html', order, function(err, html) {
            callback(html);
        });
    });
};

Following Error Happening : -

------------------------------------------options{"root":"/app/templates"}  precise as per the Folder structure ..

TypeError: Cannot set property 'useTemplate' of undefined 
  at EmailTemplates (/app/node_modules/swig-email-templates/index.js:32:20)
at Object.exports.orderConfirm(/app/app/controllers/emailTemplates.server.controller.js:42:5)  

Could You Guys Suggest i am stuck with out clue :-(

Thanks,
Prasad

document.parentWindow.close() throws error

If i try to use the this module to compile Templates i get this error:

TypeError: Object object has no method 'close'
at F:\Projekte\git-dash\node_modules\swig-email-templates\index.js:53:37
at inlineDocumentWithCb (F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\lib\juice.js:205:5)
at F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\lib\juice.js:129:5
at F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\lib\juice.js:285:5
at F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\node_modules\batch\lib\batch.js:85:20
at getStylesData (F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\lib\juice.js:226:3)
at F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\lib\juice.js:272:35
at F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\node_modules\batch\lib\batch.js:65:5
at Array.forEach (native)
at Batch.end (F:\Projekte\git-dash\node_modules\swig-email-templates\node_modules\juice\node_modules\batch\lib\batch.js:63:12)

If i replace L44 - 55 of the index.js

            if (err) {
              // free the associated memory
              // with lazily created parentWindow
              try {
                document.parentWindow.close();
              } catch (cleanupErr) {}
              cb(err);
            } else {
              var inner = document.innerHTML;
              document.parentWindow.close();
              cb(null, inner);
            }

with

            if (err) {
              // free the associated memory
              // with lazily created parentWindow
              try {
                document.close();
              } catch (cleanupErr) {}
              cb(err);
            } else {
              var inner = document.innerHTML;
              document.close();
              cb(null, inner);
            }

It works

Custom filter using swig email templates

Hey there,

I'm using swig-email-templates, but find myself needing to create a custom filter after using it for a few months.

The Swig documentation says that I need to specify the filter name in swig.init(), but I'm not quite sure where to do that since I'm not instantiating Swig directly.

Any idea where I would do that?

Thanks!

Should this work with nodemailer's embedded images using the 'cid' parameter?

emailHelper.templates.render('email_test.html', context, function (err, html, text) {
emailHelper.transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Testmail',
html: html,
//text: text
attachments: [{
filename: 'logo.jpg',
path: '../../public/img',
cid: 'logouniquecid' //same cid value as in the html img src
}]
});
});

Settings:
var templates = new EmailTemplates({
root: global.appRoot + '/server/templates',
text: false, // Disable text alternatives
swig: {
cache: false // Don't cache swig templates
}
});

In email_test.html

<img class="img-responsive" src="cid:logouniquecid"/>

The cid value is the same as should be... however, I always get the rendered mail with inline CSS and the image, but I always get the following error:

Not found, skipping: cid:logouniquecid

Fix for Node version >= 4.x

Please could you provide the fix for the newest version of node.js >= 4.x?
I can't neither install it, there are so many errors trying to compile the dependencies, fell free to contact me if you need info.
Many thanks

Issue with cheerio encoding apostrophes

Cheerio has a known issue with decoding then re-encoding apostrophes as &apos; which is not a valid HTML4 character entity. See cheeriojs/cheerio#319. Generally most browsers are pretty flexible… except for several versions of Outlook.

In the render function, using cheerio.load(html, {decodeEntities: false}); would resolve this. Since Swig should already be returning valid HTML, no need to have cheerio altering character entities along the way.

installed on OSX mavericks using zsh and can't seem to get it to work - it's definitely not in my $PATH

Even this is crapping out and yes, there is a welcome.html in /templates:

› node_modules/swig-email-templates/bin/swig-email-templates.js render welcome.html

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory 'welcome.html'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.readFileSync (fs.js:284:15)
    at /Users/Dan/Code/node-html-emails/node_modules/swig-email-templates/bin/swig-email-templates.js:112:16
    at Array.forEach (native)
    at Object.<anonymous> (/Users/Dan/Code/node-html-emails/node_modules/swig-email-templates/bin/swig-email-templates.js:111:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

Why swig 0.14??

I mean, now we have swig 1.2.2, could you please consider to upgrade it??

Thanks, your library rocks!

Memory leak causes crashing on large batches of templates

I have created a cron script that emails several thousand users using the same template, but different data. When I run the script, a segmentation fault occurs halfway through and the script crashes.

Here is part of the error message:

#
# Fatal error in ../deps/v8/src/api.h, line 297
# CHECK(allow_empty_handle || that != __null) failed
#


==== Stack trace ============================================

Security context: 0x34aea2057281 <JS Object>#0#
    1: getListeners [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/events.js:168] (this=0x2ea0453fa709 <JS Function>#1#,target=0x19ae9ca5f41 <JS Global Object>#2#,type=0x376abc6ad5f1 <String[16]: DOMContentLoaded>,capturing=0x34aea2004161 <true>)
    2: dispatch [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/events.js:191] (this=0x2ea0453fa709 <JS Function>#1#,event=0x22209cfe0b91 <JS Object>#3#,iterator=0x22209cfe0cf1 <JS Function iterator>#4#,capturing=0x34aea2004161 <true>)
    3: dispatchEvent [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/events.js:282] (this=0x22209cf04101 <an HTMLDocument>#5#,event=0x22209cfe0b91 <JS Object>#3#)
    4: /* anonymous */ [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/html.js:460] (this=0x22209cf04101 <an HTMLDocument>#5#)
    5: arguments adaptor frame: 2->0
    6: /* anonymous */ [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/html.js:76] (this=0x34aea20573a1 <JS Global Object>#6#,err=0x34aea2004101 <null>,data=0x34aea2004161 <true>)
    7: check [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/html.js:345] (this=0x22209cf04471 <an Object>#7#)
    8: /* anonymous */ [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/html.js:363] (this=0x34aea20573a1 <JS Global Object>#6#,err=0x34aea2004101 <null>,data=0x34aea2004161 <true>)
    9: close [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/jsdom/lib/jsdom/level2/html.js:~452] (this=0x22209cf04101 <an HTMLDocument>#5#)
   10: tryCleanup [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/index.js:48] (this=0x34aea20573a1 <JS Global Object>#6#)
   11: /* anonymous */ [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/index.js:40] (this=0x34aea20573a1 <JS Global Object>#6#,err=0x34aea2004121 <undefined>)
   12: arguments adaptor frame: 0->1
   13: inlineDocumentWithCb [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/juice2/lib/juice.js:227] (this=0x34aea20573a1 <JS Global Object>#6#,document=0x22209cf04101 <an HTMLDocument>#5#,css=0x22209cf045d1 <Very long string[3319]>#8#,callback=0x22209cf04589 <JS Function>#9#)
   14: /* anonymous */ [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/juice2/lib/juice.js:144] (this=0x34aea20573a1 <JS Global Object>#6#,err=0x34aea2004101 <null>,css=0x22209cf045d1 <Very long string[3319]>#8#)
   15: /* anonymous */ [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/juice2/lib/juice.js:308] (this=0x34aea20573a1 <JS Global Object>#6#,err=0x34aea2004101 <null>,results=0x22209cf06101 <JS Array[1]>#10#)
   16: callback [/Users/andrew/Documents/code/linear-calendar/node_modules/swig-email-templates/node_modules/juice2/node_modules/batch/index.js:147] (this=0x34aea20573a1 <JS Global Object>#6#,err=0x34aea2004101 <null>,res=0x22209cf05371 <Very long string[3318]>#11#)
   17: /* anonymous */ [fs.js:266] (this=0x34aea20573a1 <JS Global Object>#6#,er=0x34aea2004101 <null>)
   19: oncomplete [fs.js:107] (this=0x22209cf06391 <an Object>#12#)
   20: arguments adaptor frame: 1->0

...

It looks like JSDOM is the module running out of memory. Is there any way for the swig-email-templates module to prevent JSDOM from hogging all the resources on big batch scripts like this?

Is it supposed to work with gettext?

My email template contains gettext from i18n-abide module but I cannot get it working. The result string disappears in the translated email. (of course same string works in a template web view, not email)

Template ha strings like this:

<p><%= gettext('Welcome to') %></p>

Error: ENOENT: no such file or directory, open on up-gradation to latest version

Hi,

I updated recently to new version "swig-email-templates": "5.0.1" and followed the code as per docs

Code to render html :-

var  emailTemplates = require('swig-email-templates'),
var templates = new emailTemplates();
var options = {
    root: path.join(__dirname, '../../templates') // need to add one more ../ to get precise path in project 
                                                                           screen shot added 
 };

 templates.render(options.root+'/email/mailchimp-order-confirm.html', order, function (err, html) {
        console.log('-------------** html ** ---------'+html);
        console.log('-------------------'+err);
        callback(html);
    });

 **Result error :-** 
** As per my Project structure the path which is saying not found is  Not True Pls take a look at the screen shot 

'-------------** html ** --------- undefined 
 -------------------Error: ENOENT: no such file or directory, open '/app/templates/email/mailchimp-order-confirm-interactive.html' 

Please Suggest !!

Thanks,
Prasad .

error related screen

Is there any problem caching the render function?

Just curious on usage --

This:

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

var options = {
  root: path.join(__dirname, "templates"),
  // any other swig options allowed here
};

exports.render = function (template, context, cb) {
  emailTemplates(options, function (err, render) {
    render(template, context, cb);
  });
};

Vs. this:

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

var options = {
  root: path.join(__dirname, "templates"),
  // any other swig options allowed here
};

emailTemplates(options, function (err, render) {
  render = render;
}

exports.render = function (template, context, cb) {
    render(template, context, cb);
};

Performance issue rendering templates

Hey there again!

I found a big difference in performance when rendering templates when used within swig-email-templates vs. using swig directly.

I only discovered this when building the newsletter part of our app which needs to generate html email for a large number of users.

The process to generate only 30 newsletters would take 5 minutes with swig-email-templates. It would eventually complete, but the node process would consume 100% CPU and block everything else during this time.

When I switched to using swig directly rendering for 30 newsletters would happen in a second or two.

Happy to help you debug this if you'd like.

Raj

Styles aren't being inlined

I realize that this module relies on Juice to handle the inlining, but I figured there may be something about the implementation causing my troubles.

I should also note that this problem exists both when using the CLI and when using a script, and whether I write the output to my local FS or simply view it as stdout.

Everything seems to be working properly EXCEPT for inlining:

  • Template inheritance works fine
  • Generating dummy contexts works
  • Including a context works

The style and link elements in my rendered templates are being stripped (as they should), but those stripped styles are never applied inline to the style attributes on my elements.

It doesn't matter whether I use very broad selectors, e.g.:

* {
  background-color: #ff0000;
}

html {
  font-family: Arial;
}

Or very specific selectors, e.g.:

#wrapperTable {
color: #333;
}

One last thing I'll mention is that the problem persisted whether I had this module installed globally or just locally to my project.

I'm running Windows 7 and haven't yet tried this module on my Ubuntu box - I hope to get to that within the next day.

In the meantime, any guidance or advice would be greatly appreciated.

SyntaxError: Invalid regular expression: missing / in file [.../report.html].

I've set a proof of concept project, which properly renders HTML and sends an email, which it does,

Then I attempted to use the Handlebars {{#each objects}} directive in the template, and now I'm getting the following:

SyntaxError: Invalid regular expression: missing / in file [.../report.html].

where ... [.../report.html] is the raw html template.

I'm putting handlebar variables in it which renders non-repeated variables just fine, I'm trying to allow it to use an array and repeat a section of the email.

var EmailTemplates = require('swig-email-templates'),
    nodemailer = require('nodemailer'),
    handlebars = require('express-handlebars'),
    hbs = require('nodemailer-express-handlebars');

var transporter = nodemailer.createTransport('smtp://smtp.advantix.local');
var viewEngine = handlebars.create({});
transporter.use('compile', hbs({
    viewEngine: viewEngine,
    viewPath: path.resolve(__dirname, 'templates/views'),
    extName: '.hb'
}));
var templates = new EmailTemplates({
    root: path.join(__dirname, 'templates/src'),
    juice: {
        webResources: {
            images: 9      // Inline images under 8kB
        }
    }
});
var context = {
    coverImage: 'http://i.istockimg.com/file_thumbview_approve/64115753/6/stock-illustration-64115753-hands-holding-smartphone-vector-.jpg',
    coverBackground: '#4091BE',
    devices: [
        { phoneNumber: '(555) 555.5555', type: 'iPhone', price: '$909.09', chartPath: '' },
        { phoneNumber: '(333) 333.3333', type: 'Monitor Phone', price: '$33.33', chartPath: '' }
    ]
};
templates.render('./report.html', context, function(err, html, text) {
    if (err) {
        console.log(err);
    } else {
        // Send email
        transporter.sendMail({
            from: '[email protected]',
            to: '[email protected]',
            subject: 'Mobility Report',
            html: html,
            text: text
        });
    }
});

Any idea where I'm going wrong?

Vulnerability CVE-2020-7598 is introduced by package minimist

Hi, a vulnerability CVE-2020-7598 is introduced in [email protected]:
[email protected][email protected][email protected]

However, optimist is a legacy package, which has not been maintained for about 8 years.
Is it possible to migrate optimist to other package to remediate this vulnerability?

I noticed several migration records in other js repo for optimist:

  1. in handlebars, version 4.7.3-->4.7.4, migrate optimist to yargs via commit
  2. in db-migrate, version 1.0.0-beta.2-->1.0.0-beta.3, migrate optimist to yargs via commit
  3. in http-server, version 0.12.1-->0.12.2, deprecated optimist and directly use minimist via commit

Thanks.

Remove html extension

A lot of people don't use 'html' for template extensions - I use 'swig' myself. Wouldn't it make more sense to not have the extension forced on? Swig itself doesn't.

Thanks

Dependency update - Minimist

I was thrilled to see the dependency updates that yielded the 6.0.0 release, as it made libe much more convenient, but one dependency was missed - that being Minimist which is at 1.2.5 as of 10 months ago. I wonder if we could see a 6.0.1 release with that dependency change,so we don't have to do obnoxious things to package-lock files to get swig-email-templates to play nice. Thanks.

Problem running on windows platform

We are working with swig this week (it's a nice module) and testing on Windows and Mac. On Mac it works fine, but on Windows there's an error with file path resolution both when running at the command line or in app code.

When I traced out the issue, I found that changing line 31 of swig-email-templates/index.js so the "file://" is causing issues and removing it seems to clean up the error.

var fileUrl = path.resolve(process.cwd(), path.join(options.root, templateName));

I also realized that there is a command line error where the default folder for "templates" was not being applied when performing a readFileSync command in line 112 of swig-email-template.js

It should be:
var str = fs.readFileSync(argv.r + "" + file, 'utf8');

also need to strip out CRLF from argv which gets thrown in with a windows command line.

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.