How to use the juice function in juice

To help you get started, we’ve selected a few juice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opencollective / opencollective-api / server / lib / email.js View on Github external
const render = (template, data) => {
  let text;
  data.imageNotSvg = data.collective && data.collective.image && !data.collective.image.endsWith('.svg');
  data = merge({}, data);
  delete data.config;
  data.config = { host: config.host };

  // sets paypalEmail for purpose of email templates
  if (data.user) {
    data.user.paypalEmail = data.user.paypalEmail || data.user.email;
  }

  if (templates[`${template}.text`]) {
    text = templates[`${template}.text`](data);
  }
  const html = juice(he.decode(templates[template](data)));

  // When in development mode, we log the data used to compile the template
  // (useful to get login token without sending an email)
  debugLib('data')(`Rendering ${template} with data`, data);

  return { text, html };
};
github OpenNeuroOrg / openneuro / packages / openneuro-server / libs / email / index.js View on Github external
send(email, callback) {
    // template data
    let html = templates[email.template](email.data)

    // inline styles
    html = juice(html)

    // determine if the main is from a specific sender
    // or the generic email address
    let user = (email && email.from) ? email.from : config.notifications.email.user
    let from = user + '@' + config.notifications.email.url
    
    // configure mail options
    var mailOptions = {
      from: from,
      to: email.to,
      subject: email.subject,
      html: html,
    }

    // send email
    transporter.sendMail(mailOptions, callback)
github OpenNeuroOrg / openneuro / server / libs / email / index.js View on Github external
send(email, callback) {
    // template data
    let html = templates[email.template](email.data)

    // inline styles
    html = juice(html)

    // configure mail options
    var mailOptions = {
      from: config.notifications.email.user,
      to: email.to,
      subject: email.subject,
      html: html,
    }

    // send email
    transporter.sendMail(mailOptions, callback)
  },
}
github erxes / erxes / src / modules / inbox / components / conversationDetail / workarea / mail / Mail.tsx View on Github external
renderBody(mailData) {
    const { isCollapsed } = this.state;

    if (isCollapsed) {
      return null;
    }

    // all style inlined
    const mailContent = juice(mailData.body || '');

    const innerHTML = { __html: this.cleanHtml(mailContent) };

    return (
      <>
        <content>
        {this.renderReplyButton()}
        {this.renderAttachments(mailData)}
      
    );
  }
</content>
github cleverbeagle / pup / modules / server / handlebarsEmailToHtml.js View on Github external
export default (handlebarsMarkup, context, options) =&gt; {
  if (handlebarsMarkup &amp;&amp; context) {
    const template = handlebars.compile(handlebarsMarkup);
    const content = template(context);
    const {
      productName, twitterUsername, facebookUsername, productAddress,
    } = Meteor.settings.public;

    if (options &amp;&amp; options.noBaseTemplate) {
      // Use juice to inline CSS <style></style> styles from  unless disabled.
      return options &amp;&amp; !options.inlineCss ? content : juice(content);
    }

    const base = handlebars.compile(getPrivateFile('email-templates/base.html'));

    const baseContext = {
      ...context,
      content,
      productName,
      twitterUsername,
      facebookUsername,
      productAddress,
    };

    return options &amp;&amp; !options.inlineCss ? base(baseContext) : juice(base(baseContext));
  }
github erxes / erxes / src / modules / inbox / components / conversationDetail / workarea / mail / Mail.tsx View on Github external
renderDetails(mailData) {
    const [from] = mailData.from || [{}];
    const { body = '' } = mailData;

    return (
      <details>
        <strong>{from.email || ''}</strong>
        {this.renderAddress('To:', mailData.to, juice(body))}
        {this.renderAddress('Cc:', mailData.cc, juice(body))}
        {this.renderAddress('Bcc:', mailData.bcc, juice(body))}
      </details>
    );
  }
github Mailtrain-org / mailtrain / client / src / lib / sandboxed-codeeditor-root.js View on Github external
getHtml() {
        let contents;
        if (this.props.sourceType === CodeEditorSourceType.MJML) {
            try {
                const res = mjml2html(this.state.source);
                contents = res.html;
            } catch (err) {
                contents = '';
            }
        } else if (this.props.sourceType === CodeEditorSourceType.HTML) {
            contents = juice(this.state.source);
        }

        return contents;
    }
github MoonMail / MoonMail / api / lib / services / deliver_campaign_service.js View on Github external
return new Promise((resolve) => {
      const inlinedBody = juice(campaign.body);
      resolve(omitEmpty({
        userId: campaign.userId,
        userPlan: this.userPlan,
        appendFooter: this.appendFooter,
        currentUserState: this.currentState,
        campaign: {
          id: campaign.id,
          subject: campaign.subject,
          name: campaign.name,
          body: inlinedBody,
          senderId: campaign.senderId,
          precompiled: false,
          listIds: campaign.listIds,
          segmentId: campaign.segmentId,
          attachments: campaign.attachments,
          metadata: campaignMetadata,
github freeCodeCamp / pantry-for-good / server / lib / mail / mail-generator.js View on Github external
export default async function generate(identifier, bindings) {
  const page = await Page.findOne({identifier}).lean()
  if (!page || page.disabled) return

  let attachments = []
  const body = transformBody(page.body, bindings, attachments)
  const subject = transformSubject(page.subject, bindings)
  const text = transformText(body)
  const html = template.replace(/\{content\}/, body)
    .replace(/\{subject\}/g, subject)

  return {
    html: juice(html),
    text,
    subject,
    attachments: uniq(attachments)
  }
}