files.forEach(function(f) {
      console.log(f);
      //var filepath = f.src.toString();
      if (typeof f !== 'string' || f === '') {
        grunt.log.error('src must be a single string');
        return false;
      }

      if (!grunt.file.exists(f)) {
        grunt.log.error('Source file "' + f + '" not found.');
        return false;
      }

      juice.juiceFile(f, options, function(err, html) {

        if (err) {
          return grunt.log.error(err);
        }

        grunt.file.write(f, html);
        grunt.log.writeln('File "' + f + '" created.');

        index++;
        if (index === count) {
          done();
        }

      });

    });
 jobs.push(function(callback) {
   juice.juiceFile(filepath, options, function(err, html) {
     if (err) {
       callback(err);
       grunt.warn(err, 3);
     }
     else {
       grunt.file.write(f.dest, html);
       grunt.log.writeln('File "' + f.dest + '" created.');
       callback();
     }
   });
 });
Example #3
0
function sendEmail(options, callback, template) {
  if (process.env.NODE_ENV === 'test') {
    if (options.to.email && options.template) {
      return callback(null, {
        _id: '123',
        status: 'sent'
      });
    } else {
      return callback(new Error('Must have email & template set to send an email.'));
    }
  }

  if (!template) {
    if (templates[options.template]) {
      return sendEmail(options, callback, templates[options.template]);
    } else {
      return juice.juiceFile(__dirname + '/../assets/email/' + options.template + '.html', {},
        function(err, data) {
          if (err) {
            return callback(err);
          } else {
            templates[options.template] = hogan.compile(data);
            return sendEmail(options, callback, templates[options.template]);
          }
        }
      );
    }
  }

  client.messages.send({
    message: {
      html: template.render(options),
      subject: options.subject,
      to: [options.to],
      from_email: config.email.address,
      from_name: config.email.name,
      track_opens: true,
      track_clicks: true,
      auto_text: true,
      tags: options.tags || []
    }
  }, function(result) {
    if (result[0].status === 'rejected' || result[0].status === 'invalid') {
      callback(new Error(result[0].reject_reason), result[0]);
    } else {
      callback(null, result[0]);
    }
  }, function(err) {
    callback(err);
  });
}