From 0c82a4daf18561ddcd621d18cd9a83baa5be5486 Mon Sep 17 00:00:00 2001 From: Maxime Brazeilles Date: Thu, 20 Oct 2016 11:33:35 +0200 Subject: [PATCH 1/4] semicolons, mjml 3, packagejson ... --- examples/gulpfile.js | 7 +++---- examples/test.mjml | 17 ++++++++++++++++ package.json | 4 ++-- src/index.js | 48 ++++++++++++++++++++++++++------------------ 4 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 examples/test.mjml diff --git a/examples/gulpfile.js b/examples/gulpfile.js index 19086d7..2bf5d9c 100644 --- a/examples/gulpfile.js +++ b/examples/gulpfile.js @@ -1,9 +1,8 @@ - -var gulp = require('gulp'); -var mjml = require('../index') +var gulp = require('gulp') +var mjml = require('../src/index') gulp.task('default', function () { gulp.src('./test.mjml') .pipe(mjml()) .pipe(gulp.dest('./html')) -}); +}) diff --git a/examples/test.mjml b/examples/test.mjml new file mode 100644 index 0000000..d578f74 --- /dev/null +++ b/examples/test.mjml @@ -0,0 +1,17 @@ + + + + + + + + + + + Hello World + + + + + + diff --git a/package.json b/package.json index c082237..cc5fc1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-mjml", - "version": "1.0.1", + "version": "2.0.0", "description": "Add Gulp to your MJML workflow", "main": "src/index", "scripts": { @@ -11,7 +11,7 @@ "dependencies": { "gulp": "^3.9.0", "gulp-util": "^3.0.7", - "mjml": "latest", + "mjml": "^3.0.0", "through2": "^2.0.0" } } diff --git a/src/index.js b/src/index.js index a1c7540..7b35783 100644 --- a/src/index.js +++ b/src/index.js @@ -1,29 +1,37 @@ - var through = require ('through2') - , mjmlDefaultEngine = require ('mjml') - , gutil = require ('gulp-util'); +var mjmlDefaultEngine = require ('mjml') +var gutil = require ('gulp-util') -var GulpError = gutil.PluginError, - NAME = 'MJML'; +var GulpError = gutil.PluginError +var NAME = 'MJML' module.exports = function mjml (mjmlEngine) { if(mjmlEngine === undefined) { - mjmlEngine = mjmlDefaultEngine; + mjmlEngine = mjmlDefaultEngine } - return through.obj(function (file, enc, callback) { + return through.obj(function (file, enc, callback) { + + if (file.isStream()) { + this.emit('error', new GulpError(NAME, 'Streams are not supported!')) + return callback() + } + + if (file.isBuffer()) { + var output = file.clone() + var render - if (file.isStream()) { - this.emit('error', new PluginError(NAME, 'Streams are not supported!')); - return callback() - } + try { + render = mjmlEngine.mjml2html(file.contents.toString()) + } catch (e) { + this.emit('error', new GulpError(NAME, e)) + return callback() + } - if (file.isBuffer()) { - var output = file.clone(); - output.contents = new Buffer(mjmlEngine.mjml2html(file.contents.toString())); - output.path = gutil.replaceExtension(file.path.toString(), '.html'); - this.push(output); - } - return callback(); - }) -}; + output.contents = new Buffer(render.html) + output.path = gutil.replaceExtension(file.path.toString(), '.html') + this.push(output) + } + return callback() + }) +} From b8bf85f3d22c944a3ab0cdb24e86cbb1b590dd5c Mon Sep 17 00:00:00 2001 From: Maxime Brazeilles Date: Thu, 20 Oct 2016 11:38:41 +0200 Subject: [PATCH 2/4] remove semicolons --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e7ad723..708ebed 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,14 @@ Add Gulp to your MJML workflow! ``` javascript -var gulp = require('gulp'); +var gulp = require('gulp') var mjml = require('gulp-mjml') gulp.task('default', function () { return gulp.src('./test.mjml') .pipe(mjml()) .pipe(gulp.dest('./html')) -}); +}) ``` @@ -24,7 +24,7 @@ gulp.task('default', function () { ``` javascript -var gulp = require('gulp'); +var gulp = require('gulp') var mjml = require('gulp-mjml') // Require your own components if needed, and your mjmlEngine @@ -35,6 +35,6 @@ gulp.task('default', function () { return gulp.src('./test.mjml') .pipe(mjml(mjmlEngine)) .pipe(gulp.dest('./html')) -}); +}) ``` From 2f7491d86406897ec324944a5fc895e1da828101 Mon Sep 17 00:00:00 2001 From: Maxime Brazeilles Date: Thu, 20 Oct 2016 11:41:50 +0200 Subject: [PATCH 3/4] No BC in mjml 3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc5fc1f..13165cc 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dependencies": { "gulp": "^3.9.0", "gulp-util": "^3.0.7", - "mjml": "^3.0.0", + "mjml": "~3.0.0", "through2": "^2.0.0" } } From d9e2783a573609182ad80576e0d2f883dbf40983 Mon Sep 17 00:00:00 2001 From: Maxime Brazeilles Date: Fri, 21 Oct 2016 10:35:31 +0200 Subject: [PATCH 4/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 13165cc..cc5fc1f 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dependencies": { "gulp": "^3.9.0", "gulp-util": "^3.0.7", - "mjml": "~3.0.0", + "mjml": "^3.0.0", "through2": "^2.0.0" } }