adamayres / gulp-wrap

A gulp plugin to wrap the stream contents with a lodash template.
https://www.npmjs.com/package/gulp-wrap
MIT License
84 stars 17 forks source link

Possible to pass front-matter value to template src? #25

Closed tomgenoni closed 8 years ago

tomgenoni commented 9 years ago

The following is incorrect but illustrates what I'm trying to do: pull the value set for template in each of the source file's front matter and pass it src of the wrap. Is this doable?

gulp.task('build', function() {
  gulp.src('./content/**/*.md')
    .pipe(frontMatter({
      property: 'data'
    }))
    .pipe(wrap({
      src: <% data.template %>
    }))
    .pipe(gulp.dest(paths.build))
});
adamayres commented 8 years ago

Something we could add is allowing the src parameter of the template object taking a function that has the file in the callback, however the library is on the verge of having too many fancy options like this. I suggest using something like gulp-tap to handle this:

var gulp = require('gulp');
var wrap = require('gulp-wrap');
var frontMatter = require('gulp-front-matter');
var tap = require('gulp-tap');

gulp.task('wrap', function () {
  gulp.src(srcPattern)
    .pipe(frontMatter({
      property: 'data'
    }))
    .pipe(tap(function(file, t) {
      // you could optionally pass this into a gulp.src with a custom dest
      // and return the stream to prevent it from using the original dest
      t.through(wrap, [{ src: file.data.src }]);
    }))
    .pipe(gulp.dest(dest));
});