adamayres / gulp-wrap

A gulp plugin to wrap the stream contents with a lodash template.

Home Page:https://www.npmjs.com/package/gulp-wrap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to pass front-matter value to template src?

tomgenoni opened this issue · comments

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))
});

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));
});