Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. grunt.loadNpmTasks('grunt-prettify');
  2.  
  3. module.exports = function(grunt) {
  4.  
  5. // Create basic grunt config (e.g. watch files)
  6.  
  7. grunt.initConfig({
  8. pkg: grunt.file.readJSON('package.json'),
  9. watch: {
  10. grunt: { files: ['gruntfile.js'] },
  11. jade: {
  12. files: 'src/*.jade',
  13. tasks: ['jade']
  14. }
  15. }
  16. });
  17.  
  18. // Load json to populate jade templates and build loop
  19.  
  20. var json = grunt.file.readJSON('template.json');
  21.  
  22. for(var i = 0; i < json.length; i++) {
  23. var obj = json[i];
  24.  
  25. // For each json item create a new jade task with a custom 'target' name.
  26. // Because a custom target is provided don't nest options/data/file parameters
  27. // in another target like 'compile' as grunt wont't be able to find them
  28.  
  29. // Make sure that functions are called using immediate invocation or the variables will be lost
  30.  
  31. grunt.config(['jade', obj.filename], {
  32. options: {
  33. // Pass data to the jade template
  34. data: (function(dest, src) {
  35. return {
  36. myJadeName: obj.myname,
  37. myDesc: obj.desc,
  38. from: src,
  39. to: dest
  40. };
  41. }()) // <-- n.b. using() for immediate invocation
  42. },
  43.  
  44. // Add files using custom function
  45.  
  46. files: (function() {
  47. var files = {};
  48. files['build/' + obj.filename + '.html'] = 'src/index.jade';
  49. return files;
  50. }()) // <-- n.b. using () for immediate invocation
  51. });
  52.  
  53. }
  54.  
  55. grunt.loadNpmTasks('grunt-contrib-jade');
  56. grunt.loadNpmTasks('grunt-contrib-watch');
  57. grunt.loadNpmTasks('grunt-prettify');
  58.  
  59.  
  60. // Register all the jade tasks using top level 'jade' task
  61. // You can also run subtasks using the target name e.g. 'jade:whatever'
  62.  
  63. grunt.registerTask('default', ['jade', 'watch']);
  64. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement