Skip to content

Instantly share code, notes, and snippets.

@dervalp
Created October 18, 2012 07:13
Show Gist options
  • Select an option

  • Save dervalp/3910258 to your computer and use it in GitHub Desktop.

Select an option

Save dervalp/3910258 to your computer and use it in GitHub Desktop.
Blanket - more object oriented ?
/**
* Module Depedencies
*/
var path = require('path');
/**
* Export
*/
exports = module.exports = Blanket;
/**
* CTO
* @options
* {
* files: {
* "filename" : @content
* }
* }
*/
function Blanket(options){
this.root = options.root;
this.dest: options.dest;
this.files: options.filesContent;
this.onEachFileInstrumented: options.onEachFileInstrumented;
this.onInstrumented = options.onInstrumented;
}
/**
* Instrument file
*/
Blanket.prototype.instrumented = function(){
var files = this.files,
root = this.root,
dest = this.dest;
for(var file in files)
{
//TODO, move in private function
var fileContent = files[file];
var fileName = file;
var instrumentFileName = filename.replace(root, dest);
var lines = inFile.split("\n");
var instrumented = "";
//TODO, we need to actually parse the js a bit,
//or adding these lines can cause unprocessable js
//set up namespace
instrumented += "if (typeof _$blanket === 'undefined') { _$blanket = {}; }\n";
//initialize file object
instrumented += "_$blanket['"+inFileName+"']=[];\n";
//initialize array values
for (var j=0;j <lines.length; j++){
instrumented += "_$blanket['"+inFileName+"']["+j+"]=0;\n";
}
for (var i=0; i<lines.length; i++){
instrumented += "_$blanket['"+inFileName+"']["+i+"]++;\n";
instrumented += lines[i]+"\n";
}
this.onEachFileInstrumented(instrumentFileName, instrumented);
}
this.onInstrumented();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment