Code coverage report for juice\index.js

Statements: 95.74% (45 / 47)      Branches: 75% (9 / 12)      Functions: 100% (5 / 5)      Lines: 95.74% (45 / 47)      Ignored: none     

All files » juice\ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77            1 1 1 1 1 1 1   1   1   1 1 1   1 1 1 1 1   1 1 1   1 1 1   1   5 5     5 5 5 5   5       1 21 21     1 21   21 21       21 21   21 1   20     21 21    
 'use strict';
 
/**
 * Module dependencies.
 */
 
var utils = require('./lib/utils');
var packageJson = require('./package');
var fs = require('fs');
var path = require('path');
var inline = require('web-resource-inliner');
var juiceClient = require('./client');
var juice = juiceClient;
 
module.exports = juice;
 
juice.version = packageJson.version;
 
juice.Selector = utils.Selector;
juice.Property = utils.Property;
juice.utils = utils;
 
juice.ignoredPseudos = juiceClient.ignoredPseudos;
juice.widthElements = juiceClient.widthElements;
juice.tableElements = juiceClient.tableElements;
juice.nonVisualElements = juiceClient.nonVisualElements;
juice.styleToAttribute = juiceClient.styleToAttribute;
 
juice.juiceDocument = juiceClient.juiceDocument;
juice.inlineDocument = juiceClient.inlineDocument;
juice.inlineContent = juiceClient.inlineContent;
 
juice.juiceFile = juiceFile;
juice.juiceResources = juiceResources;
juice.inlineExternal = inlineExternal;
 
function juiceFile(filePath, options, callback) {
  // set default options
  fs.readFile(filePath, 'utf8', function(err, content) {
    Iif (err) {
      return callback(err);
    }
    options = utils.getDefaultOptions(options); // so we can mutate options without guilt
    Eif (!options.webResources.relativeTo) {
      var rel = path.dirname(path.relative(process.cwd(),filePath));
      options.webResources.relativeTo = rel;
    }
    juiceResources(content, options, callback);
  });
}
 
function inlineExternal(html, inlineOptions, callback) {
  var options = utils.extend({fileContent: html}, inlineOptions);
  inline.html(options, callback);
};
 
function juiceResources(html, options, callback) {
  options = utils.getDefaultOptions(options);
 
  var onInline = function(err, html) {
    Iif (err) {
      return callback(err);
    }
 
    var $ = utils.cheerio(html, { xmlMode: options && options.xmlMode});
    juiceClient.juiceDocument($, options);
 
    if (options.xmlMode) {
      return callback(null, $.xml());
    }
    return callback(null, utils.decodeEntities($.html()));
  };
 
  options.webResources.relativeTo = options.webResources.relativeTo || options.url; // legacy support
  inlineExternal(html, options.webResources, onInline);
}