Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grunt.loadNpmTasks('grunt-prettify');
- module.exports = function(grunt) {
- // Create basic grunt config (e.g. watch files)
- grunt.initConfig({
- pkg: grunt.file.readJSON('package.json'),
- watch: {
- grunt: { files: ['gruntfile.js'] },
- jade: {
- files: 'src/*.jade',
- tasks: ['jade']
- }
- }
- });
- // Load json to populate jade templates and build loop
- var json = grunt.file.readJSON('template.json');
- for(var i = 0; i < json.length; i++) {
- var obj = json[i];
- // For each json item create a new jade task with a custom 'target' name.
- // Because a custom target is provided don't nest options/data/file parameters
- // in another target like 'compile' as grunt wont't be able to find them
- // Make sure that functions are called using immediate invocation or the variables will be lost
- grunt.config(['jade', obj.filename], {
- options: {
- // Pass data to the jade template
- data: (function(dest, src) {
- return {
- myJadeName: obj.myname,
- myDesc: obj.desc,
- from: src,
- to: dest
- };
- }()) // <-- n.b. using() for immediate invocation
- },
- // Add files using custom function
- files: (function() {
- var files = {};
- files['build/' + obj.filename + '.html'] = 'src/index.jade';
- return files;
- }()) // <-- n.b. using () for immediate invocation
- });
- }
- grunt.loadNpmTasks('grunt-contrib-jade');
- grunt.loadNpmTasks('grunt-contrib-watch');
- grunt.loadNpmTasks('grunt-prettify');
- // Register all the jade tasks using top level 'jade' task
- // You can also run subtasks using the target name e.g. 'jade:whatever'
- grunt.registerTask('default', ['jade', 'watch']);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement