Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to not extend file.data. #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

scottfalkingham
Copy link

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.

@colynb
Copy link
Owner

colynb commented Nov 27, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants