gulp-swig
gulp-swig copied to clipboard
clone(options) breaks ability to pass data around.
The way the code is now it breaks when you need to run a function from the html that is defined in the context. The way it is now, variables are static once they are passed into swig and they are unable to be modified.
var opts = options ? clone(options) : {};
should be
var opts = options ? options : {};
Can you give me an example or write a test showing that it breaks? That will help clarify what you're talking about. Thanks.
index.html
{{ pushToArray('something') }}
{{myArray}}
gulpfile.js
var gulp = require('gulp');
gulp.task('default', function() {
var swig = require('gulp-swig');
var ctx = {
data: {
pushToArray: function(style){
ctx.data.myArray.push(style);
return '';
},
myArray: []
}
};
return gulp.src('index.html')
.pipe(swig(ctx))
.pipe(gulp.dest("output"));
});
the output folder that gets generated will contain a index.html
the way gulp-swig is now myArray never gets updated. and so the output is blank. if you make the change i suggested, you will see the the array does get updated.
The problem is that the clone breaks the reference to the original object because it makes a brand new object instead of passing the reference to the one already created.