Comments (12)
@nathanbowser how might you suggest we rewrite it?
from email-templates.
@nathanbowser rather, could you write in markdown some JavaScript as to how you would like to be able to use emailTemplates
? e.g. write a simple Readme example of your idea here
from email-templates.
+1, I'm hitting the max number of files open on my mac when I load test my app. I'm going to try looking into it.
from email-templates.
@niftylettuce Sorry, I'm no longer using this module.
from email-templates.
@nathanbowser what alternative are you using (if any)?
from email-templates.
I switched over to mandrill, which has an api that allows you to define templates, and then pass them your model.
from email-templates.
I do believe consolidate has a template cache, will look into it to close this issue.
from email-templates.
what about
var emailTemplates = require('email-templates');
var template = emailTemplates(templatesDir);
template('my_fancy-email', locals, function(err, html, text) {
})
that would allow to do this:
var emailTemplates = require('email-templates');
var template = emailTemplates(templatesDir);
module.exports = function(locals, done) {
template('my_fancy-email', locals, done)
});
The parsing can be done once and exporting the thing is much easier.
Or even parse only the template that is requested to be rendered.
from email-templates.
One can use promises, but thats a lot of boiler plate.
Maybe lib should utilize promises.
'use strict';
var path = require('path');
var templatesDir = path.join(__dirname, 'templates');
var emailTemplates = require('email-templates');
var api = {};
var parsedTemplates;
function init() {
if (parsedTemplates) {
return Promise.resolve(parsedTemplates);
}
return new Promise(function(resolve, reject) {
emailTemplates(templatesDir, function(err, template) {
if (err) {
return reject(err);
}
parsedTemplates = template;
resolve(template);
});
});
}
api.confirm = function(locals) {
return init().then(function(template) {
return new Promise(function(reject, resolve) {
template('confirm', locals, function(err, html, text) {
if (err) {
return reject(err);
}
resolve({
html: html,
text: text
});
});
});
}).then(console.log.bind(console));
};
module.exports = api;
from email-templates.
just created a module for that
from email-templates.
I do believe consolidate has a template cache, will look into it to close this issue.
@jeduan consolidate does have caching, https://github.com/tj/consolidate.js#caching
When passing in the locals object you should be able to add { cache: true, other: 'local variables' }
to the locals object to instruct consolidate to cache the template. The consolidate cache does depend on your choice of engine supporting caching.
I'm testing this out right now, assuming it works a simple change to the README should suffice.
from email-templates.
Ok, so v2 is the work of thinking about this. Please check out the branch https://github.com/niftylettuce/node-email-templates/tree/v2.0
The API is now fully Promise-based @StephanHoyer
I'll be closing this. Please reopen if you have any more thoughts.
from email-templates.
Related Issues (20)
- Verbose console output HOT 1
- Update html-to-text HOT 1
- [fix] "Cannot find name 'HTMLElement')." Underlying package Juice is abandoned HOT 5
- Double quote on subject HOT 1
- Is there any date/number/currency formatting tools with i18n? HOT 1
- [fix] Syntax error when imported HOT 2
- [fix] Unable to send dynamic template from DB HOT 1
- [fix] Unable to use plugin HOT 2
- [fix] Pug block extends doesn't work HOT 1
- [fix] i18n - auto translate HOT 1
- [feat] extract locale phrases AOT HOT 3
- [fix] The juice step does not seem to be working HOT 1
- [feat] - AWS s3 as a source for template files HOT 2
- Critical and high severity vulnerabilities HOT 1
- [fix] CC emails not working if we specify mutiple emails instead of single HOT 6
- [fix] CC emails not working if we specify mutiple emails instead of single email HOT 2
- [fix] Move preview-email to devDeps
- [fix] DESCRIPTIVE TITLE HOT 1
- [fix] Peer dependency needs a bump @loadjs/consolidate HOT 1
- Getting monorepo-symlink-test Security Vulnerability warning due to resolve package of email-templates
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from email-templates.