UNPKG

gulp-twig2html

Version:

Gulp plugin that compile twig templates to html pages

31 lines (25 loc) 852 B
'use strict'; const TwigRenderer = require('@toptalo/twig-renderer'); const through = require('through2'); const PluginError = require('plugin-error'); const PLUGIN_NAME = 'gulp-twig2html'; module.exports = params => { const twigRenderer = new TwigRenderer(params); return through.obj(function (file, enc, callback) { if (file.isNull()) { callback(null, file); return; } if (file.isStream()) { throw new PluginError(PLUGIN_NAME, 'Streaming not supported'); } else { twigRenderer.render(file.path).then(html => { file.contents = new Buffer(html); this.push(file); callback(); }).catch(error => { throw new PluginError(PLUGIN_NAME, error.message); }); } }); };