From 1000887d6790898742d7f214060490221adeeed6 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Wed, 5 Jun 2013 10:01:52 -0600 Subject: [PATCH 1/8] Added task inlinecontent --- Gruntfile.js | 14 ++++++++++- tasks/inline_css.js | 60 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9821836..69c5ba3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -39,6 +39,18 @@ module.exports = function(grunt) { }, }, + inlinecontent: { + default_options: { + files: [ + { + src: 'examples/in.html', + css: ['examples/file.css'], + dest: 'examples/out.html', + }, + ], + }, + }, + // Unit tests. nodeunit: { tests: ['test/*_test.js'], @@ -56,7 +68,7 @@ module.exports = function(grunt) { // Whenever the "test" task is run, first clean the "tmp" dir, then run this // plugin's task(s), then test the result. - grunt.registerTask('test', ['clean', 'inlinecss', 'nodeunit']); + grunt.registerTask('test', ['clean', 'inlinecss', 'inlinecontent', 'nodeunit']); // By default, lint and run all tests. grunt.registerTask('default', ['jshint', 'test']); diff --git a/tasks/inline_css.js b/tasks/inline_css.js index 68f78f7..9a70921 100644 --- a/tasks/inline_css.js +++ b/tasks/inline_css.js @@ -56,4 +56,64 @@ module.exports = function(grunt) { }); }); + grunt.registerMultiTask('inlinecontent', 'Takes an html file and css files and turns inline. Great for emails.', function() { + // There are no options for juice.inlinecontent + var done = this.async(); + var index = 0; + var count = this.files.length; + + // Iterate over all specified file groups. + this.files.forEach(function(f) { + + var htmlpath = f.src.toString(); + var csspath = ''; + var html = ''; + var css = ''; + var error = false; + + if (typeof htmlpath !== 'string') { + grunt.log.error('src must be a single string'); + return false; + } + + if (!grunt.file.exists(htmlpath) || !htmlpath) { + grunt.log.error('Source file "' + htmlpath + '" not found.'); + return false; + } + + html = grunt.file.read(htmlpath).toString(); + + // Iterate over all css files + f.css.forEach(function(c) { + csspath = c.toString(); + + if (typeof csspath !== 'string') { + grunt.log.error('src must be a single string'); + error = true; + return false; + } + + if (!grunt.file.exists(csspath) || !csspath) { + grunt.log.error('CSS file "' + csspath + '" not found.'); + error = true; + return false; + } + + css += grunt.file.read(csspath).toString(); + }); + + if (!error) { + grunt.file.write(f.dest, juice.inlineContent(html, css)); + grunt.log.writeln('File "' + f.dest + '" created.'); + } + + + index++; + if (index === count) { + done(); + } + + }); + }); + }; From 6f0760692e9b77fb7ed137b3a730b06e1c1da11e Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Fri, 7 Jun 2013 10:24:40 -0600 Subject: [PATCH 2/8] Preparing to upload to npm --- Gruntfile.js | 6 ++++-- package.json | 14 +++++++------- tasks/inline_css.js | 7 ++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 69c5ba3..e103e8f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,8 +1,10 @@ /* - * grunt-inline-css - * https://github.com/jgallen23/grunt-inline-css + * grunt-inline-content + * https://github.com/straker/grunt-inline-content * * Copyright (c) 2013 Greg Allen + * Forked by Steven Lambert until merged into grunt-inline-css + * https://github.com/jgallen23/grunt-inline-css * Licensed under the MIT license. */ diff --git a/package.json b/package.json index 2802814..39d7503 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,22 @@ { - "name": "grunt-inline-css", - "description": "Takes an html file with css link and turns inline. Great for emails.", + "name": "grunt-inline-content", + "description": "Takes an html file with css link or separate css files and turns inline. Great for emails. Forked from grunt-inline-css until merged.", "version": "0.1.3", - "homepage": "https://github.com/jgallen23/grunt-inline-css", + "homepage": "https://github.com/straker/grunt-inline-content", "author": { - "name": "Greg Allen" + "name": "Steven Lambert" }, "repository": { "type": "git", - "url": "git://github.com/jgallen23/grunt-inline-css.git" + "url": "git://github.com/straker/grunt-inline-content.git" }, "bugs": { - "url": "https://github.com/jgallen23/grunt-inline-css/issues" + "url": "https://github.com/straker/grunt-inline-content/issues" }, "licenses": [ { "type": "MIT", - "url": "https://github.com/jgallen23/grunt-inline-css/blob/master/LICENSE-MIT" + "url": "https://github.com/straker/grunt-inline-content/blob/master/LICENSE-MIT" } ], "main": "Gruntfile.js", diff --git a/tasks/inline_css.js b/tasks/inline_css.js index 9a70921..ef5ee28 100644 --- a/tasks/inline_css.js +++ b/tasks/inline_css.js @@ -1,11 +1,12 @@ /* - * grunt-inline-css - * https://github.com/jgallen23/grunt-inline-css + * grunt-inline-content + * https://github.com/straker/grunt-inline-content * * Copyright (c) 2013 Greg Allen + * Forked by Steven Lambert until merged into grunt-inline-css + * https://github.com/jgallen23/grunt-inline-css * Licensed under the MIT license. */ - 'use strict'; module.exports = function(grunt) { From 8ba41eb7cbb72ff6032f08de957e9878ae9181f8 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Fri, 7 Jun 2013 10:33:48 -0600 Subject: [PATCH 3/8] Readme updated --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 1ac3a6e..f78758f 100644 --- a/README.md +++ b/README.md @@ -38,5 +38,24 @@ grunt.initConfig({ You can see available options [here](https://github.com/LearnBoost/juice) +## The "inlinecontent" task + +### Overview +In your project's Gruntfile, add a section named `inlinecontent` to the data object passed into `grunt.initConfig()`. + +```js +grunt.initConfig({ + inlinecontent: { + main: { + { + src: 'examples/in.html', + css: ['examples/file.css'], + dest: 'examples/out.html', + }, + } + } +}) +``` + ## Contributing In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). From 55243822f70e5ca8dfe77e9a6a886148d90d5136 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Fri, 7 Jun 2013 10:35:14 -0600 Subject: [PATCH 4/8] Readme updated --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f78758f..a149476 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# grunt-inline-css +# grunt-inline-content -> Takes an html file with css link and turns inline. Great for emails. +> Takes an html file with css link or separate css files and turns inline. Great for emails. ## Getting Started This plugin requires Grunt `~0.4.0` @@ -8,13 +8,13 @@ This plugin requires Grunt `~0.4.0` If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: ```shell -npm install grunt-inline-css --save-dev +npm install grunt-inline-content --save-dev ``` One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: ```js -grunt.loadNpmTasks('grunt-inline-css'); +grunt.loadNpmTasks('grunt-inline-content'); ``` ## The "inlinecss" task @@ -54,7 +54,7 @@ grunt.initConfig({ }, } } -}) +}) ``` ## Contributing From 312ba422fef443d27bbf8b5a9a04d1fdace3e1b2 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 12 Nov 2013 17:11:11 -0700 Subject: [PATCH 5/8] Preparing repo for merge --- Gruntfile.js | 6 ++---- README.md | 8 ++++---- package.json | 10 +++++----- tasks/inline_css.js | 7 +++---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index e103e8f..69c5ba3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,10 +1,8 @@ /* - * grunt-inline-content - * https://github.com/straker/grunt-inline-content + * grunt-inline-css + * https://github.com/jgallen23/grunt-inline-css * * Copyright (c) 2013 Greg Allen - * Forked by Steven Lambert until merged into grunt-inline-css - * https://github.com/jgallen23/grunt-inline-css * Licensed under the MIT license. */ diff --git a/README.md b/README.md index a149476..3680c74 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# grunt-inline-content +# grunt-inline-css > Takes an html file with css link or separate css files and turns inline. Great for emails. @@ -8,13 +8,13 @@ This plugin requires Grunt `~0.4.0` If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: ```shell -npm install grunt-inline-content --save-dev +npm install grunt-inline-css --save-dev ``` One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: ```js -grunt.loadNpmTasks('grunt-inline-content'); +grunt.loadNpmTasks('grunt-inline-css'); ``` ## The "inlinecss" task @@ -54,7 +54,7 @@ grunt.initConfig({ }, } } -}) +}) ``` ## Contributing diff --git a/package.json b/package.json index 39d7503..451232e 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,22 @@ { - "name": "grunt-inline-content", + "name": "grunt-inline-css", "description": "Takes an html file with css link or separate css files and turns inline. Great for emails. Forked from grunt-inline-css until merged.", "version": "0.1.3", - "homepage": "https://github.com/straker/grunt-inline-content", + "homepage": "https://github.com/straker/grunt-inline-css", "author": { "name": "Steven Lambert" }, "repository": { "type": "git", - "url": "git://github.com/straker/grunt-inline-content.git" + "url": "git://github.com/straker/grunt-inline-css.git" }, "bugs": { - "url": "https://github.com/straker/grunt-inline-content/issues" + "url": "https://github.com/straker/grunt-inline-css/issues" }, "licenses": [ { "type": "MIT", - "url": "https://github.com/straker/grunt-inline-content/blob/master/LICENSE-MIT" + "url": "https://github.com/straker/grunt-inline-css/blob/master/LICENSE-MIT" } ], "main": "Gruntfile.js", diff --git a/tasks/inline_css.js b/tasks/inline_css.js index ef5ee28..1a18ea8 100644 --- a/tasks/inline_css.js +++ b/tasks/inline_css.js @@ -1,12 +1,11 @@ /* - * grunt-inline-content - * https://github.com/straker/grunt-inline-content + * grunt-inline-css + * https://github.com/straker/grunt-inline-css * * Copyright (c) 2013 Greg Allen - * Forked by Steven Lambert until merged into grunt-inline-css - * https://github.com/jgallen23/grunt-inline-css * Licensed under the MIT license. */ + 'use strict'; module.exports = function(grunt) { From fd9c0992e6257218919187be5c639b71d475d883 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 12 Nov 2013 17:12:38 -0700 Subject: [PATCH 6/8] Preparing repo for merge --- package.json | 8 ++++---- tasks/inline_css.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 451232e..ecc557a 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,21 @@ "name": "grunt-inline-css", "description": "Takes an html file with css link or separate css files and turns inline. Great for emails. Forked from grunt-inline-css until merged.", "version": "0.1.3", - "homepage": "https://github.com/straker/grunt-inline-css", + "homepage": "https://github.com/jgallen23/grunt-inline-css", "author": { - "name": "Steven Lambert" + "name": "Greg Allen" }, "repository": { "type": "git", "url": "git://github.com/straker/grunt-inline-css.git" }, "bugs": { - "url": "https://github.com/straker/grunt-inline-css/issues" + "url": "https://github.com/jgallen23/grunt-inline-css/issues" }, "licenses": [ { "type": "MIT", - "url": "https://github.com/straker/grunt-inline-css/blob/master/LICENSE-MIT" + "url": "https://github.com/jgallen23/grunt-inline-css/blob/master/LICENSE-MIT" } ], "main": "Gruntfile.js", diff --git a/tasks/inline_css.js b/tasks/inline_css.js index 1a18ea8..9a70921 100644 --- a/tasks/inline_css.js +++ b/tasks/inline_css.js @@ -1,6 +1,6 @@ /* * grunt-inline-css - * https://github.com/straker/grunt-inline-css + * https://github.com/jgallen23/grunt-inline-css * * Copyright (c) 2013 Greg Allen * Licensed under the MIT license. From 02fc956d674a4c68b85d88df1734c3307be85303 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 12 Nov 2013 17:13:24 -0700 Subject: [PATCH 7/8] Preparing repo for merge --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ecc557a..6a58bf0 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/straker/grunt-inline-css.git" + "url": "git://github.com/jgallen23/grunt-inline-css.git" }, "bugs": { "url": "https://github.com/jgallen23/grunt-inline-css/issues" From a3ef1007c2b2ba7927beb38b41a1a7490a2924d9 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 12 Nov 2013 17:15:03 -0700 Subject: [PATCH 8/8] Preparing repo for merge --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6a58bf0..aae79a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grunt-inline-css", - "description": "Takes an html file with css link or separate css files and turns inline. Great for emails. Forked from grunt-inline-css until merged.", + "description": "Takes an html file with css link or separate css files and turns inline. Great for emails.", "version": "0.1.3", "homepage": "https://github.com/jgallen23/grunt-inline-css", "author": {