<commit_before>'use strict';

var twig             = require('twig').twig;
var through          = require('through2');
var minify           = require('html-minifier').minify;
var autoElemsFromDom = require('auto-elems-from-dom');

var ext = /\.(twig)$/;

var minifyDefaults = {
  removeComments: true,
  collapseWhitespace: true
};

function compile(id, str) {
  var minified = minify(str, minifyDefaults);

  var template = twig({
    id: id,
    data: minified
  });

  var tokens = JSON.stringify(template.tokens);
  // the id will be the filename and path relative to the require()ing module
  return 'function(data) {'+
    '  var template = twig({'+
    '    id: __filename,'+
    '    data:' + tokens + ','+
    '    precompiled: true,'+
    '    allowInlineIncludes: true'+
    '  });'+
    '  var fragment = autoElemsFromDom(' +
    '    template.render(data),' +
    '    \'attr\',' +
    '    \'data-dootify\',' +
    '    true' +
    '  );'+
    '  return fragment;'+
    '}';
}<commit_msg>fix for same id<commit_after>'use strict';

var twig             = require('twig').twig;
var through          = require('through2');
var minify           = require('html-minifier').minify;
var autoElemsFromDom = require('auto-elems-from-dom');

var ext = /\.(twig)$/;

var minifyDefaults = {
  removeComments: true,
  collapseWhitespace: true
};

function compile(id, str) {
  var minified = minify(str, minifyDefaults);

  // check if template already exists
  var template = twig({ ref: id });
  if (!template) {
    template = twig({
      id: id,
      data: minified
    });
  }

  var tokens = JSON.stringify(template.tokens);
  // the id will be the filename and path relative to the require()ing module
  return 'function(data) {'+
    '  var template = twig({'+
    '    id: __filename,'+
    '    data:' + tokens + ','+
    '    precompiled: true,'+
    '    allowInlineIncludes: true'+
    '  });'+
    '  var fragment = autoElemsFromDom(' +
    '    template.render(data),' +
    '    \'attr\',' +
    '    \'data-dootify\',' +
    '    true' +
    '  );'+
    '  return fragment;'+
    '}';
}
{'fraction_non_alphanumeric': 0.16516373991457048, 'fraction_numerical': 0.0009492168960607499, 'mean_word_length': 2.5016611295681064, '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': '150370', 'n_tokens_mistral': 723, 'n_tokens_neox': 697, 'n_words': 164}