Code Monkey home page Code Monkey logo

Comments (12)

niftylettuce avatar niftylettuce commented on May 17, 2024

@nathanbowser how might you suggest we rewrite it?

from email-templates.

niftylettuce avatar niftylettuce commented on May 17, 2024

@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.

juanpin avatar juanpin commented on May 17, 2024

+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.

nathanbowser avatar nathanbowser commented on May 17, 2024

@niftylettuce Sorry, I'm no longer using this module.

from email-templates.

niftylettuce avatar niftylettuce commented on May 17, 2024

@nathanbowser what alternative are you using (if any)?

from email-templates.

nathanbowser avatar nathanbowser commented on May 17, 2024

I switched over to mandrill, which has an api that allows you to define templates, and then pass them your model.

from email-templates.

jeduan avatar jeduan commented on May 17, 2024

I do believe consolidate has a template cache, will look into it to close this issue.

from email-templates.

StephanHoyer avatar StephanHoyer commented on May 17, 2024

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.

StephanHoyer avatar StephanHoyer commented on May 17, 2024

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.

StephanHoyer avatar StephanHoyer commented on May 17, 2024

just created a module for that

from email-templates.

clarkbw avatar clarkbw commented on May 17, 2024

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.

jeduan avatar jeduan commented on May 17, 2024

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)

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.