Code coverage report for tasks/wrappers/jade.js

Statements: 35.71% (10 / 28)      Branches: 100% (0 / 0)      Functions: 0% (0 / 7)      Lines: 35.71% (10 / 28)      Ignored: none     

All files » tasks/wrappers/ » jade.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411 1 1 1 1   1           1                 1                 1                   1
var Promise = require('es6-promise').Promise;
var path = require('path');
var jade = require('jade');
var fs = require('../utils/fs');
var File = require('../utils/file');
 
function Jade(location, destination, options){
    this.location = location;
    this.destination = destination;
    this.options = options;
}
 
Jade.prototype.renderFile = function(fileObj){
    var replacements = this.options;
    var render = jade.compile(fileObj.contents.toString('utf-8'), { filename: fileObj.path, pretty: true });
    var outFile = path.join(this.destination,fileObj.relativeDir, fileObj.name);
    var file = new File({path: outFile, contents:render(replacements)});
    file.ext = 'html';
    return file;
};
 
Jade.prototype.render = function(fileObjs){
    var self = this;
    var promises = [];
    fileObjs.forEach(function(fileObj){
        promises.push(self.renderFile(fileObj));
    });
    return Promise.all(promises);
};
 
Jade.prototype.write = function(){
    var self = this;
    return fs.read(this.location)
        .then(function(fileObjs){
            return self.render(fileObjs);
        }).then(function(fileObjs){
            return fs.write(fileObjs);
        });
};
 
module.exports = Jade;