Skip to content

Commit 051449d

Browse files
committed
Merge pull request #138 from jrit/cheerio-node-12
fix undefined options
2 parents e318777 + 895bdbd commit 051449d

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
lines changed

lib/juice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function inlineDocument($, css, options) {
163163
function addProps (style, selector) {
164164
for (var i = 0, l = style.length; i < l; i++) {
165165
var name = style[i];
166-
var value = style[name] + (options.preserveImportant && style._importants[name] ? ' !important' : '');
166+
var value = style[name] + (options && options.preserveImportant && style._importants[name] ? ' !important' : '');
167167
var sel = style._importants[name] ? importantSelector : selector;
168168
var prop = new Property(name, value, sel);
169169
var existing = el.styleProps[name];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "juice",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Inlines css into html source",
55
"bin": "./bin/juice",
66
"main": "./lib/juice",

test/juice.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12

23
/*!
34
* Juice unit tests.
@@ -7,11 +8,11 @@
78
* Test dependencies.
89
*/
910

10-
var juice = require('../')
11-
, Selector = juice.Selector
12-
, Property = juice.Property
13-
, utils = juice.utils
14-
, assert = require('assert');
11+
var juice = require('../');
12+
var Selector = juice.Selector;
13+
var Property = juice.Property;
14+
var utils = juice.utils;
15+
var assert = require('assert');
1516

1617
/**
1718
* Tests.
@@ -54,7 +55,7 @@ it('selector specificity comparison', function () {
5455
it('selector specificity calculator', function () {
5556
function spec (selector) {
5657
return new Selector(selector).specificity();
57-
};
58+
}
5859

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

75-
var a = prop('color', 'white', '#woot')
76-
, b = prop('color', 'red', '#a #woot')
76+
var a = prop('color', 'white', '#woot');
77+
var b = prop('color', 'red', '#a #woot');
7778

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

80-
var a = prop('background-color', 'red', '#a')
81-
, b = prop('background-color', 'red', '.a.b.c')
81+
a = prop('background-color', 'red', '#a');
82+
b = prop('background-color', 'red', '.a.b.c');
8283

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

85-
var a = prop('background-color', 'red', '#a .b.c')
86-
, b = prop('background-color', 'red', '.a.b.c #c')
86+
a = prop('background-color', 'red', '#a .b.c');
87+
b = prop('background-color', 'red', '.a.b.c #c');
8788

8889
assert.deepEqual(a.compare(b),b);
8990
} );

test/run.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
"use strict";
12

2-
var juice = require('../')
3-
, utils = require('../lib/utils')
4-
, basename = require('path').basename
5-
, fs = require('fs')
6-
, assert = require('assert');
3+
var juice = require('../');
4+
var utils = require('../lib/utils');
5+
var basename = require('path').basename;
6+
var fs = require('fs');
7+
var assert = require('assert');
78

89

910
/**
@@ -38,10 +39,10 @@ function read (file) {
3839
}
3940

4041
function test (testName, options) {
41-
var base = __dirname + '/cases/' + testName
42-
, html = read(base + '.html')
43-
, css = read( base + '.css' )
44-
, config = options ? JSON.parse( read( base + '.json' ) ) : null;
42+
var base = __dirname + '/cases/' + testName;
43+
var html = read(base + '.html');
44+
var css = read( base + '.css' );
45+
var config = options ? JSON.parse( read( base + '.json' ) ) : null;
4546

4647
options = {};
4748

test/test.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/*globals describe:false it:false*/
2-
var juice = require('../')
3-
, utils = require('../lib/utils')
4-
, path = require('path')
5-
, fs = require('fs')
6-
, Batch = require('batch')
7-
, assert = require('assert');
2+
3+
"use strict";
4+
5+
var juice = require('../');
6+
var utils = require('../lib/utils');
7+
var path = require('path');
8+
var fs = require('fs');
9+
var Batch = require('batch');
10+
var assert = require('assert');
811

912
var tests = [
1013
"doctype",
@@ -18,6 +21,14 @@ tests.forEach(function(testName) {
1821
it(testName, createIt(testName));
1922
});
2023

24+
it("inlineContent", function()
25+
{
26+
var html = '<p>Hello</p>';
27+
var css = 'p{font-weight:bold;}';
28+
29+
assert.strictEqual(juice.inlineContent(html, css), '<p style="font-weight: bold;">Hello</p>');
30+
});
31+
2132
function createIt(testName) {
2233
return function(cb) {
2334
var batch = new Batch();

0 commit comments

Comments
 (0)