-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from mjmlio/mjml3
MJML 3 : fix #11
- Loading branch information
Showing
5 changed files
with
54 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')) | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<mjml> | ||
<mj-body> | ||
<mj-container> | ||
<mj-section> | ||
<mj-column> | ||
|
||
<mj-image width="100" src="/assets/img/logo-small.png"></mj-image> | ||
|
||
<mj-divider border-color="#F45E43"></mj-divider> | ||
|
||
<mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello World</mj-text> | ||
|
||
</mj-column> | ||
</mj-section> | ||
</mj-container> | ||
</mj-body> | ||
</mjml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
} |