<commit_before>{% comment %}

This is the template which generates src/js/hutmap/models.js
Context:
{ 
  'models': [
    {'name': 'model1', 'fields': ['field1', 'field2', ...]},
    ...
  ]
}

{% endcomment %}

// This file generated from the template at scripts/make/generate/templates/models.js
// Please do not edit by hand.
{% for model in models %}
goog.provide('hutmap.{{ model.name }}');
{% endfor %}
goog.require('goog.structs.Map');
goog.require('goog.array');

{% for model in models %}
hutmap.{{ model.name }} = function(values) {
  if (!values)
    values = {};

  if (goog.DEBUG) {
    var map = new goog.structs.Map(values);
    keys = map.getKeys();
    fields = [
      {% for field in model.fields %}
        {% if not forloop.last %}
          '{{ field }}',
        {% else %}
          '{{ field }}'
        {% endif %}
      {% endfor %}
    ];
    goog.array.forEach(keys, function(key, index, array) {
      if (!goog.array.contains(fields, key)) {
        throw "hutmap.{{ model.name }}(): Invalid field '" + key + "' given in values parameter.";
      }
    });
  }

  {% for field in model.fields %}
  this.{{ field }} = values.{{ field }};
  {% endfor %}

  {% for field in model.fields %}
  if (this.{{ field }} !== undefined &&
      this.{{ field }} !== null &&
      this.{{ field }} !== '') {
    this.{{ field }}_display =  values.{{ field }};
  } else {
    this.{{ field }}_display = 'unknown';
    {% for model2 in models %}
    {% ifequal model2.name|lower field|lower %}
    {% ifnotequal model.name|lower field|lower %}
    this.{{ field }}_display = new hutmap.{{ model2.name }}();
    {% endifnotequal %}
    {% endifequal %}
    {% endfor %}
  }
  {% endfor %}
};

hutmap.{{ model.name }}.prototype.equals = function(other) {
  {% for field in model.fields %}
  {% if forloop.first %}
  return this.{{ field }} === other.{{ field }} && 
  {% endif %}
  {% if not forloop.first and not forloop.last %}
    this.{{ field }} === other.{{ field }} && 
  {% endif %}
  {% if forloop.last %}
    this.{{ field }} === other.{{ field }};
  {% endif %}
  {% endfor %}
};
{% endfor %}
<commit_msg>Added constructing referenced model objects to models.js template.<commit_after>{% comment %}

This is the template which generates src/js/hutmap/models.js
Context:
{ 
  'models': [
    {'name': 'model1', 'fields': ['field1', 'field2', ...]},
    ...
  ]
}

{% endcomment %}

// This file generated from the template at scripts/make/generate/templates/models.js
// Please do not edit by hand.
{% for model in models %}
goog.provide('hutmap.{{ model.name }}');
{% endfor %}
goog.require('goog.structs.Map');
goog.require('goog.array');

{% for model in models %}
hutmap.{{ model.name }} = function(values) {
  if (!values)
    values = {};

  if (goog.DEBUG) {
    var map = new goog.structs.Map(values);
    keys = map.getKeys();
    fields = [
      {% for field in model.fields %}
        {% if not forloop.last %}
          '{{ field }}',
        {% else %}
          '{{ field }}'
        {% endif %}
      {% endfor %}
    ];
    goog.array.forEach(keys, function(key, index, array) {
      if (!goog.array.contains(fields, key)) {
        throw "hutmap.{{ model.name }}(): Invalid field '" + key + "' given in values parameter.";
      }
    });
  }

  {% for field in model.fields %}
  this.{{ field }} = values.{{ field }};
  {% for model2 in models %}
  {% ifequal model2.name|lower field|lower %}
  {% ifnotequal model.name|lower field|lower %}
  this.{{ field }} = new hutmap.{{ model2.name }}(values.{{ field }});
  {% endifnotequal %}
  {% endifequal %}
  {% endfor %}
  {% endfor %}

  {% for field in model.fields %}
  if (this.{{ field }} !== undefined &&
      this.{{ field }} !== null &&
      this.{{ field }} !== '') {
    this.{{ field }}_display =  values.{{ field }};
  } else {
    this.{{ field }}_display = 'unknown';
    {% for model2 in models %}
    {% ifequal model2.name|lower field|lower %}
    {% ifnotequal model.name|lower field|lower %}
    this.{{ field }}_display = new hutmap.{{ model2.name }}();
    {% endifnotequal %}
    {% endifequal %}
    {% endfor %}
  }
  {% endfor %}
};

hutmap.{{ model.name }}.prototype.equals = function(other) {
  {% for field in model.fields %}
  {% if forloop.first %}
  return this.{{ field }} === other.{{ field }} && 
  {% endif %}
  {% if not forloop.first and not forloop.last %}
    this.{{ field }} === other.{{ field }} && 
  {% endif %}
  {% if forloop.last %}
    this.{{ field }} === other.{{ field }};
  {% endif %}
  {% endfor %}
};
{% endfor %}

{'fraction_non_alphanumeric': 0.20609515457136593, 'fraction_numerical': 0.00328875246656435, 'mean_word_length': 2.606324110671937, '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': '7237183', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1467, 'n_words': 379}