gulp-swig
gulp-swig copied to clipboard
Added option to not extend file.data.
When using an auto generated json file such as the manifest from a cache buster, the generated keys may not be valid variable names in Swig.
{"js/script.js":"js/script.da39a3ee.js"}
To overcome this, a new option extend_filedata
has been added. When set to false
it sets file.data
to data.filedata
instead of extending data
. This allows a user to use bracket-notation to access the invalid variable in Swig.
{{ filedata['js/script.js'] }}
By default extend_filedata
is true
.
Have you looked into the gulp-data
plugin? You could do something like:
/*
Get data via JSON file, keyed on filename.
*/
var swig = require('gulp-swig');
var data = require('gulp-data');
var getJsonData = function(file) {
var data = {"js/script.js":"js/script.da39a3ee.js"};
return { filedata: data }
};
gulp.task('json-test', function() {
return gulp.src('./examples/test1.html')
.pipe(data(getJsonData))
.pipe(swig())
.pipe(gulp.dest('build'));
});