<commit_before>/**

  Watches files and updates compilers, renderers and handlers

  • addFile
  • removeFile
  • setup (exports)

**/

/**

  Dependencies and exports

**/

var Compiler = require("./compiler");
var Handler = require("./handler");
var Utils = require("./utils");


module.exports = setup;


/**

  Creates compilation pipeline for a file, adds route handlers and global lookup.

  @param {Router} router Parent router
  @param {File} file File information as returned by Utils#parse
  @param {String} [options.url] The base URL for the route
  @param {String} [options.type] The file type (html, js, css)

**/

function addFile(router, file, options) {

  global.shipp.debug("Adding file: " + file.path);

  // Stop-gap method to identify bundles in real-time
  if ("js" === options.type && !file.bundle && Utils.isIndexFile(file))
    file.bundle = true;

  options = options || {};
  options.url = options.url || "/";

  // Add to list of extensions if not present
  // !!! TODO pipeline from ext
  var pipeline;
  var source = { file: file };
  var renderer = Compiler.createRenderer(id, source, options.type, pipeline);
  var key = Utils.makeRouteKey(options.url, file, options);
  var route = Utils.makeRoute(options.url, file, options);
 
  var renderer = Compiler.createRenderer(key, source, options.type);
  var handler = Handler.createHandler(renderer);

  route = Utils.makeRoute(options.url, file, options);
  router.get(route, handler);

  // Add to assets (used in templating, as well as asset pipelines)
  if (!Utils.isHTML(options.type))
    global.shipp.assets[key] = route;

}


/**

  Given a file, removes corresponding route handler and global assets.

  @param {Router} router Parent router
  @param {File} file File information as returned by Utils#parse
  @param {String} [options.url] The base URL for the route
  @param {String} [options.type] The file type (html, js, css)<commit_msg>Files#addFile: fixes bugs with rendering<commit_after>/**

  Watches files and updates compilers, renderers and handlers

  • addFile
  • removeFile
  • setup (exports)

**/

/**

  Dependencies and exports

**/

var Compiler = require("./compiler");
var Handler = require("./handler");
var Utils = require("./utils");


module.exports = setup;


/**

  Creates compilation pipeline for a file, adds route handlers and global lookup.

  @param {Router} router Parent router
  @param {File} file File information as returned by Utils#parse
  @param {String} [options.url] The base URL for the route
  @param {String} [options.type] The file type (html, js, css)

**/

function addFile(router, file, options) {

  global.shipp.debug("Adding file: " + file.path);

  // Stop-gap method to identify bundles in real-time
  if ("js" === options.type && !file.bundle && Utils.isIndexFile(file))
    file.bundle = true;

  options = options || {};
  options.url = options.url || "/";

  // Add to list of extensions if not present
  var source = { file: file, ext: file.ext };
  var key = Utils.makeRouteKey(options.url, file, options);
  var route = Utils.makeRoute(options.url, file, options);
 
  var renderer = Compiler.createRenderer(key, source, options.type);
  var handler = Handler.createHandler(renderer);

  router.get(route, handler);

  // Add to assets (used in templating, as well as asset pipelines)
  if (!Utils.isHTML(options.type))
    global.shipp.assets[key] = route;

}


/**

  Given a file, removes corresponding route handler and global assets.

  @param {Router} router Parent router
  @param {File} file File information as returned by Utils#parse
  @param {String} [options.url] The base URL for the route
  @param {String} [options.type] The file type (html, js, css)
{'fraction_non_alphanumeric': 0.126514131897712, 'fraction_numerical': 0.0, 'mean_word_length': 3.801033591731266, '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': '3041366', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1105, 'n_words': 397}