In Grunt, you can set options per target or per task:
jade: {
options: { /* task level options */ },
htmlA: { // <- this is a target name
options: {
// target level options override the task level
client: false,
pretty: true,
data: grunt.file.readJSON("src/A/data.json")
},
src: 'src/A/index.jade',
dest: 'build/A/index.html'
},
htmlB: {
options: {
client: false,
pretty: true,
data: grunt.file.readJSON("src/B/data.json")
},
src: 'src/B/index.jade',
dest: 'build/B/index.html'
},
}
Although the data
option in grunt-contrib-jade accepts a function as well so it might be better to do it more programmatically:
jade: {
html: {
options: {
client: false,
pretty: true,
data: function(dest, src) {
var path = require('path');
// Resolve data.json in the first src folder
return grunt.file.readJSON(path.resolve(path.dirname(src[0]), 'data.json'));
}
},
files: (function() {
var files = {};
// Build A-Z files
for (var i = 65; i <= 90; i++) {
var chr = String.fromCharCode(i);
files['build/' + chr + '/index.html'] = 'src/' + chr + '/index.jade';
}
return files;
}())
}
}