<commit_before>/*global obviel: true, jQuery: true, template_url: true
  alert: true , browser: true, document: true, app_url: true, 
  window: true, Gettext: true, json_locale_data: true
*/
/*jshint evil: true */

/*

How does this work?

There are two phases:

* Compilation phase: the template is parsed and structures are generated
  for a fast execution phase.

* Execution phase: the compiled template is combined with a JavaScript
  object and a DOM element. The resulting rendered template is attached
  to this element.

How does compilation work?

* a separated Section is compiled for each data-with, data-if and
  data-each element, or combinations thereof.

* Sections are organized in a tree; each section may have
  sub-sections. The template itself starts with a single Section at
  the top.

* each section also maintains a list of dynamic elements: an element
  with dynamic content. An element becomes dynamic if:

  * it has an attribute which uses variable interpolation.

  * it has a child text node that uses variable interpolation.

  * it has a data-id directive.

  * it has a data-trans directive.

  * it has a data-tvar directive.

* Sections and dynamic elements are found in a section by following a
  path of childNode indexes from the Section they are in. This way we
  avoid having to modify the DOM with temporary ID markers, which is
  relatively slow and does not allow the rendering of a template on an
  element unattached to the document.

when rendering a section:

* clone original section (deep copy) into DOM.

* now find all dynamic elements by id and fill in interpolations
  according to data (and translations).

* render sub-sections and attach them.

*/

if (typeof obviel === "undefined") {
    var obviel = {};
}

obviel.template = {};

(function($, module) {

    // will define these later, is to please jshint
    var is_html_text, trim, normalize_space;
    var formatters, funcs;
    var default_view_name = null;
    var resolve_in_obj, get_directive, validate_dotted_name;
    var cached_tokenize, morph_element;
    var split_name_formatter, split_name_formatters;
    var parse_text_for_plural, parse_tvar, get_implicit_count_variable;
    var check_message_id;
    
    var OBVIEL_TEMPLATE_ID_PREFIX = 'obviel-template-';

    module.NAME_TOKEN = 0;
    module.TEXT_TOKEN = 1;

    module.Error = function(el, message) {
        this.el = el;
        this.message = message;
    };

    module.Error.prototype.toString = function() {
        return this.message;
    };
    
    module.CompilationError = function(el, message) {
        this.el = el;
        this.message = message;
    };

    module.CompilationError.prototype = new module.Error();
    <commit_msg>Add half-done path function to be used in error reporting. But things are not right with the paths of the root element I suspect.<commit_after>/*global obviel: true, jQuery: true, template_url: true
  alert: true , browser: true, document: true, app_url: true, 
  window: true, Gettext: true, json_locale_data: true
*/
/*jshint evil: true */

/*

How does this work?

There are two phases:

* Compilation phase: the template is parsed and structures are generated
  for a fast execution phase.

* Execution phase: the compiled template is combined with a JavaScript
  object and a DOM element. The resulting rendered template is attached
  to this element.

How does compilation work?

* a separated Section is compiled for each data-with, data-if and
  data-each element, or combinations thereof.

* Sections are organized in a tree; each section may have
  sub-sections. The template itself starts with a single Section at
  the top.

* each section also maintains a list of dynamic elements: an element
  with dynamic content. An element becomes dynamic if:

  * it has an attribute which uses variable interpolation.

  * it has a child text node that uses variable interpolation.

  * it has a data-id directive.

  * it has a data-trans directive.

  * it has a data-tvar directive.

* Sections and dynamic elements are found in a section by following a
  path of childNode indexes from the Section they are in. This way we
  avoid having to modify the DOM with temporary ID markers, which is
  relatively slow and does not allow the rendering of a template on an
  element unattached to the document.

when rendering a section:

* clone original section (deep copy) into DOM.

* now find all dynamic elements by id and fill in interpolations
  according to data (and translations).

* render sub-sections and attach them.

*/

if (typeof obviel === "undefined") {
    var obviel = {};
}

obviel.template = {};

(function($, module) {

    // will define these later, is to please jshint
    var is_html_text, trim, normalize_space;
    var formatters, funcs;
    var default_view_name = null;
    var resolve_in_obj, get_directive, validate_dotted_name;
    var cached_tokenize, morph_element;
    var split_name_formatter, split_name_formatters;
    var parse_text_for_plural, parse_tvar, get_implicit_count_variable;
    var check_message_id;
    
    var OBVIEL_TEMPLATE_ID_PREFIX = 'obviel-template-';

    module.NAME_TOKEN = 0;
    module.TEXT_TOKEN = 1;

    module.Error = function(el, message) {
        this.el = el;
        this.message = message;
    };

    // XXX this doesn't generate the right paths yet
    module.Error.prototype.path = function() {
        var path = [];
        var el = this.el;
        while (el !== null && el.nodeType === 1) {
            path.push(el.tagName.toLowerCase());
            el = el.parentNode;
        }
        path.reverse();
        return path.join('/');
    };
    
    module.Error.prototype.toString = function() {
        return this.message;
    };
    
    module.CompilationError = function(el, message) {
        this.el = el;
        this.message = message;
    };

    module.CompilationError.prototype = new module.Error();
    
{'fraction_non_alphanumeric': 0.0743174924165824, 'fraction_numerical': 0.0008426019548365353, 'mean_word_length': 3.212207239176721, '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': '900754', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1658, 'n_words': 693}