Created
October 25, 2015 20:40
-
-
Save venning/3346d78d1e6a27a2ebdd to your computer and use it in GitHub Desktop.
Handlebars-based version of gulp-template
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
'use strict'; | |
var through = require('through2'); | |
var PluginError = require('gulp-util').PluginError; | |
var Handlebars = require('handlebars'); | |
var PLUGIN_NAME = 'gulp-handlebars-template'; | |
// partly taken from: https://github.com/gulpjs/gulp/blob/master/docs/writing-a-plugin/guidelines.md | |
// partly taken from: https://github.com/sindresorhus/gulp-template/blob/master/index.js | |
module.exports = function (context) { | |
return through.obj(function (file, enc, cb) { | |
if (file.isNull()) { | |
return cb(null, file); | |
} | |
if (file.isStream()) { | |
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported')); | |
} | |
var template = Handlebars.compile(file.contents.toString()); | |
file.contents = new Buffer(template(context)); | |
cb(null, file); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment