<commit_before>#!/usr/bin/env node
// Build "notes-app/templates.html" to
// "notes-app/js/app/templates/templates.js"

// Libraries.
var fs = require("fs");

// Constants.
var TMPL_SRC_PATH = "./notes/app/templates.html",
  SCRIPT_RE = new RegExp(/<script([\s\S]|.)*?<\/script>/g),
  SCRIPT_ID_RE = /<script.*id="(.*?)"/,
  SCRIPT_TEXT_RE = /[\s]*<(\/|)script.*>[\s]*/g,
  SCRIPT_ESCAPES_RE = /\"/g;

// Builder function.
var _build = module.exports = function (srcPath, outPath) {
  // Read into string.
  var tmplSrc = fs.readFileSync(srcPath).toString(),
    templates = [],
    results,
    scriptPart,
    scriptId;

  // Parse into array of id, text.
  while ((results = SCRIPT_RE.exec(tmplSrc)) !== null) {
    scriptPart = results[0];
    templates.push({
      id: SCRIPT_ID_RE.exec(scriptPart)[1],
      text: scriptPart
        .replace(SCRIPT_TEXT_RE, "")
        .replace(SCRIPT_ESCAPES_RE, "\\\"")
    });
  }

  // Output as a JS file.
  console.log("/*jslint maxlen: 200 */");
  console.log("// Underscore Templates\n");

  templates.forEach(function (tmpl) {
    var out = "",
      text = tmpl.text;

    out += "App.Templates[\"" + tmpl.id + "\"] =\n  \"";
    out += tmpl.text
      .split("\n")
      .map(function (t) { return t.replace(/^  /, ""); })
      .join("\" +\n  \"");
    out += "\";\n"

    console.log(out);
  });
};

// Script
if (require.main === module) {
  _build(TMPL_SRC_PATH);
}<commit_msg>Encapsulate template output.<commit_after>#!/usr/bin/env node
// Build "notes-app/templates.html" to
// "notes-app/js/app/templates/templates.js"

// Libraries.
var fs = require("fs");

// Constants.
var TMPL_SRC_PATH = "./notes/app/templates.html",
  SCRIPT_RE = new RegExp(/<script([\s\S]|.)*?<\/script>/g),
  SCRIPT_ID_RE = /<script.*id="(.*?)"/,
  SCRIPT_TEXT_RE = /[\s]*<(\/|)script.*>[\s]*/g,
  SCRIPT_ESCAPES_RE = /\"/g;

// Builder function.
var _build = module.exports = function (srcPath, outPath) {
  // Read into string.
  var tmplSrc = fs.readFileSync(srcPath).toString(),
    templates = [],
    buffer = [],
    results,
    scriptPart,
    scriptId;

  // Writer encapsulation.
  var _write = function (out) {
    if (outPath) {
      buffer.push(out);
    } else {
      console.log(out);
    }
  };

  // Parse into array of id, text.
  while ((results = SCRIPT_RE.exec(tmplSrc)) !== null) {
    scriptPart = results[0];
    templates.push({
      id: SCRIPT_ID_RE.exec(scriptPart)[1],
      text: scriptPart
        .replace(SCRIPT_TEXT_RE, "")
        .replace(SCRIPT_ESCAPES_RE, "\\\"")
    });
  }

  // Output as a JS file.
  _write("/*jslint maxlen: 200 */");
  _write("// Underscore Templates\n");

  templates.forEach(function (tmpl) {
    var out = "",
      text = tmpl.text;

    out += "App.Templates[\"" + tmpl.id + "\"] =\n  \"";
    out += tmpl.text
      .split("\n")
      .map(function (t) { return t.replace(/^  /, ""); })
      .join("\" +\n  \"");
    out += "\";\n"

    _write(out);
  });
};

// Script
if (require.main === module) {
  _build(TMPL_SRC_PATH);
}
{'fraction_non_alphanumeric': 0.2139090309822017, 'fraction_numerical': 0.0032959789057350032, 'mean_word_length': 2.574793875147232, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '4474390', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1136, 'n_words': 210}