<commit_before>module.exports = (function(){




})();<commit_msg>Started implement the core features of the template engine.<commit_after>/**
 * Main entry point for the just-template-it module.
 */

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





module.exports = (function() {
  var _templatePath = ""; // Path to the templates base directory.
  var _loadedFiles = {};  // Files already loaded, stored in memory.

  /**
   * Fetch template file from filesystem.
   * @param {string} type File name (without end or path).
   * @param {function} callback Callback to fire on done: function(error, fileAsString) - where error will be undefined if no error.
   */
  var getFile = function(type, callback) {
    if(_loadedFiles[type] !== undefined) {
      callback(undefined , _loadedFiles[type]);
    } else {
      var path = _templatePath + type + ".jti";
      fs.exists(path, function(exists){
        if(!exists) {
          callback(util.format("Failed to fetch template. File does not exist. (%s)", path));
        } else {
          fs.readFile(path, function(error, data){
            if(error) {
              callback("Failed to fetch template. Failed to read file.");
            } else {
              _loadedFiles[type] = data.toString();
              getFile(type, callback);
            }
          });
        }
      });
    }
  };

  var includeRegex = new RegExp("\\{include\\|(.+)\\}", 'g');

  /**
   * Replaces all {include\} tags with the included file.
   * @param {string} template Loaded template to replace includes in.
   * @param {function} callback Callback to fire on done: function(error, templateAsString) - where error will be undefiend if no error.
   */
  var includes = function(template, callback) {
    if(data.indexOf("{include|") === -1){
      callback(undefined, template);
    } else {
      var match;
      var includes = [];
      while((match = includeRegex.exec(template)) !== null) {
        includes.push(match[1]);
      }
      var isError = null;
      var count = 0;

      for(var i=includes.length;i-->0;) {
        count++;
        var curr = includes[i];
        getFile(curr, function(error, includedFile){
          if(error){

          }
        });
      }


    }
  };



  /**
   * Initialize the Template engine.
   * @param {string} templatePath Path to the template files base directory.
   */
  this.init = function(templatePath) {
    _templatePath = templatePath;

  };

  /**
   * Change the path of the templates base directory.
   * Observe, this will truncate the currently loaded template files.
   * @param {string} newPath Path to the template files base directory.
   */
  this.setTemplatePath = function(newPath) {
    _templatePath = newPath;
    _loadedFiles = [];
  };

  /**
   * Fetch a template and set the parameters with the given data object.
   * @param {string} template Template name.
   * @param {object} data Data object.
   * @param {function} callback Callback to fire on done: function(error, loadedTemplateAsString) - where error will be undefined if no error.
   */
  this.getTemplate = function(template, data, callback) {
    getFile(template, function(error, data){
      if(error){
        callback(error);
      } else {

      }
    });
  };

  return this;
})();

{'fraction_non_alphanumeric': 0.1286193233770192, 'fraction_numerical': 0.0012191405059433099, 'mean_word_length': 2.517684887459807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2284581', 'n_tokens_mistral': 941, 'n_tokens_neox': 913, 'n_words': 294}