<commit_before>var fs = require('fs'),
  parser = require('./parser')();

module.exports = function(ioServer, options) {

  var loadVariables,
    saveVariables,
    reloadStyles,
    currentSocket,
    io = ioServer;

  if (!fs.existsSync(options.styleVariables)) {
    console.error('Could not find SASS variables file', options.styleVariables);
    return;
  }

  loadVariables = function(socket) {
    return function() {
      var syntax = path.extname(options.styleVariables).substring(1);
      fs.readFile(options.styleVariables, {encoding: 'utf8'}, function(err, data) {
        var values = {};
        if (err) {
          return console.error(err);
        }
        values = parser.parseVariables(data, syntax);
        socket.emit('variables from server', values);
        console.log('EVENT: variables from server');
      });
    };
  };

  saveVariables = function(socket) {
    return function(variables) {
      fs.readFile(options.styleVariables, {encoding: 'utf8'}, function(err, originalData) {
        var data = parser.setVariables(originalData, variables);
        fs.writeFile(options.styleVariables, data, function(err, data) {
          if (err) {
            return console.error(err);
          }
          socket.emit('variables saved to server', data);
          console.log('EVENT: variables saved to server');
        });
      });
    };
  };

  emitChanges = function() {
    io.sockets.emit('styles changed');
  };

  io.on('connection', function(socket) {
    console.log('Socket connection established (id:', socket.conn.id + ')');
    socket.on('request variables from server', loadVariables(socket));
    socket.on('variables to server', saveVariables(socket));
  });

  return {
    emitChanges: emitChanges
  }
};<commit_msg>Pass syntax when setting variables<commit_after>var fs = require('fs'),
  path = require('path'),
  parser = require('./parser')();

module.exports = function(ioServer, options) {

  var loadVariables,
    saveVariables,
    reloadStyles,
    currentSocket,
    io = ioServer;

  if (!fs.existsSync(options.styleVariables)) {
    console.error('Could not find SASS variables file', options.styleVariables);
    return;
  }

  loadVariables = function(socket) {
    return function() {
      var syntax = path.extname(options.styleVariables).substring(1);
      fs.readFile(options.styleVariables, {encoding: 'utf8'}, function(err, data) {
        var values = {};
        if (err) {
          return console.error(err);
        }
        values = parser.parseVariables(data, syntax);
        socket.emit('variables from server', values);
        console.log('EVENT: variables from server');
      });
    };
  };

  saveVariables = function(socket) {
    return function(variables) {
      var syntax = path.extname(options.sassVariables).substring(1);
      fs.readFile(options.styleVariables, {encoding: 'utf8'}, function(err, originalData) {
        var data = parser.setVariables(originalData, syntax, variables);
        fs.writeFile(options.styleVariables, data, function(err, data) {
          if (err) {
            return console.error(err);
          }
          socket.emit('variables saved to server', data);
          console.log('EVENT: variables saved to server');
        });
      });
    };
  };

  emitChanges = function() {
    io.sockets.emit('styles changed');
  };

  io.on('connection', function(socket) {
    console.log('Socket connection established (id:', socket.conn.id + ')');
    socket.on('request variables from server', loadVariables(socket));
    socket.on('variables to server', saveVariables(socket));
  });

  return {
    emitChanges: emitChanges
  }
};
{'fraction_non_alphanumeric': 0.13989071038251366, 'fraction_numerical': 0.001912568306010929, 'mean_word_length': 3.04083885209713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6284887', 'n_tokens_mistral': 1019, 'n_tokens_neox': 1004, 'n_words': 226}