Created
September 16, 2012 05:29
-
-
Save twolfson/3731124 to your computer and use it in GitHub Desktop.
Grunt mustache re-implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// At this time, grunt-mustache was giving me shit so I rewrote it for what I needed... | |
module.exports = function (grunt) { | |
// Project configuration. | |
grunt.initConfig({ | |
mustache: { | |
template: { | |
src: 'template.svg.mustache', | |
dest: 'template.svg', | |
partials: 'partials/*.mustache' | |
} | |
}, | |
watch: { | |
mustache: { | |
files: '<config:mustache.template.src>', | |
tasks: 'mustache' | |
} | |
} | |
}); | |
// Load local tasks. | |
var mustache = require('mustache'), | |
fs = require('fs'), | |
path = require('path'); | |
grunt.registerMultiTask('mustache', 'Render mustache files', function () { | |
var data = this.data, | |
srcFile = data.src, | |
srcContent = grunt.file.read(srcFile), | |
partials = data.partials || [], | |
partialArr = grunt.file.expandFiles(partials), | |
partialMap = {}; | |
partialArr.forEach(function (partial) { | |
var partialItem = grunt.file.read(partial), | |
filename = path.basename(partial, '.mustache'); | |
partialMap[filename] = partialItem; | |
}); | |
var retVal = mustache.render(srcContent, {}, partialMap), | |
destFile = data.dest; | |
grunt.file.write(destFile, retVal); | |
}); | |
// Default task. | |
grunt.registerTask('default', 'mustache'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment