simon-dt / gulp-twig

Twig plugin for gulp.js, The streaming build system. Looking for maintainer or collaborators. See wiki
https://github.com/zimmen/gulp-twig/wiki/Looking-for-maintainer-or-collaborator(s)
MIT License
62 stars 33 forks source link

Actual example of gulp-data use #56

Open WojoJustin opened 6 years ago

WojoJustin commented 6 years ago

I've only been able to make this work by providing a function to process a JSON file directly through the twig initialization in gulp:

return gulp.src(paths.src)
    .on('error', handleErrors)
    .pipe(twig({
              data: {
                "tables": function(file) {
                  var dataPath = path.resolve(config.root.src, config.tasks.html.src, config.tasks.html.dataFile);

                  var data = JSON.parse(fs.readFileSync(dataPath, 'utf8'));

                  return data;
                }
              }
    }))
    .on('error', handleErrors)
    .pipe(gulp.dest(paths.dest))

running:

.pipe(data(function (file) {
    return JSON.parse(fs.readFileSync('./examples/' + path.basename(file.path) + '.json'));
}))
.pipe(twig())

has not worked at all. gulp-data has been returning the actual gulp information and not my json file data. There's also no way to configure how this data is defined in the template.