UNPKG

757 BJavaScriptView Raw
1var map = require('map-stream');
2var rext = require('replace-ext');
3
4module.exports = function (options) {
5 'use strict';
6 if (!options) {
7 options = {};
8 }
9
10 function modifyContents(file, cb) {
11 if (file.isNull()) {
12 return cb(null, file);
13 }
14
15 if (file.isStream()) {
16 return cb(new Error('gulp-twig: Streaming not supported'));
17 }
18
19 var Twig = require('twig'),
20 twig = Twig.twig,
21 template = twig({
22 path: file.path,
23 async: false
24 });
25
26 file.contents = new Buffer(template.render(options.data));
27 file.path = rext(file.path, '.html');
28 cb(null, file);
29 }
30
31 return map(modifyContents);
32};