<commit_before>/**
 * Pre-compiles templates using Ractive and returns a module with all dependencies required
 *
 * Copyright 2015 Wayfair, LLC
 * Available under the Apache Version 2.0 License
 *
 * https://github.com/wayfair/tungstenjs
 *
 * @license Apache-2.0
 */
'use strict';

var path = require('path');
var _ = require('underscore');
var utils = require('./shared_utils');

/**
 * Compiles given templates
 * @param  {String} contents Root directory of templates to get stripped off partials
 */
module.exports = function(contents, templateFileExt, useWebpack) {
  templateFileExt = typeof templateFileExt !== 'undefined' ? templateFileExt : 'mustache';
  useWebpack = typeof useWebpack !== 'undefined' ? useWebpack : false;
  if (useWebpack) {
    this.cacheable();
  }
  var parsedTemplate = utils.compileTemplate(contents, module.src);
  var partials = utils.findPartials(parsedTemplate);
  utils.handleDynamicComments(parsedTemplate);
  var template = JSON.stringify(parsedTemplate);

  var templatePath = path.relative(path.dirname(module.dest), __dirname + '/template');
  templatePath = templatePath.replace(/\\/g, '/');

  var output = 'var Template=require("tungstenjs/src/template/template");';
  output += 'var template=new Template(' + template + ');';
  output += 'module.exports=template;';
  if (_.size(partials) > 0) {
    output += 'template.setPartials({';
    output += _.map(partials, function(v, partial) {
      return '"' + partial + '":require("./' + partial + '.' + templateFileExt + '")';
    }).join(',');
    output += '});';
  }

  return output;
};
<commit_msg>Changing default to use webpack<commit_after>/**
 * Pre-compiles templates using Ractive and returns a module with all dependencies required
 *
 * Copyright 2015 Wayfair, LLC
 * Available under the Apache Version 2.0 License
 *
 * https://github.com/wayfair/tungstenjs
 *
 * @license Apache-2.0
 */
'use strict';

var path = require('path');
var _ = require('underscore');
var utils = require('./shared_utils');

/**
 * Compiles given templates
 * @param  {String} contents Root directory of templates to get stripped off partials
 */
module.exports = function(contents, templateFileExt, useWebpack) {
  templateFileExt = typeof templateFileExt !== 'undefined' ? templateFileExt : 'mustache';
  useWebpack = typeof useWebpack !== 'undefined' ? useWebpack : true;
  if (useWebpack) {
    this.cacheable();
  }
  var parsedTemplate = utils.compileTemplate(contents, module.src);
  var partials = utils.findPartials(parsedTemplate);
  utils.handleDynamicComments(parsedTemplate);
  var template = JSON.stringify(parsedTemplate);

  var templatePath = path.relative(path.dirname(module.dest), __dirname + '/template');
  templatePath = templatePath.replace(/\\/g, '/');

  var output = 'var Template=require("tungstenjs/src/template/template");';
  output += 'var template=new Template(' + template + ');';
  output += 'module.exports=template;';
  if (_.size(partials) > 0) {
    output += 'template.setPartials({';
    output += _.map(partials, function(v, partial) {
      return '"' + partial + '":require("./' + partial + '.' + templateFileExt + '")';
    }).join(',');
    output += '});';
  }

  return output;
};

{'fraction_non_alphanumeric': 0.15418091389493316, 'fraction_numerical': 0.005595275101025801, 'mean_word_length': 4.37228714524207, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1994123', 'n_tokens_mistral': 961, 'n_tokens_neox': 946, 'n_words': 240}