Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleaned up testing response

  • Loading branch information...
commit 4f7bf724d6532f386c8f98cc82b598055b1eb16d 1 parent cb888ad
Craig Condon authored February 27, 2012
17  README.md
Source Rendered
@@ -6,6 +6,7 @@
6 6
 - HTML compatibility checking for popular email clients. See:
7 7
 	- http://www.campaignmonitor.com/css/
8 8
 	- http://www.campaignmonitor.com/downloads/documents-tools/campaign-monitor-guide-to-css-in-email-sept-2011.pdf
  9
+	- http://www.email-standards.org/
9 10
 
10 11
 ### HTML Example
11 12
 
@@ -40,7 +41,7 @@ Into this:
40 41
 
41 42
 ### Testing Compatibility Screenshot
42 43
 
43  
-![Alt command line](http://i.imgur.com/xpsyQ.png)
  44
+![Alt command line](http://i.imgur.com/AUX7z.png)
44 45
 
45 46
 ### Requirements
46 47
 
@@ -90,20 +91,26 @@ emailify -i /my/html/file.html
90 91
 
91 92
 ### Node.js API
92 93
 
93  
-#### .parse(content, callback)
  94
+#### .parse(content[, options], callback)
94 95
 
95 96
 parses html content into email-safe html
96 97
 
  98
+- `content` - the html content
  99
+- `options`
  100
+	`test` - runs test against code for compatibility
  101
+
  102
+
97 103
 ```javascript
98 104
 var emailify = require('emailify'),
99 105
 fs           = require('fs')
100 106
 
101  
-emailify.parse(fs.readFileSync('/my/email/newsletter.html', 'utf8'), function(err, content) {
  107
+emailify.parse(fs.readFileSync('/my/email/newsletter.html', 'utf8'), function(err, content, warnings) {
102 108
 	//send newsletter
103 109
 });
104 110
 ```
105 111
 
106  
-#### .load(file, callback)
  112
+#### .load(file[, options], callback)
  113
+
107 114
 
108 115
 loads a html file
109 116
 
@@ -111,7 +118,7 @@ loads a html file
111 118
 var emailify = require('emailify'),
112 119
 fs           = require('fs')
113 120
 
114  
-emailify.load('/my/email/newsletter.html', function(err, content) {
  121
+emailify.load('/my/email/newsletter.html', function(err, content, warnings) {
115 122
 	//send newsletter
116 123
 });
117 124
 ```
54  bin/emailify
@@ -10,9 +10,10 @@ alias('o','output').
10 10
 alias('t','test').
11 11
 argv;
12 12
 
13  
-var fs = require('fs'),
  13
+var fs   = require('fs'),
14 14
 emailify = require('../'),
15  
-outcome = require('outcome');
  15
+outcome  = require('outcome'),
  16
+celeri   = require('celeri');
16 17
 
17 18
 /**
18 19
  */
@@ -27,7 +28,7 @@ function fixFile(file) {
27 28
  */
28 29
 
29 30
 var on = outcome.error(function(err) {
30  
-	
  31
+
31 32
 	console.error(err);
32 33
 
33 34
 });
@@ -36,8 +37,8 @@ var on = outcome.error(function(err) {
36 37
  */
37 38
 
38 39
 
39  
-emailify.load(fixFile(argv.i), { test: argv.t }, on.success(function(content) {
40  
-	
  40
+emailify.load(fixFile(argv.i), { test: argv.t }, on.success(function(content, warnings) {
  41
+
41 42
 	if(argv.o) {
42 43
 
43 44
 		fs.writeFile(fixFile(argv.o), content, on);
@@ -48,4 +49,45 @@ emailify.load(fixFile(argv.i), { test: argv.t }, on.success(function(content) {
48 49
 		console.log(content);
49 50
 	}
50 51
 
51  
-}));
  52
+	printWarnings(warnings);
  53
+
  54
+}));
  55
+
  56
+
  57
+/**
  58
+ */
  59
+
  60
+function printWarnings(warnings) {
  61
+
  62
+	if(!warnings.length) return;
  63
+
  64
+	var toPrint = [];
  65
+
  66
+	for(var i = warnings.length; i--;) {
  67
+		var warning = warnings[i];
  68
+
  69
+		toPrint.push({
  70
+			type: warning.type,
  71
+			platforms: warning.platforms.join("\n "),
  72
+			value: warning.value
  73
+		});
  74
+	}
  75
+
  76
+
  77
+	console.log('\n');
  78
+	console.log('   Unsupported Clients'.bold);
  79
+
  80
+	celeri.table(toPrint, {
  81
+		columns: {
  82
+			type: 9,
  83
+			value: 15,
  84
+			platforms: 26
  85
+		},
  86
+		pad: {
  87
+			'left': 3
  88
+		},
  89
+		horz:' ',
  90
+		fixed: true
  91
+	});
  92
+	console.log('\n');
  93
+}
4  examples/test-1/index.html
@@ -6,6 +6,10 @@
6 6
 				box-shadow: #ff6600;
7 7
 			}
8 8
 
  9
+			a:hover {
  10
+				
  11
+			}
  12
+
9 13
 		</style>
10 14
 	</head>
11 15
 	<body>
9  lib/index.js
@@ -38,6 +38,7 @@ function _parse(content, options, callback) {
38 38
 
39 39
 
40 40
 	var on = outcome.error(callback),
  41
+	warnings,
41 42
 	window;
42 43
 
43 44
 	step(
@@ -92,12 +93,14 @@ function _parse(content, options, callback) {
92 93
 		 * clean it.
93 94
 		 */
94 95
 
95  
-		function() {
  96
+		on.success(function(warn) {
  97
+
  98
+			warnings = warn;
96 99
 
97 100
 			window.$('script, link, style').remove();
98 101
 			this();
99 102
 
100  
-		},
  103
+		}),
101 104
 
102 105
 
103 106
 		/**
@@ -106,7 +109,7 @@ function _parse(content, options, callback) {
106 109
 
107 110
 		function() {
108 111
 
109  
-			callback(null, window.document.innerHTML);
  112
+			callback(null, window.document.innerHTML, warnings || []);
110 113
 
111 114
 		}
112 115
 	);
11  lib/test/compatibility/test-android.js
... ...
@@ -1,12 +1,11 @@
1  
-var assert = require('assert'),
2  
-utils      = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
5 4
 
6  
-	'Android - 1.7%': {
7  
-
8  
-		'styles': utils.doesNotContainStylesBatch(
  5
+	'name':'Android',
  6
+	'test': {
9 7
 
  8
+		'style': [
10 9
 
11 10
 			//TEXT
12 11
 			'word-wrap',
@@ -43,7 +42,7 @@ module.exports = {
43 42
 			//TABLE
44 43
 			'border-spacing',
45 44
 			'caption-side',
46  
-			'empty-cells')
  45
+			'empty-cells']
47 46
 
48 47
 	}
49 48
 
10  lib/test/compatibility/test-apple-mail-4.js
... ...
@@ -1,16 +1,16 @@
1  
-var assert = require('assert'),
2  
-utils      = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
5 4
 
6  
-	'Apple Mail 4 - 11%': {
  5
+	'name': 'Apple Mail 4',
  6
+	'test': {
7 7
 
8  
-		'styles': utils.doesNotContainStylesBatch(
  8
+		'style': [
9 9
 
10 10
 			//BOX
11 11
 			'box-shadow',
12 12
 
13  
-			'caption-side')
  13
+			'caption-side']
14 14
 
15 15
 	}
16 16
 
10  lib/test/compatibility/test-gmail.js
... ...
@@ -1,11 +1,11 @@
1  
-var assert = require('assert'),
2  
-utils      = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
5 4
 
6  
-	'GMail - 7%': {
  5
+	'name': 'GMail',
  6
+	'test': {
7 7
 
8  
-		'styles': utils.doesNotContainStylesBatch(
  8
+		'style': [
9 9
 
10 10
 
11 11
 			//TEXT
@@ -41,7 +41,7 @@ module.exports = {
41 41
 			//TABLE
42 42
 			'border-spacing',
43 43
 			'caption-side',
44  
-			'empty-cells')
  44
+			'empty-cells']
45 45
 
46 46
 	}
47 47
 
10  lib/test/compatibility/test-hotmail.js
... ...
@@ -1,11 +1,11 @@
1  
-var assert = require('assert'),
2  
-utils     = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
5 4
 
6  
-	'Hotmail - 12%': {
  5
+	'name': 'Hotmail',
  6
+	'test': {
7 7
 
8  
-		'styles': utils.doesNotContainStylesBatch(
  8
+		'style': [
9 9
 
10 10
 			//BG
11 11
 			'background-image',
@@ -23,7 +23,7 @@ module.exports = {
23 23
 
24 24
 			//LISTS
25 25
 			'list-style-image',
26  
-			'list-style-position')
  26
+			'list-style-position']
27 27
 
28 28
 	}
29 29
 
10  lib/test/compatibility/test-iphone-ipad.js
... ...
@@ -1,17 +1,17 @@
1  
-var assert = require('assert'),
2  
-utils      = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
5 4
 
6  
-	'Apple iPhone/iPad - 16%': {
  5
+	'name': 'Apple iPhone/iPad',
  6
+	'test': {
7 7
 
8  
-		'styles': utils.doesNotContainStylesBatch(
  8
+		'style': [
9 9
 
10 10
 			//BOX
11 11
 			'box-shadow',
12 12
 
13 13
 			//TABLE
14  
-			'caption-side')
  14
+			'caption-side']
15 15
 
16 16
 	}
17 17
 };
11  lib/test/compatibility/test-outlook-2003.js
... ...
@@ -1,11 +1,10 @@
1  
-var assert = require('assert'),
2  
-utils      = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
  4
+	'name': 'Outlook Express 2000/2003',
  5
+	'test': {
5 6
 
6  
-	'Outlook Express 2000/2003 - 27%': {
7  
-
8  
-		'styles': utils.doesNotContainStylesBatch(
  7
+		'style': [
9 8
 
10 9
 			//TEXT
11 10
 			'text-shadow',
@@ -27,7 +26,7 @@ module.exports = {
27 26
 			//TABLE
28 27
 			'border-spacing',
29 28
 			'caption-side',
30  
-			'empty-cells')
  29
+			'empty-cells']
31 30
 
32 31
 	}
33 32
 
10  lib/test/compatibility/test-outlook-2010-2010.js
... ...
@@ -1,11 +1,11 @@
1  
-var assert = require('assert'),
2  
-utils      = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
5 4
 
6  
-	'Outlook Express 2007/2010 - 27%': {
  5
+	'name': 'Outlook Express 2007/2010',
  6
+	'test': {
7 7
 
8  
-		'styles': utils.doesNotContainStylesBatch(
  8
+		'style': [
9 9
 
10 10
 
11 11
 			//TEXT
@@ -53,7 +53,7 @@ module.exports = {
53 53
 			//TABLE
54 54
 			'border-spacing',
55 55
 			'caption-side',
56  
-			'empty-cells')
  56
+			'empty-cells']
57 57
 
58 58
 	}
59 59
 
13  lib/test/compatibility/test-yahoo-mail.js
... ...
@@ -1,11 +1,12 @@
1  
-var assert = require('assert'),
2  
-utils      = require('../utils');
  1
+var assert = require('assert');
3 2
 
4 3
 module.exports = {
5 4
 
6  
-	'Yahoo! Mail - 9%': {
  5
+	'name': 'Yahoo! Mail',
7 6
 
8  
-		'styles': utils.doesNotContainStylesBatch(
  7
+	'test': {
  8
+
  9
+		'style': [
9 10
 
10 11
 			//BG
11 12
 			'background-image',
@@ -26,8 +27,8 @@ module.exports = {
26 27
 			'resize',
27 28
 			'right',
28 29
 			'top',
29  
-			'z-index')
  30
+			'z-index']
30 31
 
31 32
 	}
32  
-	
  33
+
33 34
 };
20  lib/test/index.js
... ...
@@ -1,15 +1,13 @@
1 1
 var plugin = require('plugin'),
2  
-vows       = require('vows'),
3  
-utils      = require('./utils'),
4  
-loader     = plugin.loader();
  2
+loader     = plugin.loader(),
  3
+suite      = require('./suite');
5 4
 
6 5
 require('colors');
7 6
 
8 7
 module.exports = function(window, options, callback) {
9 8
 
10  
-	var subject = vows.describe('Email Compatibility');
11  
-	utils.attach(window);
12  
-	
  9
+	var subject = suite(window);
  10
+
13 11
 	loader.
14 12
 	factory(function(plugin) {
15 13
 
@@ -25,20 +23,14 @@ module.exports = function(window, options, callback) {
25 23
 
26 24
 		}
27 25
 
28  
-		for(var prop in module) {
29  
-
30  
-			module[prop].topic = window;
31  
-
32  
-		}
33  
-
34  
-		subject.addBatch(module);
  26
+		subject.add(module);
35 27
 
36 28
 	}).
37 29
 	require(__dirname + "/selectors/**/test-*").
38 30
 	require(__dirname + "/compatibility/**/test-*").
39 31
 	load(function() {
40 32
 
41  
-		subject.run(options, callback);
  33
+		subject.run(callback);
42 34
 
43 35
 	});	
44 36
 
27  lib/test/selectors/test-selectors.js
@@ -4,36 +4,21 @@ sprintf = require('sprintf').sprintf
4 4
 
5 5
 exports.plugin = function(topic) {
6 6
 
7  
-	var batch = {};
  7
+	var batch = [];
8 8
 
9 9
 		eachCssRule(topic, function(rule) {
10 10
 
11  
-			batch[sprintf('"%s" validity', rule.selectorText.bold)] = function(topic) {
12  
-
13  
-				var len
14  
-
15  
-
16  
-				//don't want jquery to break...
17  
-				try {
18  
-
19  
-					len = topic.$(rule.selectorText).length
20  
-
21  
-				} catch(e) {
22  
-
23  
-					len = 1;
24  
-
25  
-				}
26  
-
27  
-				assert.isTrue(!!len);
28  
-
29  
-			}
  11
+			batch.push(rule.selectorText);
30 12
 
31 13
 		});
32 14
 
33 15
 
34 16
 	return {
35 17
 
36  
-		'Style Selectors': batch
  18
+		'name': 'all clients',
  19
+		'test': {
  20
+			'selector': batch
  21
+		}
37 22
 
38 23
 	};
39 24
 
96  lib/test/suite.js
... ...
@@ -0,0 +1,96 @@
  1
+var assert = require('assert')
  2
+
  3
+var _testers = {
  4
+	'selector': function(topic, selector) {
  5
+		 var len;
  6
+
  7
+		//don't want jquery to break...
  8
+		try {
  9
+
  10
+			len = topic.$(selector).length
  11
+
  12
+		} catch(e) {
  13
+
  14
+			len = 1;
  15
+
  16
+		}
  17
+
  18
+
  19
+		assert.equal(!!len, true);
  20
+	},
  21
+	'style': function(topic, selector) {
  22
+		assert.equal(topic.$('*[cssText*="' + selector + ':"]').length, 0);
  23
+	}
  24
+}
  25
+
  26
+
  27
+module.exports = function(topic) {
  28
+
  29
+	var _batches = {};
  30
+
  31
+
  32
+	var self = {
  33
+
  34
+		add: function(platform) {
  35
+
  36
+			var name = platform.name,
  37
+			testBatch = platform.test;
  38
+
  39
+			for(var testType in testBatch) {
  40
+
  41
+				var batch = testBatch[testType];
  42
+
  43
+				if(!_batches[testType]) {
  44
+					_batches[testType] = {};
  45
+				}
  46
+
  47
+				for(var i = batch.length; i--;) {
  48
+
  49
+					var test = batch[i];
  50
+
  51
+					if(!_batches[testType][test]) {
  52
+
  53
+						_batches[testType][test] = [];
  54
+
  55
+					}
  56
+
  57
+					_batches[testType][test].push(name);
  58
+				}
  59
+
  60
+			}
  61
+
  62
+			return self;
  63
+		},
  64
+
  65
+
  66
+		run: function(callback) {
  67
+
  68
+			var incompatible = [];
  69
+
  70
+			for(var type in _batches) {
  71
+
  72
+				var tests = _batches[type],
  73
+				tester    = _testers[type];
  74
+
  75
+
  76
+				for(var test in tests) {
  77
+					try {
  78
+						tester(topic, test);
  79
+					} catch(e) {
  80
+
  81
+						incompatible.push({
  82
+							type: type,
  83
+							value: test,
  84
+							platforms: tests[test]
  85
+						});
  86
+
  87
+					}
  88
+				}
  89
+			}
  90
+
  91
+			callback(null, incompatible);
  92
+		}
  93
+	}
  94
+
  95
+	return self;
  96
+}
34  lib/test/utils.js
... ...
@@ -1,34 +0,0 @@
1  
-var assert = require('assert');
2  
-
3  
-/**
4  
- */
5  
- 
6  
-exports.attach = function(topic) {
7  
-
8  
-	topic.assertStyle = function(selector, num) {
9  
-
10  
-		assert.equal(topic.$('*[cssText*="' + selector + ':"]').length, num || 0);
11  
-
12  
-	};
13  
-
14  
-};
15  
-
16  
-/** 
17  
- */
18  
-
19  
-exports.doesNotContainStylesBatch = function() {
20  
-
21  
-	var batch = {};
22  
-
23  
-	Array.prototype.slice.apply(arguments).forEach(function(style) {
24  
-
25  
-		batch["does not contain " + style] = function(topic) {
26  
-
27  
-			topic.assertStyle(style);
28  
-
29  
-		};
30  
-
31  
-	});
32  
-
33  
-	return batch;
34  
-};

0 notes on commit 4f7bf72

Please sign in to comment.
Something went wrong with that request. Please try again.