Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 09b8538b4b2c4d52b1dfcc9df19c01342d5763dc @crcn crcn committed Feb 27, 2012
Showing with 30,500 additions and 0 deletions.
  1. +2 −0 .cupboard
  2. +5 −0 LICENSE.txt
  3. +36 −0 README.md
  4. +25 −0 bin/emailify
  5. +11 −0 examples/test-1/index.html
  6. +7 −0 examples/test-1/index.out.html
  7. +71 −0 lib/index.js
  8. +8,176 −0 lib/jquery-1.5.js
  9. +1 −0 lib/lint.js
  10. +5 −0 makefile
  11. +6 −0 node_modules/jsdom/.gitignore
  12. +6 −0 node_modules/jsdom/.npmignore
  13. +22 −0 node_modules/jsdom/LICENSE.txt
  14. +282 −0 node_modules/jsdom/README.md
  15. +23 −0 node_modules/jsdom/benchmark/mark.js
  16. 0 node_modules/jsdom/benchmark/stats.json
  17. +151 −0 node_modules/jsdom/changelog
  18. +34 −0 node_modules/jsdom/example/browser/browser.js
  19. +1,170 −0 node_modules/jsdom/example/ender/ender.js
  20. +10 −0 node_modules/jsdom/example/ender/run.js
  21. +167 −0 node_modules/jsdom/example/jquery/jquery.js
  22. +9 −0 node_modules/jsdom/example/jquery/run.js
  23. +243 −0 node_modules/jsdom/example/node-xml/example.xml
  24. +45 −0 node_modules/jsdom/example/node-xml/run.js
  25. +742 −0 node_modules/jsdom/example/pure/pure.js
  26. +96 −0 node_modules/jsdom/example/pure/run.js
  27. +11 −0 node_modules/jsdom/example/pure/sax-test.js
  28. +535 −0 node_modules/jsdom/example/pure/sax.js
  29. +166 −0 node_modules/jsdom/example/sizzle/run.js
  30. +534 −0 node_modules/jsdom/example/sizzle/sax.js
  31. +1,066 −0 node_modules/jsdom/example/sizzle/sizzle.js
  32. +360 −0 node_modules/jsdom/lib/jsdom.js
  33. +52 −0 node_modules/jsdom/lib/jsdom/browser/documentfeatures.js
  34. +180 −0 node_modules/jsdom/lib/jsdom/browser/domtohtml.js
  35. +1,506 −0 node_modules/jsdom/lib/jsdom/browser/htmlencoding.js
  36. +184 −0 node_modules/jsdom/lib/jsdom/browser/htmltodom.js
  37. +621 −0 node_modules/jsdom/lib/jsdom/browser/index.js
  38. +1,765 −0 node_modules/jsdom/lib/jsdom/level1/core.js
  39. +643 −0 node_modules/jsdom/lib/jsdom/level2/core.js
  40. +416 −0 node_modules/jsdom/lib/jsdom/level2/events.js
  41. +1,764 −0 node_modules/jsdom/lib/jsdom/level2/html.js
  42. +7 −0 node_modules/jsdom/lib/jsdom/level2/index.js
  43. +13 −0 node_modules/jsdom/lib/jsdom/level2/languages/javascript.js
  44. +236 −0 node_modules/jsdom/lib/jsdom/level2/style.js
  45. +649 −0 node_modules/jsdom/lib/jsdom/level3/core.js
  46. +299 −0 node_modules/jsdom/lib/jsdom/level3/events.js
  47. +9 −0 node_modules/jsdom/lib/jsdom/level3/html.js
  48. +10 −0 node_modules/jsdom/lib/jsdom/level3/index.js
  49. +221 −0 node_modules/jsdom/lib/jsdom/level3/ls.js
  50. +1,859 −0 node_modules/jsdom/lib/jsdom/level3/xpath.js
  51. +31 −0 node_modules/jsdom/lib/jsdom/selectors/index.js
  52. +1,449 −0 node_modules/jsdom/lib/jsdom/selectors/sizzle.js
  53. +27 −0 node_modules/jsdom/lib/jsdom/utils.js
  54. +170 −0 node_modules/jsdom/package.json
  55. +22 −0 node_modules/jsdom/status.json
  56. +2 −0 node_modules/optimist/.gitignore
  57. +4 −0 node_modules/optimist/.npmignore
  58. +21 −0 node_modules/optimist/LICENSE
  59. +485 −0 node_modules/optimist/README.markdown
  60. +10 −0 node_modules/optimist/examples/bool.js
  61. +7 −0 node_modules/optimist/examples/boolean_double.js
  62. +7 −0 node_modules/optimist/examples/boolean_single.js
  63. +8 −0 node_modules/optimist/examples/default_hash.js
  64. +7 −0 node_modules/optimist/examples/default_singles.js
  65. +8 −0 node_modules/optimist/examples/divide.js
  66. +20 −0 node_modules/optimist/examples/line_count.js
  67. +29 −0 node_modules/optimist/examples/line_count_options.js
  68. +29 −0 node_modules/optimist/examples/line_count_wrap.js
  69. +4 −0 node_modules/optimist/examples/nonopt.js
  70. +2 −0 node_modules/optimist/examples/reflect.js
  71. +3 −0 node_modules/optimist/examples/short.js
  72. +11 −0 node_modules/optimist/examples/string.js
  73. +19 −0 node_modules/optimist/examples/usage-options.js
  74. +10 −0 node_modules/optimist/examples/xup.js
  75. +470 −0 node_modules/optimist/index.js
  76. +43 −0 node_modules/optimist/package.json
  77. +66 −0 node_modules/optimist/test/_.js
  78. +2 −0 node_modules/optimist/test/_/argv.js
  79. +3 −0 node_modules/optimist/test/_/bin.js
  80. +322 −0 node_modules/optimist/test/parse.js
  81. +256 −0 node_modules/optimist/test/usage.js
  82. +9 −0 node_modules/outcome/.cupboard
  83. +1 −0 node_modules/outcome/.gitignore
  84. +245 −0 node_modules/outcome/README.md
  85. +24 −0 node_modules/outcome/examples/basic-test.js
  86. +43 −0 node_modules/outcome/examples/fs-test.js
  87. +20 −0 node_modules/outcome/examples/test.html
  88. +29 −0 node_modules/outcome/examples/test3.js
  89. +145 −0 node_modules/outcome/lib/index.js
  90. +666 −0 node_modules/outcome/outcome.js
  91. +17 −0 node_modules/outcome/outcome.min.js
  92. +15 −0 node_modules/outcome/package.json
  93. +23 −0 node_modules/outcome/project.sublime-project
  94. +1,222 −0 node_modules/outcome/project.sublime-workspace
  95. +20 −0 package.json
  96. +23 −0 project.sublime-project
@@ -0,0 +1,2 @@
+[commands]
+proj = subl --project project.sublime-project
@@ -0,0 +1,5 @@
+MIT License
+Copyright (c) 2012 Craig Condon
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
+### Emailify makes your html documents a bit more email-safe
+
+### Features
+
+- associated style sheets to dom elements
+
+
+### TODO
+
+- warnings for elements not compatible with some email clients
+- command line
+- see http://www.campaignmonitor.com/css/
+
+
+### Example
+
+```javascript
+var emailify = require('emailify'),
+fs = require('fs')
+
+emailify.parse(fs.readFileSync('/my/email/newsletter.html', 'utf8'), function(err, content) {
+ //send newsletter
+});
+```
+
+### API
+
+#### .load(file, callback)
+
+loads a html file
+
+### .parse(content, callback)
+
+parses html content into email-safe html
+
+
@@ -0,0 +1,25 @@
+#!/usr/bin/env node
+
+var argv = require('optimist').
+usage('-i [input_html] -o [output_html]').
+demand(['i','o']).
+alias('i','input').
+alias('o','output').
+argv;
+
+var fs = require('fs'),
+emailify = require('../'),
+outcome = require('outcome');
+
+
+function fixFile(file) {
+ return file.replace(/^\.\//,process.cwd() + '/').replace(/^\~/,process.env.HOME);
+}
+
+var on = outcome.error(function(err) {
+ console.error(err);
+});
+
+emailify.load(fixFile(argv.i), on.success(function(content) {
+ fs.writeFile(fixFile(argv.o), content, on);
+}));
@@ -0,0 +1,11 @@
+<html>
+<head>
+ <style>
+ h4 {
+ color: #ff6600;
+ }
+ </style>
+</head>
+<body>
+ <h4>orange header</h4>
+</body>
@@ -0,0 +1,7 @@
+<html>
+<head>
+
+</head>
+<body>
+ <h4 style="color: #ff6600;">orange header</h4>
+</body><script class="jsdom" src="/Users/craig/Dropbox/Developer/Public/emailify/lib/jquery-1.5.js"></script></html>
@@ -0,0 +1,71 @@
+var fs = require('fs'),
+jsdom = require('jsdom'),
+outcome = require('outcome'),
+EventEmitter = require('events').EventEmitter;
+
+
+function _copyStyles(window) {
+ window.$('link, style').each(function(index, element) {
+ element.sheet.cssRules.forEach(function(rule) {
+
+ //selector breaks on stuff like a:hover
+ try {
+ window.$(rule.selectorText).each(function(index, element) {
+ element.style.cssText += rule.style.cssText;
+ });
+ } catch(e) {
+
+ }
+ });
+
+ _strip(window, element);
+ });
+}
+
+function _strip(window, selector) {
+ window.$(element).remove();
+}
+
+
+/**
+ * parses content into email-safe HTML
+ */
+
+function _parse(content, callback) {
+
+ jsdom.env({
+ html: content,
+ scripts: [
+ __dirname + "/jquery-1.5.js"
+ ],
+ done: function(err, window) {
+
+ //first copy the CSS to style attributes - safe for GMAIL
+ _copyStyles(window);
+
+ //remove script attributes
+ _strip(window, 'script')
+
+
+ callback(null, window.document.innerHTML)
+ }
+ });
+
+}
+
+/**
+ */
+
+function _load(file, callback) {
+
+ fs.readFile(file, "utf8", outcome.error(callback).success(function(content) {
+
+ _parse(content, callback);
+
+ }));
+
+}
+
+
+exports.parse = _parse;
+exports.load = _load;
Oops, something went wrong.

0 comments on commit 09b8538

Please sign in to comment.