<commit_before>module.exports = function PublishPreview(app,io, settings){


	//imports
        var fs = require('fs'),
	    path = require('path'),
	    //io = require('socket-io'),
            _ = require('underscore'),
	    createContext = require('./js/context');

	var rooms, contexts, htmls;

	var defaults = {
		publish: defaultPublish,
		save: defaultSave,
		views: app.get('views'),
		engines: {},
		templates: {},
		defaultExt: app.get('view engine')
	};

	function init() {
	    rooms = []; 
	    contexts = [];
	    htmls = {};

	    settings = settings || {};	 
	    console.log(settings);
	    _.extend(defaults, settings);
	    settings = defaults;
	    console.log(settings);
	}

	function renderString(name) {
		var extension = path.extname(name) || settings.defaultExt;
		return settings.engines[extension] || require('nunjucks').renderString;
	}

	function render(filepath, ops, fn) {
	  var basename = path.relative(settings.views, filepath),
	      globals = {},
	      template = settings['templates'][basename] || {},
	      renderFn = renderString(basename);

	 initTemplate(basename);
	 /* if(template) {
		globals.template = _.each(template, function(type,field, t) {
		  t[field] = '';
		});
	  }*/

	//  var extract = require('./extract');
	  fs.readFile(filepath, {encoding:'utf8'},function(error,data){
	   if(error) {
	    console.error(error);
	    return fn('Cannot get ' + basename);
	   }   

	   console.log(data);

	   function rigMarkup(match, p0, p1, p2, p3, p4, p5, p6, offset, string) {
		var head = p0 + p1 + renderStyle() + p2;
		var wrapper = '<div id="gnp-wrap">' + renderOverlayTemplate() + p5 + '</div>';

		htmls[basename] = {
			 wrapper: wrapper,
			 head: head
		}

		return head + p3 + p4 + wrapper + renderScripts() + p6;
	   }

	   function renderScripts() {
	     //var script = '<script>console.log(1)</script>';
	     var script = fs.readFileSync(__dirname + '/views/script.html', {encoding:'utf8'});     
	     return renderFn(script, {});     
	   }
	   
	   /*function insertClass(match, p1, p2, p3, p4, offset, string){
	     var index = p1.indexOf('class="');
	     var addition = 'data-gnp-value="' + 
			     escape(p2) + 
                             '" data-gnp-key=' + 
                             p4.trim() + 
                             ' class="gnp-watch' 
	     if(index === -1) {
	       return p1.substring(0, p1.length - 1) + ' ' + addition + '">' + p2;
	     }
	    
	     return p1.replace(/class="/, function(match, p5, offset, string) {
	       return  addition + ' ';
	     }) + p2 + p3;
	   }

	   function injectInBody(match, p1, offset, string) {
	     return renderScripts() + 
		    p1; 
	   }*/

           

	   function renderOverlayTemplate() {

	    var overlay = fs.readFileSync(__dirname + '/views/overlay.html', {encoding: 'utf8'});
	    
	    var keys = Object.keys(template.fields);
	    var fields = [];
	    for(var i = 0; i < keys.length; i++) {
	     var field = {};
	     field['legend'] = keys[i];
	     field['type'] = template.fields[keys[i]];
	     fields.push(field);
	    }    

	    var renderContext = {};
	    renderContext.fields = fields;
	    renderContext.opentag = '{{';
	    renderContext.closetag = '}}';

	    return renderFn(overlay,renderContext);
	   }

	   function renderStyle() {
	    var css = fs.readFileSync(__dirname + '/css/style.css', {encoding:'utf8'});
	    return '<style>' + css + '</style>';<commit_msg>fixed template/object keys bug<commit_after>module.exports = function PublishPreview(app,io, settings){


	//imports
        var fs = require('fs'),
	    path = require('path'),
	    //io = require('socket-io'),
            _ = require('underscore'),
	    createContext = require('./js/context');

	var rooms, contexts, htmls;

	var defaults = {
		publish: defaultPublish,
		save: defaultSave,
		views: app.get('views'),
		engines: {},
		templates: {},
		defaultExt: app.get('view engine')
	};

	function init() {
	    rooms = []; 
	    contexts = [];
	    htmls = {};

	    settings = settings || {};	 
	    console.log(settings);
	    _.extend(defaults, settings);
	    settings = defaults;
	    console.log(settings);
	}

	function renderString(name) {
		var extension = path.extname(name) || settings.defaultExt;
		return settings.engines[extension] || require('nunjucks').renderString;
	}

	function render(filepath, ops, fn) {
	  var basename = path.relative(settings.views, filepath),
	      globals = {},
	      template = settings['templates'][basename] || {},
	      renderFn = renderString(basename);

	 initTemplate(basename);
	 /* if(template) {
		globals.template = _.each(template, function(type,field, t) {
		  t[field] = '';
		});
	  }*/

	//  var extract = require('./extract');
	  fs.readFile(filepath, {encoding:'utf8'},function(error,data){
	   if(error) {
	    console.error(error);
	    return fn('Cannot get ' + basename);
	   }   

	   console.log(data);

	   function rigMarkup(match, p0, p1, p2, p3, p4, p5, p6, offset, string) {
		var head = p0 + p1 + renderStyle() + p2;
		var wrapper = '<div id="gnp-wrap">' + renderOverlayTemplate() + p5 + '</div>';

		htmls[basename] = {
			 wrapper: wrapper,
			 head: head
		}

		return head + p3 + p4 + wrapper + renderScripts() + p6;
	   }

	   function renderScripts() {
	     //var script = '<script>console.log(1)</script>';
	     var script = fs.readFileSync(__dirname + '/views/script.html', {encoding:'utf8'});     
	     return renderFn(script, {});     
	   }
	   
	   /*function insertClass(match, p1, p2, p3, p4, offset, string){
	     var index = p1.indexOf('class="');
	     var addition = 'data-gnp-value="' + 
			     escape(p2) + 
                             '" data-gnp-key=' + 
                             p4.trim() + 
                             ' class="gnp-watch' 
	     if(index === -1) {
	       return p1.substring(0, p1.length - 1) + ' ' + addition + '">' + p2;
	     }
	    
	     return p1.replace(/class="/, function(match, p5, offset, string) {
	       return  addition + ' ';
	     }) + p2 + p3;
	   }

	   function injectInBody(match, p1, offset, string) {
	     return renderScripts() + 
		    p1; 
	   }*/

           

	   function renderOverlayTemplate() {

	    var overlay = fs.readFileSync(__dirname + '/views/overlay.html', {encoding: 'utf8'});
	    
	    var fields = [];
	    if(template.fields) {
		    var keys = Object.keys(template.fields);
		    for(var i = 0; i < keys.length; i++) {
		     var field = {};
		     field['legend'] = keys[i];
		     field['type'] = template.fields[keys[i]];
		     fields.push(field);
		    }    
	    }
	    var renderContext = {};
	    renderContext.fields = fields;
	    renderContext.opentag = '{{';
	    renderContext.closetag = '}}';

	    return renderFn(overlay,renderContext);
	   }

	   function renderStyle() {
	    var css = fs.readFileSync(__dirname + '/css/style.css', {encoding:'utf8'});
	    return '<style>' + css + '</style>';
{'fraction_non_alphanumeric': 0.16645031011106304, 'fraction_numerical': 0.01125054089138901, 'mean_word_length': 2.437778879524046, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3778145', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2173, 'n_words': 449}