How to use the juice.juiceResources 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 d-band / html2xlsx / src / index.js View on Github external
module.exports = (html, callback, options = {}) => {
  juice.juiceResources(html, options.juice || {}, (err, text) => {
    if (err) return callback(err);

    const file = new xlsx.File();
    const $ = cheerio.load(text);

    $('table').each((ti, table) => {
      const name = $(table).attr('name') || `Sheet${ti + 1}`;
      const sheet = file.addSheet(name);
      const maxW = [];
      const offsets = [];
      $('tr', table).each((hi, th) => {
        if (offsets[hi] === undefined) {
          offsets[hi] = 0;
        }
        let maxH = 20; // pt
        $('th, td', th).each((di, td) => {
github andrewrk / swig-email-templates / index.js View on Github external
context = context || {};

    try {
      var html = self.useTemplate(templatePath, context);
      var $ = cheerio.load(html, { decodeEntities: false });
      if (options.rewriteUrl)
        self.rewriteUrls($, options.rewriteUrl);
      if (options.rewrite)
        options.rewrite($);
    } catch (err) {
      return cb(err);
    }

    // Inline resources
    juice.juiceResources($.html(), options.juice, function(err, inlinedHTML) {
      if (err) return cb(err);

      self.generateText(templatePath, context, html, function(err, text) {
        if (err) return cb(err);

        self.generateSubject(templatePath, context, function(err, subject) {
          if (err) return cb(err);

          cb(null, inlinedHTML, text, subject);
        });
      });
    });
  }
}
github forwardemail / email-templates / src / index.js View on Github external
return new Promise((resolve, reject) => {
    juice.juiceResources(html, options, (err, html) => {
      if (err) return reject(err);
      resolve(html);
    });
  });
};
github Wikia / app / extensions / wikia / Email / scripts / Gruntfile.js View on Github external
grunt.file.recurse(src, function (absPath, rootDir, subDir, fileName) {
			var html = grunt.file.read(absPath);

			juice.juiceResources(html, {
					webResources: {
						relativeTo: src
					}
				},
				function (err, html) {
					var dest = rootDir + '/../compiled/' + fileName;
					grunt.file.write(dest, html);
				});
		});
	});
github SamyPesse / tpl-emails / lib / index.js View on Github external
that.renderTemplate(templateName, options.context, function(err, html) {
        if (err) return cb(err);

        var $ = cheerio.load(html);
        var fileUrl = path.resolve(that.options.root, templateName);

        if (options.urlRewrite) that.rewriteUrls($, options.urlRewrite);

        options.url = fileUrl;
        options.juice = options.juice || {};
        options.juice.webResources = options.juice.webResources || {};
        options.juice.webResources.relativeTo = options.juice.webResources.relativeTo || path.dirname(path.relative(process.cwd(), fileUrl));

        juice.juiceResources($.html(), options.juice, function(err, htmlInlined) {
            if (err) return cb(err);

            that.generateText(options, options.context, htmlInlined, function(err, text) {
                if (err) return cb(err);

                cb(null, htmlInlined, text);
            });
        });
    });
}
github coralproject / talk / src / core / server / queue / tasks / mailer / processor.ts View on Github external
return new Promise((resolve, reject) => {
    juiceResources(
      input,
      { webResources: { relativeTo: __dirname } },
      (err, html) => {
        if (err) {
          return reject(err);
        }

        return resolve(
          minify(html, {
            removeComments: true,
            collapseWhitespace: true,
          })
        );
      }
    );
  });