UNPKG

969 BJavaScriptView Raw
1// Dependencies ---------------------------------------------------------------
2var Task = require('../lib/task/Task'),
3 mustache = require('mustache');
4
5
6// Template Task --------------------------------------------------------------
7var template = {
8
9 mode: Task.Each,
10 data: true,
11
12 map: function(e, file) {
13 return file;
14 },
15
16 run: function(e, done) {
17
18 var locals;
19 if (typeof e.config.data === 'function') {
20 locals = e.config.data(e);
21
22 } else {
23 locals = e.config.data;
24 }
25
26 var template = mustache.compile(e.data.toString(), e.config.tags);
27 done(null, template(locals));
28
29 }
30
31};
32
33
34// Factory --------------------------------------------------------------------
35module.exports = {
36
37 task: function(pattern, data, tags) {
38 return new Task('Template', pattern, template, {
39 data: data,
40 tags: tags || mustache.tags
41 });
42 }
43
44};
45