<commit_before>/**
 * We.js email Class constructor
 */

var emailTemplates = require('email-templates');
var themeEngine = require('../themeEngine');
var fs = require('fs');

function EmailTemplate(defaultPath, templateName) {
  this.templatePath = defaultPath;
  this.templateName = templateName;
}

EmailTemplate.prototype.templatePath = '';
EmailTemplate.prototype.templateName = '';

/**
 * Email template folder cache
 * @type {String}
 */
EmailTemplate.prototype.resolvedTemplateFolder = '';

EmailTemplate.prototype.render = function render(templateVariables, cb) {
  var self = this;
  this.getTemplateFolder(function (err, templateFolder) {
    if (err) return cb(err, null);

    emailTemplates( templateFolder, function (err, template) {
      if (err) return cb(err, null);

     // render the template
      template( self.templateName, templateVariables, cb);
    });
  })
}

/**
 * Check if email template exists in theme email folder and  if exists override default email template
 *
 * @param  {Function}
 */
EmailTemplate.prototype.getTemplateFolder = function getTemplateFolder(cb) {
  if (this.resolvedTemplateFolder) return cb(null, this.resolvedTemplateFolder); // cache

  var self = this;

  var themeEmailTemplateFolder = themeEngine.themes.app.config.themeFolder + '/' +
    themeEngine.themes.app.config.emailTemplates.path;

  fs.readdir(themeEmailTemplateFolder + '/' + this.templateName, function(err, result) {
    if (err) {
      if (err.code != 'ENOENT') {
        return cb(err);
      }
    }

    if (result && result.length) {
      self.resolvedTemplateFolder = themeEmailTemplateFolder
    } else {
      self.resolvedTemplateFolder = self.defaultPath;
    }

    return cb(null, self.resolvedTemplateFolder);
  });
}

module.exports = EmailTemplate;<commit_msg>fix default template folder<commit_after>/**
 * We.js email Class constructor
 */

var emailTemplates = require('email-templates');
var themeEngine = require('../themeEngine');
var fs = require('fs');

function EmailTemplate(defaultPath, templateName) {
  this.templatePath = defaultPath;
  this.templateName = templateName;
}

EmailTemplate.prototype.templatePath = '';
EmailTemplate.prototype.templateName = '';

/**
 * Email template folder cache
 * @type {String}
 */
EmailTemplate.prototype.resolvedTemplateFolder = '';

EmailTemplate.prototype.render = function render(templateVariables, cb) {
  var self = this;
  this.getTemplateFolder(function (err, templateFolder) {
    if (err) return cb(err, null);

    console.log('>>>', templateFolder)

    emailTemplates( templateFolder, function (err, template) {
      if (err) return cb(err, null);

     // render the template
      template( self.templateName, templateVariables, cb);
    });
  })
}

/**
 * Check if email template exists in theme email folder and  if exists override default email template
 *
 * @param  {Function}
 */
EmailTemplate.prototype.getTemplateFolder = function getTemplateFolder(cb) {
  if (this.resolvedTemplateFolder) return cb(null, this.resolvedTemplateFolder); // cache

  var self = this;

  var themeEmailTemplateFolder = themeEngine.themes.app.config.themeFolder + '/' +
    themeEngine.themes.app.config.emailTemplates.path;

  fs.readdir(themeEmailTemplateFolder + '/' + this.templateName, function(err, result) {
    if (err) {
      if (err.code != 'ENOENT') {
        return cb(err);
      }
    }

    if (result && result.length) {
      self.resolvedTemplateFolder = themeEmailTemplateFolder
    } else {
      self.resolvedTemplateFolder = self.templatePath;
    }

    return cb(null, self.resolvedTemplateFolder);
  });
}

module.exports = EmailTemplate;
{'fraction_non_alphanumeric': 0.1220977874897569, 'fraction_numerical': 0.0, 'mean_word_length': 3.9486486486486485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2729990', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1013, 'n_words': 244}