<commit_before>import fs from 'fs';
import moment from 'moment';
import handlebars from 'handlebars';

/*
* Loads all the email templates
*/

const templates = {};

const templateNames = [
  'email.approve',
  'email.message',
  'github.signup',
  'group.created',
  'group.expense.created',
  'group.donation.created',
  'group.monthlyreport',
  'thankyou',
  'thankyou.wwcode',
  'thankyou.brusselstogether',
  'thankyou.ispcwa',
  'thankyou.fr',
  'thankyou.laprimaire',
  'user.forgot.password',
  'user.new.token'
];

const templatesPath = `${__dirname}/../../templates`;

// Register partials
const header = fs.readFileSync(`${templatesPath}/partials/header.hbs`, 'utf8');
const footer = fs.readFileSync(`${templatesPath}/partials/footer.hbs`, 'utf8');
const subscriptions = fs.readFileSync(`${templatesPath}/partials/subscriptions.hbs`, 'utf8');
const toplogo = fs.readFileSync(`${templatesPath}/partials/toplogo.hbs`, 'utf8');
const relatedgroups = fs.readFileSync(`${templatesPath}/partials/relatedgroups.hbs`, 'utf8');

handlebars.registerPartial('header', header);
handlebars.registerPartial('footer', footer);
handlebars.registerPartial('subscriptions', subscriptions);
handlebars.registerPartial('toplogo', toplogo);
handlebars.registerPartial('relatedgroups', relatedgroups);

handlebars.registerHelper('sign', (value) => {
  if (value >= 0) return '+';
  else return '';
});

handlebars.registerHelper('toLowerCase', (str) => {
  return str.toLowerCase();
});

handlebars.registerHelper('moment', (value, props) => {
  if (props && props.hash.format)
    return moment(value).format(props.hash.format);
  else
    return moment(value).format('MMMM Do YYYY');
});

handlebars.registerHelper('currency', (value, props) => {
  const { currency } = props.hash;
  value = value/100; // converting cents

  return value.toLocaleString(currency, {
    style: 'currency',
    currency,
    minimumFractionDigits : 2,
    maximumFractionDigits : 2
  });
<commit_msg>avoid triggering an error when rendering template if no currency (#665)<commit_after>import fs from 'fs';
import moment from 'moment';
import handlebars from 'handlebars';

/*
* Loads all the email templates
*/

const templates = {};

const templateNames = [
  'email.approve',
  'email.message',
  'github.signup',
  'group.created',
  'group.expense.created',
  'group.donation.created',
  'group.monthlyreport',
  'thankyou',
  'thankyou.wwcode',
  'thankyou.brusselstogether',
  'thankyou.ispcwa',
  'thankyou.fr',
  'thankyou.laprimaire',
  'user.forgot.password',
  'user.new.token'
];

const templatesPath = `${__dirname}/../../templates`;

// Register partials
const header = fs.readFileSync(`${templatesPath}/partials/header.hbs`, 'utf8');
const footer = fs.readFileSync(`${templatesPath}/partials/footer.hbs`, 'utf8');
const subscriptions = fs.readFileSync(`${templatesPath}/partials/subscriptions.hbs`, 'utf8');
const toplogo = fs.readFileSync(`${templatesPath}/partials/toplogo.hbs`, 'utf8');
const relatedgroups = fs.readFileSync(`${templatesPath}/partials/relatedgroups.hbs`, 'utf8');

handlebars.registerPartial('header', header);
handlebars.registerPartial('footer', footer);
handlebars.registerPartial('subscriptions', subscriptions);
handlebars.registerPartial('toplogo', toplogo);
handlebars.registerPartial('relatedgroups', relatedgroups);

handlebars.registerHelper('sign', (value) => {
  if (value >= 0) return '+';
  else return '';
});

handlebars.registerHelper('toLowerCase', (str) => {
  return str.toLowerCase();
});

handlebars.registerHelper('moment', (value, props) => {
  if (props && props.hash.format)
    return moment(value).format(props.hash.format);
  else
    return moment(value).format('MMMM Do YYYY');
});

handlebars.registerHelper('currency', (value, props) => {
  const { currency } = props.hash;
  if (!value || !currency || currency.length !== 3) {
    console.error("currency hbs helper called with invalid inputs", "value:", value, "currency:", currency);
    return value || 0;
  }
  value = value/100; // converting cents

  return value.toLocaleString(currency, {
    style: 'currency',
    currency,
    minimumFractionDigits : 2,
    maximumFractionDigits : 2
  });

{'fraction_non_alphanumeric': 0.16650763358778625, 'fraction_numerical': 0.006440839694656489, 'mean_word_length': 5.3147590361445785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5368342', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1320, 'n_words': 259}