-
-
Save qrg/28a15390f92719536d02 to your computer and use it in GitHub Desktop.
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
| 'use strict'; | |
| const through = require('through2'); | |
| const yaml = require('js-yaml'); | |
| const ejs = require('ejs'); | |
| const gutil = require('gulp-util'); | |
| module.exports = (template) => { | |
| return through.obj(function (file, enc, cb) { | |
| if (file.isNull()) { | |
| this.push(file); | |
| return cb(); | |
| } | |
| if (file.isStream()) { | |
| this.emit( | |
| 'error', | |
| new gutil.PluginError('gulp-ejs', 'Streaming not supported') | |
| ); | |
| } | |
| const data = yaml.safeLoad(file.contents.toString()); | |
| file.path = gutil.replaceExtension(file.path, '.html'); | |
| try { | |
| file.contents = new Buffer( | |
| ejs.render(template, data) | |
| ); | |
| } catch (err) { | |
| this.emit('error', new gutil.PluginError('gulp-ejs', err.toString())); | |
| } | |
| this.push(file); | |
| cb(); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment