Created
May 13, 2014 11:16
-
-
Save morlay/2a0116d06c023c4cec26 to your computer and use it in GitHub Desktop.
twig through gulp
This file contains hidden or 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
| var Twig = require('twig'); | |
| var es = require('event-stream'); | |
| var gutil = require('gulp-util'); | |
| var PluginError = gutil.PluginError; | |
| var ext = gutil.replaceExtension; | |
| module.exports = function (options) { | |
| var opts = options || {}; | |
| function compileTwig(file, callback) { | |
| var data = opts.data || {}; | |
| if (file.isStream()) { | |
| this.emit('error', new gutil.PluginError('gulp-twig', 'Streaming not supported')); | |
| callback(); | |
| } | |
| Twig.twig({ | |
| path: file.path, | |
| base: file.base, | |
| load: function (template) { | |
| file.contents = new Buffer(template.render(data), 'utf-8'); | |
| file.path = ext(file.path, '.html'); | |
| console.log('file', file.path.substr(file.base.length), 'created'); | |
| callback(null, file); | |
| } | |
| }); | |
| } | |
| return es.map(compileTwig); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment