'use strict';

var fs = require('fs');
var path = require('path');

var _ = require('underscore');

function Generator(templateFile, targetFile) {
  templateFile = path.join(__dirname,
    '..',
    'templates',
    templateFile);
  var templateContent = fs.readFileSync(templateFile, {
    encoding: 'utf8'
  });

  this._template = _.template(templateContent);
  this._targetFile = targetFile;

  return this;
}

Generator.prototype.render = function (data, callback) {
  var output = this._template(data)
    .replace(/^\s*[\r\n]/gm, '\n');
  fs.writeFile(this._targetFile, output, callback);
};

module.exports = Generator;

@@ -523,14 +523,10 @@
 %5E%5Cs*
-%5B%5Cr
 %5Cn
-%5D
 /gm,

Support only \n as newline control character