Skip to content

Commit

Permalink
Merge pull request #138 from jrit/cheerio-node-12
Browse files Browse the repository at this point in the history
fix undefined options
  • Loading branch information
jrit committed Jul 3, 2015
2 parents e318777 + 895bdbd commit 051449d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/juice.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function inlineDocument($, css, options) {
function addProps (style, selector) {
for (var i = 0, l = style.length; i < l; i++) {
var name = style[i];
var value = style[name] + (options.preserveImportant && style._importants[name] ? ' !important' : '');
var value = style[name] + (options && options.preserveImportant && style._importants[name] ? ' !important' : '');
var sel = style._importants[name] ? importantSelector : selector;
var prop = new Property(name, value, sel);
var existing = el.styleProps[name];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "juice",
"version": "1.3.1",
"version": "1.3.2",
"description": "Inlines css into html source",
"bin": "./bin/juice",
"main": "./lib/juice",
Expand Down
25 changes: 13 additions & 12 deletions test/juice.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";

/*!
* Juice unit tests.
Expand All @@ -7,11 +8,11 @@
* Test dependencies.
*/

var juice = require('../')
, Selector = juice.Selector
, Property = juice.Property
, utils = juice.utils
, assert = require('assert');
var juice = require('../');
var Selector = juice.Selector;
var Property = juice.Property;
var utils = juice.utils;
var assert = require('assert');

/**
* Tests.
Expand Down Expand Up @@ -54,7 +55,7 @@ it('selector specificity comparison', function () {
it('selector specificity calculator', function () {
function spec (selector) {
return new Selector(selector).specificity();
};
}

assert.deepEqual(spec('#test'),[0, 1, 0, 0]);
assert.deepEqual(spec('#a #b #c'),[0, 3, 0, 0]);
Expand All @@ -72,18 +73,18 @@ it('property comparison based on selector specificity', function () {
return new Property(k, v, new Selector(sel));
}

var a = prop('color', 'white', '#woot')
, b = prop('color', 'red', '#a #woot')
var a = prop('color', 'white', '#woot');
var b = prop('color', 'red', '#a #woot');

assert.deepEqual(a.compare(b),b);

var a = prop('background-color', 'red', '#a')
, b = prop('background-color', 'red', '.a.b.c')
a = prop('background-color', 'red', '#a');
b = prop('background-color', 'red', '.a.b.c');

assert.deepEqual(a.compare(b),a);

var a = prop('background-color', 'red', '#a .b.c')
, b = prop('background-color', 'red', '.a.b.c #c')
a = prop('background-color', 'red', '#a .b.c');
b = prop('background-color', 'red', '.a.b.c #c');

assert.deepEqual(a.compare(b),b);
} );
Expand Down
19 changes: 10 additions & 9 deletions test/run.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use strict";

var juice = require('../')
, utils = require('../lib/utils')
, basename = require('path').basename
, fs = require('fs')
, assert = require('assert');
var juice = require('../');
var utils = require('../lib/utils');
var basename = require('path').basename;
var fs = require('fs');
var assert = require('assert');


/**
Expand Down Expand Up @@ -38,10 +39,10 @@ function read (file) {
}

function test (testName, options) {
var base = __dirname + '/cases/' + testName
, html = read(base + '.html')
, css = read( base + '.css' )
, config = options ? JSON.parse( read( base + '.json' ) ) : null;
var base = __dirname + '/cases/' + testName;
var html = read(base + '.html');
var css = read( base + '.css' );
var config = options ? JSON.parse( read( base + '.json' ) ) : null;

options = {};

Expand Down
23 changes: 17 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/*globals describe:false it:false*/
var juice = require('../')
, utils = require('../lib/utils')
, path = require('path')
, fs = require('fs')
, Batch = require('batch')
, assert = require('assert');

"use strict";

var juice = require('../');
var utils = require('../lib/utils');
var path = require('path');
var fs = require('fs');
var Batch = require('batch');
var assert = require('assert');

var tests = [
"doctype",
Expand All @@ -18,6 +21,14 @@ tests.forEach(function(testName) {
it(testName, createIt(testName));
});

it("inlineContent", function()
{
var html = '<p>Hello</p>';
var css = 'p{font-weight:bold;}';

assert.strictEqual(juice.inlineContent(html, css), '<p style="font-weight: bold;">Hello</p>');
});

function createIt(testName) {
return function(cb) {
var batch = new Batch();
Expand Down

0 comments on commit 051449d

Please sign in to comment.