How to use juice - 10 common examples

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 ashb / juice / test / validation.t.js View on Github external
exports.test_ValidateFieldMessages = function () {
  Validation.messages.test = {};
  var v = new Validation( undefined, "test" ); // language is "test" for error messages

  // |message| present
  var one_message = {
    validation : [ "trim", "notEmpty", "integer" ],
    message : "one message"
  };
  asserts.throws( function() { v.validateField( one_message, "" ); },
                  "one message",
                  "All errors should throw single message" );
  asserts.throws( function() { v.validateField( one_message, " " ); },
                  "one message",
                  "All errors should throw single message" );
  asserts.throws( function() { v.validateField( one_message, "foo" ); },
                  "one message",
                  "All errors should throw single message" );
github ashb / juice / test / validation.t.js View on Github external
// neither |message| nor |messages| present
  var no_messages = {
    validation : [ "trim", "notEmpty", "integer" ]
  };
  asserts.throws( function() { v.validateField( no_messages, "" ); },
                  "notEmpty",
                  "notEmpty should throw its name" );
  asserts.throws( function() { v.validateField( no_messages, " " ); },
                  "notEmpty",
                  "notEmpty should throw its name" );
  asserts.throws( function() { v.validateField( no_messages, "foo" ); },
                  "integer",
                  "integer should throw its name" );

  // default messages
  Validation.messages.test = {
    "notEmpty" : "default for notEmpty",
    "integer" : "default for integer"
  };
  asserts.throws( function() { v.validateField( no_messages, "" ); },
                  "default for notEmpty",
                  "notEmpty should throw it's default message" );
  asserts.throws( function() { v.validateField( no_messages, " " ); },
                  "default for notEmpty",
                  "notEmpty should throw it's default message" );
  asserts.throws( function() { v.validateField( no_messages, "foo" ); },
                  "default for integer",
                  "integer should throw it's default message" );
}
github ashb / juice / test / validation.t.js View on Github external
exports.test_ValidateFieldMessages = function () {
  Validation.messages.test = {};
  var v = new Validation( undefined, "test" ); // language is "test" for error messages

  // |message| present
  var one_message = {
    validation : [ "trim", "notEmpty", "integer" ],
    message : "one message"
  };
  asserts.throws( function() { v.validateField( one_message, "" ); },
                  "one message",
                  "All errors should throw single message" );
  asserts.throws( function() { v.validateField( one_message, " " ); },
                  "one message",
                  "All errors should throw single message" );
  asserts.throws( function() { v.validateField( one_message, "foo" ); },
                  "one message",
                  "All errors should throw single message" );
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 flutter-view / flutter-view / src / watcher.ts View on Github external
const sassFile = `${p.dir}/${p.name}.sass`
		const cssFile = `${p.dir}/${p.name}.css`
		if(fs.existsSync(sassFile)) {
			const cssResult = renderSync({
				file: sassFile,
				includePaths: [process.cwd()+'/lib'],
				outputStyle: 'expanded',
				indentedSyntax: true
			})
			css = cssResult.css.toLocaleString()
		} else if(fs.existsSync(cssFile)) {
			css = fs.readFileSync(cssFile).toString()
		}
		if(css) {
			// merge the css styles into the html
			const mergedHtml = juice.inlineContent(html, css, {
				xmlMode: false,
				webResources: {
					relativeTo: process.cwd()+'/lib'
				}
			})
			return await parse(mergedHtml)
		} else {
			return await parse(html)
		}

		async function parse(htm: string): Promise{
			return await new Promise(function(resolve, reject) {
				const handler = new htmlparser.DefaultHandler(function (error, dom) {
					if (error) reject(error)
					else resolve(dom)
				}, { verbose: false, ignoreWhitespace: true })
github connectivedx / fuzzy-chainsaw / packages / fuzzy-chainsaw-toc / build / compile.js View on Github external
.then((res) => {
    // inject css into raw template
    const inlinedTemplate = juice.inlineContent(template, res.css);

    // compile raw template into function
    const compiledTemplate = dot.template(inlinedTemplate);

    // create dist folder if it doesn't exist
    mkdirp.sync(dest());

    // replace config(varName) in template string
    const configurableTemplate = replaceCssVariables(compiledTemplate.toString());

    // add common js export so we can require it
    const output = `module.exports = ${configurableTemplate}`;

    // save to file
    fs.writeFileSync(dest('template.js'), output);
  })