<commit_before>/*global Arenite:true*/
Arenite.Router = function (arenite) {

  var _routes = {};

  var _handleChange = function () {
    var hash = window.location.hash;
    arenite.object.keys(_routes).forEach(function (route) {
      var args = _routes[route].regex.exec(hash);
      if (args) {
        window.console.log('Arenite.Router: Executing route "' + route + '"');
        _routes[route].executions.forEach(function (execution) {
          var exec = JSON.parse(JSON.stringify(execution));
          if (!exec.args) {
            exec.args = [];
          }
          args.forEach(function (arg) {
            exec.args.push({value: arg});
          });
          arenite.di.exec(exec);
        });
      }
    });
  };

  var _init = function (routes, passive) {
    if (!passive) {
      document.body.onhashchange = _handleChange;
    }
    arenite.object.keys(routes).forEach(function (route) {
      var regex = route.replace(/:\w+/g, '(\\w+)');
      _routes[route] = {executions: routes[route], regex: new RegExp(regex)};
    });
    arenite.config.context.start.push({func: _handleChange});
  };

  return {
    init: _init
  };
};<commit_msg>improved route matching<commit_after>/*global Arenite:true*/
Arenite.Router = function (arenite) {

  var _routes = {};

  var _handleChange = function () {
    var hash = window.location.hash;
    arenite.object.keys(_routes).forEach(function (route) {
      var args = _routes[route].regex.exec(hash);
      if (args) {
        args.splice(0, 1);
        _routes[route].executions.forEach(function (execution) {
          var exec = JSON.parse(JSON.stringify(execution));
          if (!exec.args) {
            exec.args = [];
          }
          args.forEach(function (arg) {
            exec.args.push({value: arg});
          });
          window.console.log('Arenite.Router: Executing route "' + route + '" with:', exec);
          arenite.di.exec(exec);
        });
      }
    });
  };

  var _init = function (routes, passive) {
    if (!passive) {
      document.body.onhashchange = _handleChange;
    }
    arenite.object.keys(routes).forEach(function (route) {
      var regex = '^#' + route.replace(/:\w+/g, '(\\w+)') + "$";
      _routes[route] = {executions: routes[route], regex: new RegExp(regex)};
    });
    arenite.config.context.start.push({func: _handleChange});
  };

  return {
    init: _init
  };
};
{'fraction_non_alphanumeric': 0.1670843776106934, 'fraction_numerical': 0.000835421888053467, 'mean_word_length': 2.4214285714285713, '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': '2950651', 'n_tokens_mistral': 769, 'n_tokens_neox': 763, 'n_words': 132}